bbp_insert_reply( array $reply_data = array(), arrap $reply_meta = array() )
A wrapper for wp_insert_post() that also includes the necessary meta values for the reply to function properly.
Description Description
Parameters Parameters
- $reply_data
-
(Optional) Forum post data
Default value: array()
- $reply_meta
-
(Optional) Forum meta data
Default value: array()
Source Source
File: includes/replies/functions.php
function bbp_insert_reply( $reply_data = array(), $reply_meta = array() ) {
// Parse arguments against default values
$reply_data = bbp_parse_args( $reply_data, array(
'post_parent' => 0, // topic ID
'post_type' => bbp_get_reply_post_type(),
'post_author' => bbp_get_current_user_id(),
'post_password' => '',
'post_content' => '',
'post_title' => '',
'menu_order' => bbp_get_topic_reply_count( $reply_data['post_parent'], true ) + 1,
'comment_status' => 'closed'
), 'insert_reply' );
// Possibly override status based on parent topic
if ( ! empty( $reply_data['post_parent'] ) && empty( $reply_data['post_status'] ) ) {
$reply_data['post_status'] = bbp_get_topic_status( $reply_data['post_parent'] );
}
// Insert reply
$reply_id = wp_insert_post( $reply_data, false );
// Bail if no reply was added
if ( empty( $reply_id ) ) {
return false;
}
// Parse arguments against default values
$reply_meta = bbp_parse_args( $reply_meta, array(
'author_ip' => bbp_current_author_ip(),
'forum_id' => 0,
'topic_id' => 0,
'reply_to' => 0
), 'insert_reply_meta' );
// Insert reply meta
foreach ( $reply_meta as $meta_key => $meta_value ) {
// Prefix if not prefixed
if ( '_bbp_' !== substr( $meta_key, 0, 5 ) ) {
$meta_key = '_bbp_' . $meta_key;
}
// Update the meta
update_post_meta( $reply_id, $meta_key, $meta_value );
}
// Update the reply and hierarchy
bbp_update_reply( $reply_id, $reply_meta['topic_id'], $reply_meta['forum_id'], array(), $reply_data['post_author'], false, $reply_meta['reply_to'] );
/**
* Fires after reply has been inserted via `bbp_insert_reply`.
*
* @since 2.6.0 bbPress (r6036)
*
* @param int $reply_id The reply id.
* @param int $reply_meta['topic_id'] The reply topic meta.
* @param int $reply_meta['forum_id'] The reply forum meta.
*/
do_action( 'bbp_insert_reply', (int) $reply_id, (int) $reply_meta['topic_id'], (int) $reply_meta['forum_id'] );
// Return reply_id
return $reply_id;
}
Changelog Changelog
| Version | Description |
|---|---|
| 2.0.0 | Introduced. |