bbp_insert_reply

A wrapper for wp_insert_post() that also includes the necessary meta values for the reply to function properly.

Description

bbp_insert_reply( (array) $reply_data = array(), (array) $reply_meta = array() ); 

Parameters (2)

0. $reply_data — Optional. (array) => array()
The reply data.
1. $reply_meta — Optional. (array) => array()
The reply meta.

Usage

  1. if ( !function_exists( 'bbp_insert_reply' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'bbpress/includes/replies/functions.php'; 
  3.  
  4. // The reply data. 
  5. $reply_data = array(); 
  6.  
  7. // The reply meta. 
  8. $reply_meta = array(); 
  9.  
  10. // NOTICE! Understand what this does before running. 
  11. $result = bbp_insert_reply($reply_data, $reply_meta); 
  12.  

Defined (1)

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

/includes/replies/functions.php  
  1. function bbp_insert_reply( $reply_data = array(), $reply_meta = array() ) { 
  2.  
  3. // Forum 
  4. $reply_data = bbp_parse_args( $reply_data, array( 
  5. 'post_parent' => 0, // topic ID 
  6. 'post_status' => bbp_get_public_status_id(),  
  7. 'post_type' => bbp_get_reply_post_type(),  
  8. 'post_author' => bbp_get_current_user_id(),  
  9. 'post_password' => '',  
  10. 'post_content' => '',  
  11. 'post_title' => '',  
  12. 'menu_order' => 0,  
  13. 'comment_status' => 'closed' 
  14. ), 'insert_reply' ); 
  15.  
  16. // Insert reply 
  17. $reply_id = wp_insert_post( $reply_data ); 
  18.  
  19. // Bail if no reply was added 
  20. if ( empty( $reply_id ) ) { 
  21. return false; 
  22.  
  23. // Forum meta 
  24. $reply_meta = bbp_parse_args( $reply_meta, array( 
  25. 'author_ip' => bbp_current_author_ip(),  
  26. 'forum_id' => 0,  
  27. 'topic_id' => 0,  
  28. ), 'insert_reply_meta' ); 
  29.  
  30. // Insert reply meta 
  31. foreach ( $reply_meta as $meta_key => $meta_value ) { 
  32. update_post_meta( $reply_id, '_bbp_' . $meta_key, $meta_value ); 
  33.  
  34. // Update the topic 
  35. $topic_id = bbp_get_reply_topic_id( $reply_id ); 
  36. if ( !empty( $topic_id ) ) { 
  37. bbp_update_topic( $topic_id ); 
  38.  
  39. // Return new reply ID 
  40. return $reply_id;