Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    A lot of this sounds like it’s probably covered by the capabilities fields, that we don’t have available at the moment. (We’re not 100% matching).

    That said, I think you should be able to handle this fairly easily at run time.

    We have the following filter that runs right before the registration of each post type: https://github.com/WebDevStudios/custom-post-type-ui/blob/1.3.3/custom-post-type-ui.php#L380-L390

    What you could do is add a callback for the filter, and check if the current user has the “manage_options” capability, and change the show_ui boolean value based on that.

    Great plugin Michael. I’m trying to hide my custom post type “specials” completely from Editors and your suggestion of the filter seems like the best approach. I’ve gotten this far:

    add_filter(‘cptui_pre_register_post_type’, ‘fxn_bustigate’);
    function fxn_bustigate() {
    if (!current_user_can (‘manage_options’)) {
    // now what??
    }
    }

    How do I access and disable the show_ui boolean value? Thanks!

    Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    function fxn_bustigate( $args = array(), $post_type_name = '', $post_type = '' ) {
    	if ( 'specials' != $post_type ) {
    		return $args;
    	}
    
    	if ( ! current_user_can( 'manage_options' ) ) {
    		$args['show_ui'] = false;
    	}
    
    	return $args;
    }
    add_filter( 'cptui_pre_register_post_type', 'fxn_bustigate', 10, 3 );

    You needed to bring in the arguments for the filter, and then at that point it just matches up to what the args hierarchy is for register_post_type. I added a check for the post type you mention, so that it only does it on this one post type. Amend as necessary

    Nice, thank you!

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Visibility of menu user role specific’ is closed to new replies.