猿问

WordPress 用户数

您如何从 WordPress 用户计数中减去 1,以便不计算隐藏的管理员用户?

我可以一起隐藏计数,但我宁愿从计数中减去 1。

https://snipboard.io/CfAIcG.jpg

将代码插入 Functions.php


达令说
浏览 124回答 1
1回答

偶然的你

不确定为什么要隐藏计数,但不确定用户页面上实际隐藏的管理员配置文件。我已经按照你的意愿做了减法计数。将此代码放入 functions.php 并访问用户页面。add_filter("views_users", 'editCounts', 10, 1);function editCounts($views) {&nbsp; &nbsp; if ( current_user_can( 'administrator' ) ) {&nbsp; &nbsp; &nbsp; &nbsp; $total = count_users();&nbsp; &nbsp; &nbsp; &nbsp; $newTotal = $total['total_users']-1;&nbsp; &nbsp; &nbsp; &nbsp; $views = array('all' => '<a href="users.php" class="current" aria-current="page">All <span class="count">('.$newTotal.')</span></a>', 'administrator' => '<a href="users.php?role=administrator">Administrator <span class="count">('.$newTotal.')</span></a>');&nbsp; &nbsp; &nbsp; &nbsp; return $views;&nbsp; &nbsp; }else{&nbsp; &nbsp; &nbsp; &nbsp; return $views;&nbsp; &nbsp; }}&nbsp;&nbsp;希望能帮助到你
随时随地看视频慕课网APP
我要回答