Change WordPress user roles and capabilities › Forums › Give user access to plugin – how to › Allow bbPress participants to delete their own topics
- This topic has 5 replies, 2 voices, and was last updated 7 years, 5 months ago by Vladimir.
-
AuthorPosts
-
23/06/2017 at 10:57 #3889capacanadaParticipant
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
24/06/2017 at 14:02 #3892VladimirKeymasterHi,
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.24/06/2017 at 14:04 #3893VladimirKeymasterIt’s possible to modify a default bbPress access model using its custom filters:
‘bbp_map_reply_meta_caps’, ‘bbp_map_topic_meta_caps’.25/06/2017 at 09:20 #3894capacanadaParticipantHi. 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?
Thanks26/06/2017 at 13:38 #3896VladimirKeymasterHi,
I will try to help you as I return to office, at June, 29th.
29/06/2017 at 11:16 #3909VladimirKeymasterHi,
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; }
-
AuthorPosts
- You must be logged in to reply to this topic.