Disable Editing of Event Categories for editor user role in 2016

Home Forums Calendar Products Events Calendar PRO Disable Editing of Event Categories for editor user role in 2016

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #1167199
    hikeitbaby
    Participant

    Hello,

    I need to disable the ability of my editors to add new categories. I thought that removing the standard wordpress capability of “manage_categories” would take care of that, but it doesn’t seem to interact with the Events post types at all.

    I’ve looked over the documentation at https://theeventscalendar.com/knowledgebase/admin-roles-and-permissions/#capabilities and it looks like there isn’t an Events Calendar capability to manage categories at all? I’ve confirmed this by installing the Members plugin and looking in the options there, to no avail.

    Looks like another user of yours in 2013 attempted to solve this: https://theeventscalendar.com/support/forums/topic/disable-editing-of-event-categories/ but their code snippet solution isn’t working for me. I’ve moved that over to a pastebin for easier inspection here: http://pastebin.com/LRda7cVZ
    Also, I’ve included it here:

    
    
    function disable_editor_category_editing() {
    //make it so that non-admin users can not edit event categories
    	register_taxonomy( 'tribe_events_cat', 'tribe_events', array(
    		'hierarchical' => true,
    		'rewrite' => array( 'slug'=> 'events/' . sanitize_title( __( 'category', 'tribe-events-calendar' ) ), 'with_front' => false ),
    		'public' => true,
    		'show_ui' => true,
    		'labels' => array(
    		'name' =>	__( 'NTD Categories', 'tribe-events-calendar' ),
    		'singular_name' =>	__( 'NTD Category', 'tribe-events-calendar' ),
    		'search_items' =>	__( 'Search NTD Categories', 'tribe-events-calendar' ),
    		'all_items' => __( 'All NTD Categories', 'tribe-events-calendar' ),
    		'parent_item' =>	__( 'Parent NTD Category', 'tribe-events-calendar' ),
    		'parent_item_colon' =>	__( 'Parent NTD Category:', 'tribe-events-calendar' ),
    		'edit_item' =>	__( 'Edit NTD Category', 'tribe-events-calendar' ),
    		'update_item' =>	__( 'Update NTD Category', 'tribe-events-calendar' ),
    		'add_new_item' =>	__( 'Add New NTD Category', 'tribe-events-calendar' ),
    		'new_item_name' =>	__( 'New NTD Category Name', 'tribe-events-calendar' )
    	),
    	'capabilities' => array(
    		'manage_terms' => 'update_themes',
    		'edit_terms' => 'update_themes',
    		'delete_terms' => 'update_themes',
    		'assign_terms' => 'update_themes'
    	)
    	));
    }
    add_action('init', 'disable_editor_category_editing');
    
    #1167598
    hikeitbaby
    Participant

    it’s a wonky hack, but if while on the backend the user’s role was output as a class on the body element, then I could at least hide the “add new category” meta box option by targeting it as body.editor #tribe_events_cat-adder { display:none;}

    Problem is that the sidebar event categories menu option is still visible.

    The code to add to the theme functions.php looks like this:

    
    /// Add user role class to front-end body tag
    function class_to_body($classes) {
    	global $current_user;
    	$user_role = array_shift($current_user->roles);
    	$classes[] = $user_role.' ';
    	return $classes;
    }
    
    /// Add user role class and user id to front-end body tag
    
    	// add 'class-name' to the $classes array	
    function class_to_body_admin($classes) {
    	global $current_user;
    	$user_role = array_shift($current_user->roles);
    	/* Adds the user id to the admin body class array */
    	$user_ID = $current_user->ID;	
    	$classes .= $user_role.' '.'user-id-'.$user_ID ;
    	return $classes;
    	return 'user-id-'.$user_ID;	
    }
    
    add_filter('body_class','class_to_body');
    add_filter('admin_body_class', 'class_to_body_admin');
    
    function my_custom_admin_styles() {
      echo '<style>
    body.editor #tribe_events_cat-adder {
    	display:none;
    }
      </style>';
    }
    
    • This reply was modified 9 years, 7 months ago by hikeitbaby.
    #1167817
    Andras
    Keymaster

    Hello again hikeitbaby,

    I believe the code will pretty much work. Only the last function needs to be modified a bit. The css class seems a bit different than I think is needed, and the function is not invoked. Try replacing it with this and see if that works:
    function my_custom_admin_styles() {
    echo '<style>
    body.editor #tribe_events_catdiv {
    display:none;
    }
    </style>';
    }
    add_action( 'admin_head', 'my_custom_admin_styles' );

    Let me know.

    Cheers,
    Andras

    #1168134
    hikeitbaby
    Participant

    Hi Andras,

    You’re right, I forgot to include the invoction. I’ve added a css rule so the sidebar category menu item is hidden as well, though I still think using CSS as a hack shouldn’t be a long term solution for a robust platform as yours and I hoping you’ll add a proper capability in future releases.

    
    function my_custom_admin_styles() {
      echo '<style>
        body.editor #tribe_events_catdiv {
         display:none;
        }
        body.editor li#menu-posts-tribe_events ul.wp-submenu li:nth-of-type(4) {
         display: none;
        }
      </style>';
    }
    add_action( 'admin_head', 'my_custom_admin_styles' );
    
    
    #1168600
    Andras
    Keymaster

    Hi hikeitbaby,

    Thanks for your feedback. Indeed, the CSS hack is not the nicest solution.

    If you think that is something you would like as a feature I encourage you to visit our User Voice Page and either upvote an existing request or make a new request there.
    http://tribe.uservoice.com/

    Since this is marked resolved I am going to close this ticket, but if you need anything else related to this topic or another please post a new topic on the forum and we can help you out.

    Thanks and cheers,
    Andras

Viewing 5 posts - 1 through 5 (of 5 total)
  • The topic ‘Disable Editing of Event Categories for editor user role in 2016’ is closed to new replies.