Change WordPress user roles and capabilities › Forums › Give user access to plugin – how to › Allow bbPress participants to delete their own topics › Reply To: Allow bbPress participants to delete their own topics
29/06/2017 at 11:16
#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;
}