/**
 * A wrapper for wp_insert_post() that also includes the necessary meta values
 * for the reply to function properly.
 *
 * @since 2.0.0 bbPress (r3349)
 *
 * @uses bbp_parse_args()
 * @uses bbp_get_reply_post_type()
 * @uses wp_insert_post()
 * @uses update_post_meta()
 *
 * @param array $reply_data Forum post data
 * @param arrap $reply_meta Forum meta data
 */
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, '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' => bbp_get_topic_reply_count($reply_data['post_parent'], true) + 1, '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;
    }
    // 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) {
        update_post_meta($reply_id, '_bbp_' . $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 new reply ID
    return $reply_id;
}
Exemple #2
0
 /**
  * Pass the reply attributes for processing
  *
  * @since 2.0.0 bbPress (r2746)
  *
  * @param int $reply_id Reply id
  * @uses current_user_can() To check if the current user is capable of
  *                           editing the reply
  * @uses do_action() Calls 'bbp_reply_attributes_metabox_save' with the
  *                    reply id and parent id
  * @return int Parent id
  */
 public function attributes_metabox_save($reply_id)
 {
     if ($this->bail()) {
         return $reply_id;
     }
     // Bail if doing an autosave
     if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {
         return $reply_id;
     }
     // Bail if not a post request
     if (!bbp_is_post_request()) {
         return $reply_id;
     }
     // Check action exists
     if (empty($_POST['action'])) {
         return $reply_id;
     }
     // Nonce check
     if (empty($_POST['bbp_reply_metabox']) || !wp_verify_nonce($_POST['bbp_reply_metabox'], 'bbp_reply_metabox_save')) {
         return $reply_id;
     }
     // Current user cannot edit this reply
     if (!current_user_can('edit_reply', $reply_id)) {
         return $reply_id;
     }
     // Get the reply meta post values
     $topic_id = !empty($_POST['parent_id']) ? (int) $_POST['parent_id'] : 0;
     $forum_id = !empty($_POST['bbp_forum_id']) ? (int) $_POST['bbp_forum_id'] : bbp_get_topic_forum_id($topic_id);
     $reply_to = !empty($_POST['bbp_reply_to']) ? (int) $_POST['bbp_reply_to'] : 0;
     // Get reply author data
     $anonymous_data = bbp_filter_anonymous_post_data();
     $author_id = bbp_get_reply_author_id($reply_id);
     $is_edit = isset($_POST['hidden_post_status']) && $_POST['hidden_post_status'] !== 'draft';
     // Formally update the reply
     bbp_update_reply($reply_id, $topic_id, $forum_id, $anonymous_data, $author_id, $is_edit, $reply_to);
     // Allow other fun things to happen
     do_action('bbp_reply_attributes_metabox_save', $reply_id, $topic_id, $forum_id, $reply_to);
     do_action('bbp_author_metabox_save', $reply_id, $anonymous_data);
     return $reply_id;
 }
Exemple #3
0
 /**
  * Pass the reply attributes for processing
  *
  * @since bbPress (r2746)
  *
  * @param int $reply_id Reply id
  * @uses current_user_can() To check if the current user is capable of
  *                           editing the reply
  * @uses do_action() Calls 'bbp_reply_attributes_metabox_save' with the
  *                    reply id and parent id
  * @return int Parent id
  */
 public function reply_attributes_metabox_save($reply_id)
 {
     if ($this->bail()) {
         return $reply_id;
     }
     // Bail if doing an autosave
     if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {
         return $reply_id;
     }
     // Bail if not a post request
     if ('POST' != strtoupper($_SERVER['REQUEST_METHOD'])) {
         return $reply_id;
     }
     // Check action exists
     if (empty($_POST['action'])) {
         return $reply_id;
     }
     // Nonce check
     if (empty($_POST['bbp_reply_metabox']) || !wp_verify_nonce($_POST['bbp_reply_metabox'], 'bbp_reply_metabox_save')) {
         return $reply_id;
     }
     // Current user cannot edit this reply
     if (!current_user_can('edit_reply', $reply_id)) {
         return $reply_id;
     }
     // Get the reply meta post values
     $topic_id = !empty($_POST['parent_id']) ? (int) $_POST['parent_id'] : 0;
     $forum_id = !empty($_POST['bbp_forum_id']) ? (int) $_POST['bbp_forum_id'] : bbp_get_topic_forum_id($topic_id);
     // Formally update the reply
     bbp_update_reply($reply_id, $topic_id, $forum_id);
     // Allow other fun things to happen
     do_action('bbp_reply_attributes_metabox_save', $reply_id, $topic_id, $forum_id);
     return $reply_id;
 }
Exemple #4
0
 public function update_object($reply_id, $fields)
 {
     $fields['reply_id'] = $reply_id;
     return bbp_update_reply($fields);
 }