最合适的回答,由SO网友:Frank P. Walentynowicz 整理而成
首先,创建[all-capabilities]
短代码。将此代码放入主题functions.php
:
function wpse_all_capabilities() {
$out = \'<style>
.flex-columns {
column-count: 4;
column-gap: 3em;
column-rule: 1px solid #000;
}
</style>\';
$out .= \'<p class="flex-columns">\';
$users = get_users();
foreach ( $users as $user ) {
if ( $user->caps[\'administrator\'] ) {
$allcaps = array_keys( $user->allcaps );
foreach ( $allcaps as $cap ) {
$out .= $cap . \'<br>\';
}
$out .= \'</p>\';
return $out;
}
}
}
add_shortcode( \'all-capabilities\', \'wpse_all_capabilities\' );
Update: 有可能
Administrator
删除了一些功能,因此我们需要扫描所有用户。修改代码如下:
function wpse_all_capabilities() {
$allcaps = array();
$out = \'<style>
.flex-columns {
column-count: 3;
column-gap: 3em;
column-rule: 1px solid #000;
}
h2 {
text-align: center;
column-span: all;
}
</style>\';
$out .= \'<div class="flex-columns">\';
$out .= "<h2>All Possible Users\' Capabilities<hr></h2><p>";
$users = get_users();
foreach ( $users as $user ) {
$caps = array_keys( $user->allcaps );
foreach ( $caps as $cap ) {
if ( !in_array( $cap, $allcaps, true ) ) {
$num = array_push( $allcaps, $cap );
}
}
}
foreach ( $allcaps as $capability ) {
$out .= $capability . \'<br>\';
}
$out .= \'</p></div>\';
return $out;
}
add_shortcode( \'all-capabilities\', \'wpse_all_capabilities\' );
现在,您可以使用
[all-capabilities]
页面上的快捷代码。