Skip to:
Content
Pages
Categories
Search
Top
Bottom

Remove Settings Capability for Editors

  • @highgatecreative

    Participant

    Hi,
    I’m developing a site for a client (Worpdress 4.8.1) and I’m using bbPress 2.6-beta-2 to handle forums. The client’s main administrative account uses the WordPress role “Editor” and the bbPress role “Keymaster.” I want my client to keep most of the Keymaster capabilities, but I want to remove the Forum Settings page from their admin dashboard menu. I’m wondering if this can be done with the hide_menu() function.
    For native wordpress pages, the function looks something like this:
    remove_submenu_page( ‘<filename>.php’, ‘<filename>.php’ );
    Can this work with the bbPress Settings page, and if so, which filename should appear in the function?

    Peace,
    Angela

Viewing 9 replies - 1 through 9 (of 9 total)
  • @robin-w

    Moderator

    If you set them as moderators, then they don’t get forums in the dashboard

    @highgatecreative

    Participant

    But if I change the account from “Keymaster” to “Moderator,” then the main Forums tab (above Topics and Replies) gets removed even though I’ve set the “Editor” capabilities to include the following:
    ‘publish_forums’,
    ‘edit_forums’,
    ‘edit_others_forums’,
    ‘delete_forums’,
    ‘delete_others_forums’,
    ‘read_private_forums’,
    I want this person to have access to everything except for the forum settings page under Settings.

    @robin-w

    Moderator

    bbp capabilities are allocated against bbpress roles, so suspect that it would be easier to add forums to the moderator role

    I think the capability you need to add is

    bbp_forums_admin

    so set to user to moderator and add the above capability to preferably the moderator role but could be the editor role

    @highgatecreative

    Participant

    Where is the documentation for adding capabilities to the moderator role? I tried adding
    bbp_forums_admin
    to the editor role, but that didn’t add it. I’d like to try adding it to the moderator, but I’m not sure what the function should look like for that.

    @robin-w

    Moderator

    ok, I’ve been kicking this around for the last 3 hours!!

    Capabilities are spread all over the files in bbpress, so it’s taken a while to get to something.

    But I’ve learnt some good stuff along the way !!

    This is close to a perfect solution, and seems workable

    add_filter ('bbp_register_forum_post_type', 'rew_change') ; 
    
    function rew_change () {
    	$rew = array(
    				'labels'              => bbp_get_forum_post_type_labels(),
    				'rewrite'             => bbp_get_forum_post_type_rewrite(),
    				'supports'            => bbp_get_forum_post_type_supports(),
    				'description'         => __( 'bbPress Forums', 'bbpress' ),
    				'capabilities'        => bbp_get_topic_caps(),
    				'capability_type'     => array( 'forum', 'forums' ),
    				'menu_position'       => 555555,
    				'has_archive'         => bbp_get_root_slug(),
    				'exclude_from_search' => true,
    				'show_in_nav_menus'   => true,
    				'public'              => true,
    				'show_ui'             => current_user_can( 'moderate' ),
    				'can_export'          => true,
    				'hierarchical'        => false,
    				'query_var'           => true,
    				'menu_icon'           => ''
    			) ;
    	return apply_filters( 'rew_change', $rew );
    }
    
    add_filter( 'bbp_get_caps_for_role', 'rew_moderator', 10, 2);
    
    function rew_moderator ($caps, $role) {
    	if ($role == bbp_get_moderator_role() ) {
    		$caps['edit_others_forums'] = true ;
    		$caps['delete_forums'] = true ;
    		$caps['delete_others_forums'] = true ;
    		$caps['publish_forums'] = true ;
    		$caps['read_private_forums'] = true ;
    		$caps['read_hidden_forums'] = true ;
    		$caps['edit_forums'] = true ;
    				
    	}
    
    return $caps ;
    	
    }

    The line

    'capabilities' => bbp_get_topic_caps(),

    should say

    'capabilities' => bbp_get_forum_caps(),

    and my 2nd filter should then make that work, but for whatever reason it doesn’t.

    But as it gives the topic permissions which for a moderator are what you want for forums, it should be fine.

    @highgatecreative

    Participant

    Thanks! I’ll try it out later today. I appreciate your help!

    @robin-w

    Moderator

    kicked it round some more, and got to this as a better answer

    add_filter( 'bbp_get_caps_for_role', 'rew_moderator', 10, 2);
    
    function rew_moderator ($caps, $role) {
    	if ($role == bbp_get_moderator_role() ) {
    		$caps['edit_others_forums'] = true ;
    		$caps['delete_forums'] = true ;
    		$caps['delete_others_forums'] = true ;
    	}
    return $caps ;
    }
    
    add_filter ('bbp_map_forum_meta_caps', 'rew_mod', 10,4) ;
    
    function rew_mod ( $caps, $cap, $user_id, $args) {
    	switch ( $cap ) {
    	
    	case 'bbp_forums_admin'  :
    		if ( user_can( $user_id, 'moderate' ) ) {
    				$caps = array( 'moderate' );
    		}
    		
    	case 'edit_forums'         :
    	case 'edit_others_forums'  :
    	
    		if ( user_can( $user_id, 'moderate' ) ) {
    				$caps = array( 'moderate' );
    		}
    	
    	}
    	
    return $caps ;
    }

    @highgatecreative

    Participant

    This worked beautifully! Thank you so much for your help!!!

    @robin-w

    Moderator

    great – glad you are fixed

Viewing 9 replies - 1 through 9 (of 9 total)
  • You must be logged in to reply to this topic.