Пример #1
0
/**
 * A wrapper for wp_insert_post() that also includes the necessary meta values
 * for the topic to function properly.
 *
 * @since 2.0.0 bbPress (r3349)
 *
 * @uses bbp_parse_args()
 * @uses bbp_get_topic_post_type()
 * @uses wp_insert_post()
 * @uses update_post_meta()
 *
 * @param array $topic_data Forum post data
 * @param arrap $topic_meta Forum meta data
 */
function bbp_insert_topic($topic_data = array(), $topic_meta = array())
{
    // Parse arguments against default values
    $topic_data = bbp_parse_args($topic_data, array('post_parent' => 0, 'post_status' => bbp_get_public_status_id(), 'post_type' => bbp_get_topic_post_type(), 'post_author' => bbp_get_current_user_id(), 'post_password' => '', 'post_content' => '', 'post_title' => '', 'comment_status' => 'closed', 'menu_order' => 0), 'insert_topic');
    // Insert topic
    $topic_id = wp_insert_post($topic_data);
    // Bail if no topic was added
    if (empty($topic_id)) {
        return false;
    }
    // Parse arguments against default values
    $topic_meta = bbp_parse_args($topic_meta, array('author_ip' => bbp_current_author_ip(), 'forum_id' => 0, 'topic_id' => $topic_id, 'voice_count' => 1, 'reply_count' => 0, 'reply_count_hidden' => 0, 'last_reply_id' => 0, 'last_active_id' => $topic_id, 'last_active_time' => get_post_field('post_date', $topic_id, 'db')), 'insert_topic_meta');
    // Insert topic meta
    foreach ($topic_meta as $meta_key => $meta_value) {
        update_post_meta($topic_id, '_bbp_' . $meta_key, $meta_value);
    }
    // Update the topic and hierarchy
    bbp_update_topic($topic_id, $topic_meta['forum_id'], array(), $topic_data['post_author'], false);
    /**
     * Fires after topic has been inserted via `bbp_insert_topic`.
     *
     * @since 2.6.0 bbPress (r6036)
     *
     * @param int $topic_id               The topic id.
     * @param int $topic_meta['forum_id'] The topic forum meta.
     */
    do_action('bbp_insert_topic', (int) $topic_id, (int) $topic_meta['forum_id']);
    // Return new topic ID
    return $topic_id;
}
Пример #2
0
/**
 * A wrapper for wp_insert_post() that also includes the necessary meta values
 * for the reply to function properly.
 *
 * @since 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())
{
    // Forum
    $default_reply = 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' => 0, 'comment_status' => 'closed');
    $reply_data = bbp_parse_args($reply_data, $default_reply, '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
    $default_meta = array('author_ip' => bbp_current_author_ip(), 'forum_id' => 0, 'topic_id' => 0);
    $reply_meta = bbp_parse_args($reply_meta, $default_meta, '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;
}
Пример #3
0
 /**
  * When inserting a new reply, make sure the protected meta data is set correctly.
  *
  * We can't use WP_JSON_Posts::add_meta() here because the required meta is deemed
  * protected by @see is_protected_meta().
  *
  * @see WP_JSON_Posts::insert_post()
  * @see WP_JSON_Posts::add_meta()
  */
 public function add_protected_meta($post, $data, $update)
 {
     if (!$update && $this->type == $post['post_type']) {
         // Forum meta
         $reply_meta = array('author_ip' => bbp_current_author_ip(), 'forum_id' => bbp_get_topic_forum_id($post['post_parent']), 'topic_id' => $post['post_parent']);
         // Insert reply meta
         foreach ($reply_meta as $meta_key => $meta_value) {
             update_post_meta($post['ID'], '_bbp_' . $meta_key, $meta_value);
         }
         // Update the topic
         $topic_id = bbp_get_reply_topic_id($post['ID']);
         if (!empty($topic_id)) {
             bbp_update_topic($topic_id);
         }
     }
 }
Пример #4
0
 /**
  * @covers ::bbp_get_user_topics_started
  */
 public function test_bbp_get_user_topics_started()
 {
     $u = $this->factory->user->create();
     $has_topics = bbp_get_user_topics_started($u);
     $this->assertFalse($has_topics);
     $t = $this->factory->topic->create_many(3, array('post_author' => $u));
     bbp_update_topic(array('topic_id' => $t));
     $has_topics = bbp_get_user_topics_started($u);
     $this->assertTrue($has_topics);
 }
Пример #5
0
 /**
  * Pass the topic attributes for processing
  *
  * @since 2.0.0 bbPress (r2746)
  *
  * @param int $topic_id Topic id
  * @uses current_user_can() To check if the current user is capable of
  *                           editing the topic
  * @uses do_action() Calls 'bbp_topic_attributes_metabox_save' with the
  *                    topic id and parent id
  * @return int Parent id
  */
 public function attributes_metabox_save($topic_id)
 {
     if ($this->bail()) {
         return $topic_id;
     }
     // Bail if doing an autosave
     if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {
         return $topic_id;
     }
     // Bail if not a post request
     if (!bbp_is_post_request()) {
         return $topic_id;
     }
     // Nonce check
     if (empty($_POST['bbp_topic_metabox']) || !wp_verify_nonce($_POST['bbp_topic_metabox'], 'bbp_topic_metabox_save')) {
         return $topic_id;
     }
     // Bail if current user cannot edit this topic
     if (!current_user_can('edit_topic', $topic_id)) {
         return $topic_id;
     }
     // Get the forum ID
     $forum_id = !empty($_POST['parent_id']) ? (int) $_POST['parent_id'] : 0;
     // Get topic author data
     $anonymous_data = bbp_filter_anonymous_post_data();
     $author_id = bbp_get_topic_author_id($topic_id);
     $is_edit = isset($_POST['hidden_post_status']) && $_POST['hidden_post_status'] !== 'draft';
     // Formally update the topic
     bbp_update_topic($topic_id, $forum_id, $anonymous_data, $author_id, $is_edit);
     // Stickies
     if (!empty($_POST['bbp_stick_topic']) && in_array($_POST['bbp_stick_topic'], array('stick', 'super', 'unstick'))) {
         // What's the haps?
         switch ($_POST['bbp_stick_topic']) {
             // Sticky in this forum
             case 'stick':
                 bbp_stick_topic($topic_id);
                 break;
                 // Super sticky in all forums
             // Super sticky in all forums
             case 'super':
                 bbp_stick_topic($topic_id, true);
                 break;
                 // Normal
             // Normal
             case 'unstick':
             default:
                 bbp_unstick_topic($topic_id);
                 break;
         }
     }
     // Allow other fun things to happen
     do_action('bbp_topic_attributes_metabox_save', $topic_id, $forum_id);
     do_action('bbp_author_metabox_save', $topic_id, $anonymous_data);
     return $topic_id;
 }
Пример #6
0
 /**
  * Pass the topic attributes for processing
  *
  * @since bbPress (r2746)
  *
  * @param int $topic_id Topic id
  * @uses current_user_can() To check if the current user is capable of
  *                           editing the topic
  * @uses do_action() Calls 'bbp_topic_attributes_metabox_save' with the
  *                    topic id and parent id
  * @return int Parent id
  */
 public function attributes_metabox_save($topic_id)
 {
     if ($this->bail()) {
         return $topic_id;
     }
     // Bail if doing an autosave
     if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {
         return $topic_id;
     }
     // Bail if not a post request
     if ('POST' != strtoupper($_SERVER['REQUEST_METHOD'])) {
         return $topic_id;
     }
     // Nonce check
     if (empty($_POST['bbp_topic_metabox']) || !wp_verify_nonce($_POST['bbp_topic_metabox'], 'bbp_topic_metabox_save')) {
         return $topic_id;
     }
     // Bail if current user cannot edit this topic
     if (!current_user_can('edit_topic', $topic_id)) {
         return $topic_id;
     }
     // Get the forum ID
     $forum_id = !empty($_POST['parent_id']) ? (int) $_POST['parent_id'] : 0;
     // Formally update the topic
     bbp_update_topic($topic_id, $forum_id);
     // Stickies
     if (!empty($_POST['bbp_stick_topic']) && in_array($_POST['bbp_stick_topic'], array('stick', 'super', 'unstick'))) {
         // What's the haps?
         switch ($_POST['bbp_stick_topic']) {
             // Sticky in this forum
             case 'stick':
                 bbp_stick_topic($topic_id);
                 break;
                 // Super sticky in all forums
             // Super sticky in all forums
             case 'super':
                 bbp_stick_topic($topic_id, true);
                 break;
                 // Normal
             // Normal
             case 'unstick':
             default:
                 bbp_unstick_topic($topic_id);
                 break;
         }
     }
     // Allow other fun things to happen
     do_action('bbp_topic_attributes_metabox_save', $topic_id, $forum_id);
     return $topic_id;
 }
Пример #7
0
 /**
  * Pass the topic attributes for processing
  *
  * @since 2.0.0 bbPress (r2746)
  *
  * @param int $topic_id Topic id
  * @uses current_user_can() To check if the current user is capable of
  *                           editing the topic
  * @uses do_action() Calls 'bbp_topic_attributes_metabox_save' with the
  *                    topic id and parent id
  * @return int Parent id
  */
 public function save_meta_boxes($topic_id)
 {
     if ($this->bail()) {
         return $topic_id;
     }
     // Bail if doing an autosave
     if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {
         return $topic_id;
     }
     // Bail if not a post request
     if (!bbp_is_post_request()) {
         return $topic_id;
     }
     // Nonce check
     if (empty($_POST['bbp_topic_metabox']) || !wp_verify_nonce($_POST['bbp_topic_metabox'], 'bbp_topic_metabox_save')) {
         return $topic_id;
     }
     // Bail if current user cannot edit this topic
     if (!current_user_can('edit_topic', $topic_id)) {
         return $topic_id;
     }
     // Get the forum ID
     $forum_id = !empty($_POST['parent_id']) ? (int) $_POST['parent_id'] : 0;
     // Get topic author data
     $anonymous_data = bbp_filter_anonymous_post_data();
     $author_id = bbp_get_topic_author_id($topic_id);
     $is_edit = isset($_POST['hidden_post_status']) && $_POST['hidden_post_status'] !== 'draft';
     // Formally update the topic
     bbp_update_topic($topic_id, $forum_id, $anonymous_data, $author_id, $is_edit);
     // Allow other fun things to happen
     do_action('bbp_topic_attributes_metabox_save', $topic_id, $forum_id);
     do_action('bbp_author_metabox_save', $topic_id, $anonymous_data);
     return $topic_id;
 }
Пример #8
0
 public function update_object($topic_id, $fields)
 {
     $fields['topic_id'] = $topic_id;
     return bbp_update_topic($fields);
 }