Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #6853
    susanrangitsch
    Spectator

    I’m trying to prevent all users with the Participant (bbpress) role from being able to create topics. They should only be able to reply to existing topics.

    I’ve unchecked the box for publish_topics but my test users can still post new topics. What am I missing?

    #6855
    Vladimir
    Keymaster

    bbPress checks if user can create topic ising the function from the bbpress/includes/users/template.php, #2253

    
    function bbp_current_user_can_access_create_topic_form() {
    
    	// Users need to earn access
    	$retval = false;
    
    	// Always allow keymasters
    	if ( bbp_is_user_keymaster() ) {
    		$retval = true;
    
    	// Looking at a single forum & forum is open
    	} elseif ( ( bbp_is_single_forum() || is_page() || is_single() ) && bbp_is_forum_open() ) {
    		$retval = bbp_current_user_can_publish_topics();
    
    	// User can edit this topic
    	} else {
    		$retval = current_user_can( 'edit_topic', bbp_get_topic_id() );
    	}
    
    	// Filter & return
    	return (bool) apply_filters( 'bbp_current_user_can_access_create_topic_form', (bool) $retval );
    }
    

    It shows that some time bbPress checks publish_topics, some times ‘edit_topics. But the good news that bbPress offers custom filter bbp_current_user_can_access_create_topic_form where you can check you own capability, like ‘create_topics’ and participant role will can not create topics until you will not grant ‘create_topics’ to it. Like below:

    
    add_filter( 'bbp_current_user_can_access_create_topic_form', 'bbp_current_user_can_create_topic', 10, 1 );
    function bbp_current_user_can_create_topic( $ret_val ) {
        $ret_val = current_user_can( 'create_topics' );
        
        return $ret_val;
    }
    

    You may add this code to the active theme’s functions.php file of or setup it as a Must Use plugin.

    #6856
    susanrangitsch
    Spectator

    Thanks for the reply. I’m a little confused… I thought that this was one of the capabilities of the pro version of the plugin. If I’m having to enter code, that does not seem like the case.

    #6857
    Vladimir
    Keymaster

    bbPress checks capability to create topic own way, not as WordPress itself does for any post type:

    
    if ( current_user_can( $post_type_object->cap->create_posts ) ) {
    

    That’s why URE Pro currently does not change bbPress logic to use ‘create_topics’ as expected, even with correspondent option is turned ON at URE’s settings. I will include the fix to the next update.

    Thank you for pointing me this. You may use the solution offered above as a temporal workaround until I will publish the version of URE Pro which will support this correctly.

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