bbp_update_reply

Handle all the extra meta stuff from posting a new reply or editing a reply.

Description

bbp_update_reply( (int) $reply_id = 0, (int) $topic_id = 0, (int) $forum_id = 0, (constant) $anonymous_data = false, (int) $author_id = 0, (constant) $is_edit = false, (int) $reply_to = 0 ); 

Parameters (7)

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

Usage

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

Defined (1)

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

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