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
Parameters
- $reply_data
-
(Optional) Forum post data
Default value: array()
- $reply_meta
-
(Optional) Forum meta data
Default value: array()
Source
File: bp-forums/replies/functions.php
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 | function bbp_insert_reply( $reply_data = array (), $reply_meta = array () ) { // Forum $reply_data = bbp_parse_args( $reply_data , array ( 'post_parent' => 0, // topic ID 'post_status' => bbp_get_public_status_id(), 'post_type' => bbp_get_reply_post_type(), 'post_author' => bbp_get_current_user_id(), 'post_password' => '' , 'post_content' => '' , 'post_title' => '' , 'menu_order' => 0, 'comment_status' => 'closed' ), 'insert_reply' ); // Insert reply $reply_id = wp_insert_post( $reply_data ); // Bail if no reply was added if ( empty ( $reply_id ) ) { return false; } // Forum meta $reply_meta = bbp_parse_args( $reply_meta , array ( 'author_ip' => bbp_current_author_ip(), 'forum_id' => 0, 'topic_id' => 0, ), 'insert_reply_meta' ); // Insert reply meta foreach ( $reply_meta as $meta_key => $meta_value ) { update_post_meta( $reply_id , '_bbp_' . $meta_key , $meta_value ); } // Update the topic $topic_id = bbp_get_reply_topic_id( $reply_id ); if ( ! empty ( $topic_id ) ) { bbp_update_topic( $topic_id ); } // Return new reply ID return $reply_id ; } |
Changelog
Version | Description |
---|---|
bbPress (r3349) | Introduced. |
Questions?
We're always happy to help with code or other questions you might have! Search our developer docs, contact support, or connect with our sales team.