Update:
抱歉,不知怎的,我弄糊涂了,你说你知道“remove\\u meta\\u box”的功能。我做了一些挖掘,查看了Adminimize插件,了解了它的工作原理,基本上它添加了一个css style=“display none;”根据您在选项面板中设置的选项,使用for-each循环来运行所有角色,以便执行以下操作:
function get_all_user_roles() {
global $wp_roles;
$user_roles = array();
if ( isset($wp_roles->roles) && is_array($wp_roles->roles) ) {
foreach ($wp_roles->roles as $role => $data) {
array_push($user_roles, $role);
//$data contains caps, maybe for later use..
}
}
return $user_roles;
}
// return string The name of the current role
function get_current_user_role() {
global $wp_roles;
$current_user = wp_get_current_user();
$roles = $current_user->roles;
$role = array_shift($roles);
return isset($wp_roles->role_names[$role]) ? translate_user_role($wp_roles->role_names[$role] ) : false;
}
//hook admin CSS
add_action(\'admin_print_styles\', \'meta_box_css_hack\');
//the magic happens here
function meta_box_css_hack(){
$user_roles = get_all_user_roles();
foreach ($user_roles as $role) {
//first we check if its curent user
if ($role = get_current_user_role()){
/* each role has it own option in the option database witch is an array that holds the name of the meta-boxes div id. */
$disabled_metaboxes_post_ = get_option(\'disable[$role]\');
echo \'<style type=text/css">\';
$out = \'\'
foreach ($disabled_metaboxes_post_ as $meta_id)
{
$out .= \'#\'.$meta_id . \', \';
}
$out = substr($out,0,-2);
}
$out .= \' { display: none !important;} </style>\';
echo $out;
break;
}
}
我希望这有帮助。