Title: Allow users delete their posts
Last modified: May 4, 2025

---

# Allow users delete their posts

 *  Resolved [WPabmm](https://wordpress.org/support/users/aboutm2/)
 * (@aboutm2)
 * [1 year, 1 month ago](https://wordpress.org/support/topic/allow-users-delete-their-posts/)
 * Hi Robin,
 * Thank you for this plugin.
 * I appreciate that your plugin has the option to enable users to delete their 
   own posts.
 * Could I ask how I could enable this using a code snippet alone?
 * The page I need help with: _[[log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fwordpress.org%2Fsupport%2Ftopic%2Fallow-users-delete-their-posts%2F%3Foutput_format%3Dmd&locale=en_US)
   to see the link]_

Viewing 1 replies (of 1 total)

 *  Plugin Author [Robin W](https://wordpress.org/support/users/robin-w/)
 * (@robin-w)
 * [1 year, 1 month ago](https://wordpress.org/support/topic/allow-users-delete-their-posts/#post-18449171)
 * This is the code for that section, but you’ll need to see if it works, sorry,
   but I do not have time to make a code snippet for the hundreds of things that
   my plugin does.
 *     ```wp-block-code
       ///********allow users to trash own topics/repliesif (!empty($bsp_style_settings_t['participant_trash_topic']) && is_user_logged_in()) { 	/*Customize the BBPress roles to allow Participants to trash topics*/	add_filter( 'bbp_get_caps_for_role', 'bsp_add_topic_caps_filter', 10, 2 );	/*then only allow participants to trash their own topics*/	add_filter( 'bbp_map_topic_meta_caps', 'bsp_tweak_trash_topic_caps', 11, 4 );	//then redirect to the forum after trashing topic	add_action('bbp_template_redirect', 'bsp_trash_topic_check', 8);}if (!empty($bsp_style_settings_t['participant_trash_reply']) && is_user_logged_in()) { 	/*Customize the BBPress roles to allow Participants to trash replies*/	add_filter( 'bbp_get_caps_for_role', 'bsp_add_reply_caps_filter', 10, 2 );	/*then only allow participants to trash their own replies*/	add_filter( 'bbp_map_reply_meta_caps', 'bsp_tweak_trash_reply_caps', 11, 4 );}function bsp_add_topic_caps_filter( $caps, $role ){        // Only filter for roles we are interested in!        if( $role == bbp_get_participant_role() ) {		//only change delete topics 		$caps ['delete_topics']= true;	}	return $caps;}function bsp_add_reply_caps_filter( $caps, $role ){        // Only filter for roles we are interested in!        if( $role == bbp_get_participant_role() ) {		//only change delete topics 		$caps ['delete_replies']= true;	}	return $caps;}function bsp_tweak_trash_topic_caps( $caps, $cap, $user_id, $args ){	// apply only to delete_topic	if ( $cap == "delete_topic" ){		// Get the post		$_post = get_post( $args[0] );		if ( !empty( $_post ) ) {                        // Get caps for post type object                        $post_type = get_post_type_object( $_post->post_type );                        // Add 'do_not_allow' cap if user is spam or deleted                        if ( bbp_is_user_inactive( $user_id ) ) {                                $caps[] = 'do_not_allow';                        // Moderators can always edit forum content                        } elseif ( user_can( $user_id, 'moderate' ) ) {                                $caps[] = 'moderate';                        // User is author so allow edit if not in admin                        } elseif ( user_can( $user_id, 'participate' ) && ( (int) $user_id === (int) $_post->post_author ) ) {                                $caps = array();                        // Unknown so do not allow                        } else {                                $caps[] = 'do_not_allow';                        }		}	}		// return the capabilities	return $caps;}function bsp_tweak_trash_reply_caps( $caps, $cap, $user_id, $args ){	// apply only to delete_reply	if ( $cap == "delete_reply" ){		// Get the post		$_post = get_post( $args[0] );		if ( !empty( $_post ) ) {			// Get caps for post type object			$post_type = get_post_type_object( $_post->post_type );						// Add 'do_not_allow' cap if user is spam or deleted			if ( bbp_is_user_inactive( $user_id ) ) {				$caps[] = 'do_not_allow';			// Moderators can always edit forum content			} elseif ( user_can( $user_id, 'moderate' ) ) {				$caps[] = 'moderate';			// User is author so allow edit if not in admin                        } elseif ( user_can( $user_id, 'participate' ) && ( (int) $user_id === (int) $_post->post_author ) ) {                                $caps = array();							// Unknown so do not allow			} else {				$caps[] = 'do_not_allow';			}		}	}		// return the capabilities	return $caps;}//check if topic has been trashed by author and show forum if it hasfunction bsp_trash_topic_check() {	$topic_slug = get_option( '_bbp_topic_slug');	//quick check if we need to do this function, so bail if not a topic	if (strpos($_SERVER['REQUEST_URI'], $topic_slug) == FALSE) return;	$forum_slug = bbp_get_root_slug();	//if check is set (ie we prefix forums with the forum slug) then part 1 will be forum slug and part 2 will be topic slug, if not part 1 will be topic slug	$check = bbp_include_root_slug();	$link = explode('/', $_SERVER['REQUEST_URI']);	//next we need the topic id (post id) of the topic so we need to check if it is a topic and if so, find the topic id	if ($check && $link[1] == $forum_slug && $link[2] == $topic_slug ) {		$post = bsp_get_page_by_slug( $link[3], OBJECT, 'topic' );		if (!empty ($post)) $login_check=1;        } 	elseif (empty($check) && $link[1] === $topic_slug) {		$post = bsp_get_page_by_slug( $link[2], OBJECT, 'topic' );		if (!empty ($post)) $login_check=1;	}	//now we need to check if the topic has been trashed by author	if (!empty ($login_check) && $post->post_status == 'trash' && $post->post_author == get_current_user_id() ) {		$topic_id = $post->ID;		//then redirect to the forum we came from		$forum = bbp_get_forum_permalink (bbp_get_topic_forum_id ( $topic_id ));		wp_redirect ($forum);		exit;	}	else return;}
       ```
   

Viewing 1 replies (of 1 total)

The topic ‘Allow users delete their posts’ is closed to new replies.

 * ![](https://ps.w.org/bbp-style-pack/assets/icon-256x256.jpg?rev=2706563)
 * [bbp style pack](https://wordpress.org/plugins/bbp-style-pack/)
 * [Support Threads](https://wordpress.org/support/plugin/bbp-style-pack/)
 * [Active Topics](https://wordpress.org/support/plugin/bbp-style-pack/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/bbp-style-pack/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/bbp-style-pack/reviews/)

 * 2 replies
 * 2 participants
 * Last reply from: [Robin W](https://wordpress.org/support/users/robin-w/)
 * Last activity: [1 year, 1 month ago](https://wordpress.org/support/topic/allow-users-delete-their-posts/#post-18449171)
 * Status: resolved