Change WordPress user roles and capabilities Forums Give user access to plugin – how to Allow bbPress participants to delete their own topics

This topic contains 5 replies, has 2 voices, and was last updated by  Vladimir 2 years, 2 months ago.

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #3889

    capacanada
    Participant

    Hi

    I would like to allow bbpress participants to delete their own topics. I have set this in the user role editor but it does not work. http://prntscr.com/fn87po. I am in my topic but it does not have a delete button: http://prntscr.com/fn8838.

    Thanks

    #3892

    Vladimir
    Keymaster

    Hi,

    bbPress uses a different model of work with topics and replies privileges comparing to the WordPress posts. While bbPress adds ‘delete_topics’, ‘delete_replies’ it really uses just ‘delete_others_topics’ (includes/topics/capabilities.php, line #180) and ‘delete_others_replies’ (includes/replies/capabilities.php, line #162). So default bbPress permissions model does not allow to a user to delete his own content. User should have a ‘moderate’ or ‘delete_others_%’ capability to get access to delete operation. But with this access user can delete a content from any user/author.

    #3893

    Vladimir
    Keymaster

    It’s possible to modify a default bbPress access model using its custom filters:
    ‘bbp_map_reply_meta_caps’, ‘bbp_map_topic_meta_caps’.

    #3894

    capacanada
    Participant

    Hi. Thanks for the feedback. I am not sure what I would need to with regards to your second response, could you please explain a bit more in detail?
    Thanks

    #3896

    Vladimir
    Keymaster

    Hi,

    I will try to help you as I return to office, at June, 29th.

    #3909

    Vladimir
    Keymaster

    Hi,
    In order to force bbPress to use ‘delete_replies’ and ‘delete_topics’ capabilities for content authours add this code to your active theme functions.php file or setup it as a “must use” plugin:

    
    add_filter('bbp_map_reply_meta_caps', 'bbp_delete_own_replies', 10, 4);
    
    function bbp_delete_own_replies($caps, $cap, $user_id, $args) {
        if ($cap!=='delete_reply' || in_array('do_not_allow', $caps)) {  
            return $caps;        
        }
        
        $_post = get_post( $args[0] );
        if (empty($_post)) {
            return $caps;
        }
        
        if ($_post->post_author==$user_id) {
            $caps = array('delete_replies');
        }
        
        return $caps;    
    }
    
    add_filter('bbp_map_topic_meta_caps', 'bbp_delete_own_topics', 10, 4);
    
    function bbp_delete_own_topics($caps, $cap, $user_id, $args) {
    
        if ($cap=='delete_topic' || in_array('do_not_allow', $caps)) {
            return $caps;
        }
        
        $_post = get_post( $args[0] );
        if (empty($_post)) {
            return $caps;
        }
        
        if ($_post->post_author==$user_id) {
            $caps = array('delete_topics');
        }
        
        return $caps;
    }
    
Viewing 6 posts - 1 through 6 (of 6 total)

You must be logged in to reply to this topic.