function remove_topic_custom() { $post = get_post($_POST['id']); if ($post->post_author == get_current_user_id()) { bbp_delete_topic($_POST['id']); wp_delete_post($_POST['id'], true); } die(json_encode(array('result' => 'OK'))); }
/** * Delete the bbPress topic associated with a post being deleted unless: * - that topic is also associated with another post * - cancelled by 'bbppt_do_delete_topic' filter * @param int post_ID ID of the post being deleted */ function maybe_delete_topic($post_ID) { if (get_post_meta($post_ID, 'use_bbpress_discussion_topic', true)) { $topic_ID = get_post_meta($post_ID, 'bbpress_discussion_topic_id', true); $affected_posts = get_posts(array('post_type' => apply_filters('bbppt_eligible_post_types', array('post', 'page')), 'meta_key' => 'bbpress_discussion_topic_id', 'meta_value' => $topic_ID)); if (count($affected_posts) == 1 && apply_filters('bbppt_do_delete_topic', true, $topic_ID)) { // Delete topic bbp_delete_topic($topic_ID); } } }