Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author HelgaTheViking

    (@helgatheviking)

    There’s no baked-in way, but as you suggested remove_meta_box() should work.

    Maybe something like this?

    $options = get_option('featured_items_metabox_options', false );
    
    if( isset( $options['types'] ) ) foreach( $options['types'] as $type ) {
    	if( ! current_user_can( 'manage_options' ) )
                  remove_meta_box( '_featured_metabox', $type, 'side' );
    }
    Thread Starter aaronrobb

    (@aaronrobb)

    I was having issues with the remove meta box not working. No idea why, but i currently hacked up the plugin code in the class file on line 76 to read:

    if( ! is_wp_error( $this->type_obj ) && current_user_can('manage_options') ):

    It may just be our system clashing with something else to not let the remove metabox work. Its working with that little code now, but I’ll keep searching to find why the basic remove function won’t run.

    Thanks!

    Plugin Author HelgaTheViking

    (@helgatheviking)

    Maybe the problem is that you are trying to remove the box before it has been added? The boxes are being added on the add_meta_boxes hook, so I believe they can be removed there as well so long we you have a later priority than my plugin.

    function admin_only_metaboxes(){
    
    	$options = get_option('featured_items_metabox_options', false );
    
    	if( isset( $options['types'] ) ) foreach( $options['types'] as $type ) {
    		if( ! current_user_can( 'manage_options' ) )
    	              remove_meta_box( '_featured_metabox', $type, 'side' );
    	}
    
    }
    add_action( 'add_meta_boxes', 'admin_only_metaboxes', 20 );
Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Limit access to admins?’ is closed to new replies.