current_user_can()
检查当前用户的指定功能。看见Roles and Capabilities.
此外,CSS只是在视觉上隐藏该节,但不会将其从页面HTML中删除。以下代码检查该功能并完全删除该节。
<?php
// For example,
// any user other than an Admin of single site installation,
// but not Multisite Admin and not SuperAdmin:
if ( ! current_user_can( \'delete_users\' ) ) {
add_action( \'admin_head\', \'my_profile_admin_buffer_start\' );
add_action( \'admin_footer\', \'my_profile_admin_buffer_end\' );
}
function my_remove_about_section( $buffer ) {
// get section header and everything until the next section
$about_section = \'~<h2>About Yourself</h2>.+?/table>~s\';
// replace it with empty string
$buffer = preg_replace( $about_section, \'\', $buffer, 1 );
return $buffer;
}
function my_profile_admin_buffer_start() {
ob_start( \'my_remove_about_section\' );
}
function my_profile_admin_buffer_end() {
ob_end_flush();
}
整个想法是从我的旧的死前WordPress-5项目,并没有经过测试。