bbp_update_topic

Handle all the extra meta stuff from posting a new topic.

Description

bbp_update_topic( (int) $topic_id = 0, (int) $forum_id = 0, (constant) $anonymous_data = false, (int) $author_id = 0, (bool) $is_edit = false ); 

Parameters (5)

0. $topic_id — Optional. (int)
Topic id
1. $forum_id — Optional. (int)
Forum id
2. $anonymous_data — Optional. (constant) => false
Logged-out user data.
3. $author_id — Optional. (int)
The author id.
4. $is_edit — Optional. (bool) => false
Is the post being edited? Defaults to false.

Usage

  1. if ( !function_exists( 'bbp_update_topic' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'bbpress/includes/topics/functions.php'; 
  3.  
  4. // Optional. Topic id 
  5. $topic_id = -1; 
  6.  
  7. // Optional. Forum id 
  8. $forum_id = -1; 
  9.  
  10. // Optional logged-out user data. 
  11. $anonymous_data = false; 
  12.  
  13. // The author id. 
  14. $author_id = -1; 
  15.  
  16. // Optional. Is the post being edited? Defaults to false. 
  17. $is_edit = false; 
  18.  
  19. // NOTICE! Understand what this does before running. 
  20. $result = bbp_update_topic($topic_id, $forum_id, $anonymous_data, $author_id, $is_edit); 
  21.  

Defined (1)

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

/includes/topics/functions.php  
  1. function bbp_update_topic( $topic_id = 0, $forum_id = 0, $anonymous_data = false, $author_id = 0, $is_edit = false ) { 
  2.  
  3. // Validate the ID's passed from 'bbp_new_topic' action 
  4. $topic_id = bbp_get_topic_id( $topic_id ); 
  5. $forum_id = bbp_get_forum_id( $forum_id ); 
  6.  
  7. // Bail if there is no topic 
  8. if ( empty( $topic_id ) ) 
  9. return; 
  10.  
  11. // Check author_id 
  12. if ( empty( $author_id ) ) 
  13. $author_id = bbp_get_current_user_id(); 
  14.  
  15. // Check forum_id 
  16. if ( empty( $forum_id ) ) 
  17. $forum_id = bbp_get_topic_forum_id( $topic_id ); 
  18.  
  19. // If anonymous post, store name, email, website and ip in post_meta. 
  20. // It expects anonymous_data to be sanitized. 
  21. // Check bbp_filter_anonymous_post_data() for sanitization. 
  22. if ( !empty( $anonymous_data ) && is_array( $anonymous_data ) ) { 
  23.  
  24. // Parse arguments against default values 
  25. $r = bbp_parse_args( $anonymous_data, array( 
  26. 'bbp_anonymous_name' => '',  
  27. 'bbp_anonymous_email' => '',  
  28. 'bbp_anonymous_website' => '',  
  29. ), 'update_topic' ); 
  30.  
  31. // Update all anonymous metas 
  32. foreach ( $r as $anon_key => $anon_value ) { 
  33. update_post_meta( $topic_id, '_' . $anon_key, (string) $anon_value, false ); 
  34.  
  35. // Set transient for throttle check (only on new, not edit) 
  36. if ( empty( $is_edit ) ) { 
  37. set_transient( '_bbp_' . bbp_current_author_ip() . '_last_posted', time() ); 
  38.  
  39. } else { 
  40. if ( empty( $is_edit ) && !current_user_can( 'throttle' ) ) { 
  41. bbp_update_user_last_posted( $author_id ); 
  42.  
  43. // Handle Subscription Checkbox 
  44. if ( bbp_is_subscriptions_active() && !empty( $author_id ) ) { 
  45. $subscribed = bbp_is_user_subscribed( $author_id, $topic_id ); 
  46. $subscheck = ( !empty( $_POST['bbp_topic_subscription'] ) && ( 'bbp_subscribe' === $_POST['bbp_topic_subscription'] ) ) ? true : false; 
  47.  
  48. // Subscribed and unsubscribing 
  49. if ( true === $subscribed && false === $subscheck ) { 
  50. bbp_remove_user_subscription( $author_id, $topic_id ); 
  51.  
  52. // Subscribing 
  53. } elseif ( false === $subscribed && true === $subscheck ) { 
  54. bbp_add_user_subscription( $author_id, $topic_id ); 
  55.  
  56. // Forum topic meta 
  57. bbp_update_topic_forum_id( $topic_id, $forum_id ); 
  58. bbp_update_topic_topic_id( $topic_id, $topic_id ); 
  59.  
  60. // Update associated topic values if this is a new topic 
  61. if ( empty( $is_edit ) ) { 
  62.  
  63. // Update poster IP if not editing 
  64. update_post_meta( $topic_id, '_bbp_author_ip', bbp_current_author_ip(), false ); 
  65.  
  66. // Last active time 
  67. $last_active = current_time( 'mysql' ); 
  68.  
  69. // Reply topic meta 
  70. bbp_update_topic_last_reply_id ( $topic_id, 0 ); 
  71. bbp_update_topic_last_active_id ( $topic_id, $topic_id ); 
  72. bbp_update_topic_last_active_time ( $topic_id, $last_active ); 
  73. bbp_update_topic_reply_count ( $topic_id, 0 ); 
  74. bbp_update_topic_reply_count_hidden ( $topic_id, 0 ); 
  75. bbp_update_topic_voice_count ( $topic_id ); 
  76.  
  77. // Walk up ancestors and do the dirty work 
  78. bbp_update_topic_walker( $topic_id, $last_active, $forum_id, 0, false );