Remove Metaboxes

时间:2015-04-10 作者:Dannie Herdyawan

我尝试从非管理员的帖子、页面和添加产品页面(WooCommerce)中删除元数据库,我的代码如下:

// ciusART Remove Metaboxes
add_action(\'admin_head\', \'remove_metaboxes_for_non_admin\');
function remove_metaboxes_for_non_admin(){
    if (!is_admin()){ // only remove for non admins
        remove_meta_box(\'wpseo_meta\', \'post\', \'advanced\');
        remove_meta_box(\'wpseo_meta\', \'page\', \'advanced\');
        remove_meta_box(\'wpseo_meta\', \'products\', \'advanced\');
        remove_meta_box(\'acf_acf_extended-footer\', \'post\', \'advanced\');
        remove_meta_box(\'acf_acf_extended-footer\', \'page\', \'advanced\');
        remove_meta_box(\'acf_acf_extended-footer\', \'products\', \'advanced\');
        remove_meta_box(\'acf_acf_layout-settings\', \'post\', \'advanced\');
        remove_meta_box(\'acf_acf_layout-settings\', \'page\', \'advanced\');
        remove_meta_box(\'acf_acf_layout-settings\', \'products\', \'advanced\');
        remove_meta_box(\'acf_acf_product-settings\', \'post\', \'advanced\');
        remove_meta_box(\'acf_acf_product-settings\', \'page\', \'advanced\');
        remove_meta_box(\'acf_acf_product-settings\', \'products\', \'advanced\');
        remove_meta_box(\'acf_acf_sidebar\', \'post\', \'advanced\');
        remove_meta_box(\'acf_acf_sidebar\', \'page\', \'advanced\');
        remove_meta_box(\'acf_acf_sidebar\', \'products\', \'advanced\');
        remove_meta_box(\'acf_acf_size-guide\', \'post\', \'advanced\');
        remove_meta_box(\'acf_acf_size-guide\', \'page\', \'advanced\');
        remove_meta_box(\'acf_acf_size-guide\', \'products\', \'advanced\');
        remove_meta_box(\'acf_acf_header-image-background\', \'post\', \'advanced\');
        remove_meta_box(\'acf_acf_header-image-background\', \'page\', \'advanced\');
        remove_meta_box(\'acf_acf_header-image-background\', \'products\', \'advanced\');
        remove_meta_box(\'acf_acf_footer-image-background\', \'post\', \'advanced\');
        remove_meta_box(\'acf_acf_footer-image-background\', \'page\', \'advanced\');
        remove_meta_box(\'acf_acf_footer-image-background\', \'products\', \'advanced\');
        remove_meta_box(\'acf_acf_extended-footer-image-background\', \'post\', \'advanced\');
        remove_meta_box(\'acf_acf_extended-footer-image-background\', \'page\', \'advanced\');
        remove_meta_box(\'acf_acf_extended-footer-image-background\', \'products\', \'advanced\');
        // continue adding as necessary
    }
}
但是这个代码不起作用,你能帮我。。。

谢谢

2 个回复
SO网友:GastroGeek

我不认为这会发生。。。。

Is\\u admin()检测管理UI而不是管理权限。。。尝试:

if (is_admin()) : 
function my_remove_meta_boxes()  { 
if( !current_user_can(\'manage_options\') )  { 
    remove_meta_box(...);
}}
add_action( \'admin_menu\', \'my_remove_meta_boxes\' );
endif;

SO网友:Bhavik Patel

请换衣服!is\\u admin()当前用户是管理员,is\\u admin()不是检查用户,但他们检查管理面板区域

请更改代码

 add_action(\'admin_head\', \'remove_metaboxes_for_non_admin\');
function remove_metaboxes_for_non_admin(){
    global $current_user;
    if ($current_user->role[0]!=\'administrator\')
    {
        remove_meta_box(\'wpseo_meta\', \'post\', \'advanced\');
        remove_meta_box(\'wpseo_meta\', \'page\', \'advanced\');
        remove_meta_box(\'wpseo_meta\', \'products\', \'advanced\');
        remove_meta_box(\'acf_acf_extended-footer\', \'post\', \'advanced\');
        remove_meta_box(\'acf_acf_extended-footer\', \'page\', \'advanced\');
        remove_meta_box(\'acf_acf_extended-footer\', \'products\', \'advanced\');
        remove_meta_box(\'acf_acf_layout-settings\', \'post\', \'advanced\');
        remove_meta_box(\'acf_acf_layout-settings\', \'page\', \'advanced\');
        remove_meta_box(\'acf_acf_layout-settings\', \'products\', \'advanced\');
        remove_meta_box(\'acf_acf_product-settings\', \'post\', \'advanced\');
        remove_meta_box(\'acf_acf_product-settings\', \'page\', \'advanced\');
        remove_meta_box(\'acf_acf_product-settings\', \'products\', \'advanced\');
        remove_meta_box(\'acf_acf_sidebar\', \'post\', \'advanced\');
        remove_meta_box(\'acf_acf_sidebar\', \'page\', \'advanced\');
        remove_meta_box(\'acf_acf_sidebar\', \'products\', \'advanced\');
        remove_meta_box(\'acf_acf_size-guide\', \'post\', \'advanced\');
        remove_meta_box(\'acf_acf_size-guide\', \'page\', \'advanced\');
        remove_meta_box(\'acf_acf_size-guide\', \'products\', \'advanced\');
        remove_meta_box(\'acf_acf_header-image-background\', \'post\', \'advanced\');
        remove_meta_box(\'acf_acf_header-image-background\', \'page\', \'advanced\');
        remove_meta_box(\'acf_acf_header-image-background\', \'products\', \'advanced\');
        remove_meta_box(\'acf_acf_footer-image-background\', \'post\', \'advanced\');
        remove_meta_box(\'acf_acf_footer-image-background\', \'page\', \'advanced\');
        remove_meta_box(\'acf_acf_footer-image-background\', \'products\', \'advanced\');
        remove_meta_box(\'acf_acf_extended-footer-image-background\', \'post\', \'advanced\');
        remove_meta_box(\'acf_acf_extended-footer-image-background\', \'page\', \'advanced\');
        remove_meta_box(\'acf_acf_extended-footer-image-background\', \'products\', \'advanced\');
        // continue adding as necessary
    }
}

结束

相关推荐

允许admin-ajax.php接收“application/json”而不是“x-www-form-urlencode”

我在用AngularJS的$http 函数将我的有效负载发送到WordPressadmin-ajax.php 子系统,但后者似乎只接受x-www-form-urlencoded 数据,而不是application/json 由Angular提供。我知道there are ways 使$http函数更像$.post(), 但这是荒谬的——既然已经是JSON,为什么还要将一堆JSON数据转换成一种形式呢?为此目的—is there any way of instructing admin-ajax to co