0

i am unable to remove plugin meta box from custom post for all non admin users. Here is the function of the plugin :

    function PreparePostPageOptions() {
        global $WishListMemberInstance;
        $post_types = array('post', 'page', 'attachment') + get_post_types(array('_builtin' => false));
        foreach ($post_types AS $post_type) {
            if ($post_type == 'attachment')
                add_meta_box('wlm_attachment_metabox', __('WishList Member', 'wishlist-member'), array(&$WishListMemberInstance, 'AttachmentOptions'), $post_type);
            else
                add_meta_box('wlm_postpage_metabox', __('WishList Member', 'wishlist-member'), array(&$WishListMemberInstance, 'PostPageOptions'), $post_type);
        }
    }

This is the code I am using for the removal:

    if (is_admin()) :
function remove_wlm_metaboxes(){
    if ( ! current_user_can( 'administrator' ) ) {  
        remove_meta_box( 'wlm_postpage_metabox', 'post', 'normal' ); 
    }
}
add_action( 'admin_menu', 'remove_wlm_metaboxes', 9999 );
endif;
1

Why are you adding metaboxes to non-admin users in the first page? Try this:

function PreparePostPageOptions() {

    if( !current_user_can('administrator') )  // add meta boxes only for admin
       return;

        global $WishListMemberInstance;
        $post_types = array('post', 'page', 'attachment') + get_post_types(array('_builtin' => false));
        foreach ($post_types AS $post_type) {
            if ($post_type == 'attachment')
                add_meta_box('wlm_attachment_metabox', __('WishList Member', 'wishlist-member'), array(&$WishListMemberInstance, 'AttachmentOptions'), $post_type);
            else
                add_meta_box('wlm_postpage_metabox', __('WishList Member', 'wishlist-member'), array(&$WishListMemberInstance, 'PostPageOptions'), $post_type);
        }
    }

In case you are wondering why your given code is not working. You are adding the function on wrong hook. You might want to try:

add_action( 'add_meta_boxes', 'remove_wlm_metaboxes', 9999 );

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy