bb_delete_post

The BuddyPress bb delete post function.

Description

bb_delete_post( $post_id, (int) $new_status = 0 ); 

Parameters (2)

0. $post_id
The post id.
1. $new_status — Optional. (int)
The new status.

Usage

  1. if ( !function_exists( 'bb_delete_post' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'buddypress/bp-forums/bbpress/bb-includes/functions.bb-posts.php'; 
  3.  
  4. // The post id. 
  5. $post_id = null; 
  6.  
  7. // The new status. 
  8. $new_status = -1; 
  9.  
  10. // NOTICE! Understand what this does before running. 
  11. $result = bb_delete_post($post_id, $new_status); 
  12.  

Defined (2)

The function is defined in the following location(s).

/bp-forums/bbpress/bb-includes/functions.bb-posts.php  
  1. function bb_delete_post( $post_id, $new_status = 0 ) { 
  2. global $bbdb, $topic, $bb_post; 
  3. $post_id = (int) $post_id; 
  4. $bb_post = bb_get_post ( $post_id ); 
  5. $new_status = (int) $new_status; 
  6. $old_status = (int) $bb_post->post_status; 
  7. $topic = get_topic( $bb_post->topic_id ); 
  8. $topic_id = (int) $topic->topic_id; 
  9.  
  10. if ( $bb_post ) { 
  11. $uid = (int) $bb_post->poster_id; 
  12. if ( $new_status == $old_status ) 
  13. return; 
  14. _bb_delete_post( $post_id, $new_status ); 
  15. if ( 0 == $old_status ) { 
  16. bb_update_topicmeta( $topic_id, 'deleted_posts', $topic->deleted_posts + 1 ); 
  17. $bbdb->query( $bbdb->prepare( "UPDATE $bbdb->forums SET posts = posts - 1 WHERE forum_id = %d", $topic->forum_id ) ); 
  18. } else if ( 0 == $new_status ) { 
  19. bb_update_topicmeta( $topic_id, 'deleted_posts', $topic->deleted_posts - 1 ); 
  20. $bbdb->query( $bbdb->prepare( "UPDATE $bbdb->forums SET posts = posts + 1 WHERE forum_id = %d", $topic->forum_id ) ); 
  21. $posts = (int) $bbdb->get_var( $bbdb->prepare( "SELECT COUNT(*) FROM $bbdb->posts WHERE topic_id = %d AND post_status = 0", $topic_id ) ); 
  22. $bbdb->update( $bbdb->topics, array( 'topic_posts' => $posts ), compact( 'topic_id' ) ); 
  23.  
  24. if ( 0 == $posts ) { 
  25. if ( 0 == $topic->topic_status || 1 == $new_status ) 
  26. bb_delete_topic( $topic_id, $new_status ); 
  27. } else { 
  28. if ( 0 != $topic->topic_status ) { 
  29. $bbdb->update( $bbdb->topics, array( 'topic_status' => 0 ), compact( 'topic_id' ) ); 
  30. $bbdb->query( $bbdb->prepare( "UPDATE $bbdb->forums SET topics = topics + 1 WHERE forum_id = %d", $topic->forum_id ) ); 
  31. bb_topic_set_last_post( $topic_id ); 
  32. bb_update_post_positions( $topic_id ); 
  33. bb_update_topic_voices( $topic_id ); 
  34.  
  35. $user = bb_get_user( $uid ); 
  36.  
  37. $user_posts = new BB_Query( 'post', array( 'post_author_id' => $user->ID, 'topic_id' => $topic_id ) ); 
  38. if ( $new_status && !$user_posts->results ) { 
  39. $topics_replied_key = $bbdb->prefix . 'topics_replied'; 
  40. bb_update_usermeta( $user->ID, $topics_replied_key, $user->$topics_replied_key - 1 ); 
  41. wp_cache_delete( $topic_id, 'bb_topic' ); 
  42. wp_cache_delete( $topic_id, 'bb_thread' ); 
  43. wp_cache_flush( bb_query ); 
  44. wp_cache_flush( 'bb_cache_posts_post_ids' ); 
  45. do_action( 'bb_delete_post', $post_id, $new_status, $old_status ); 
  46. return $post_id; 
  47. } else { 
  48. return false; 
  1. function _bb_delete_post( $post_id, $post_status ) { 
  2. global $bbdb; 
  3. $post_id = (int) $post_id; 
  4. $post_status = (int) $post_status; 
  5. $bbdb->update( $bbdb->posts, compact( 'post_status' ), compact( 'post_id' ) ); 
  6. wp_cache_delete( $post_id, 'bb_post' ); 
  7. do_action( '_bb_delete_post', $post_id, $post_status );