/** * Recaches the last post in every topic and forum * * @since 2.0.0 bbPress (r3040) * * @uses wpdb::query() To run our recount sql queries * @uses is_wp_error() To check if the executed query returned {@link WP_Error} * @uses bbp_get_forum_post_type() To get the forum post type * @uses bbp_get_topic_post_type() To get the topic post type * @uses bbp_get_reply_post_type() To get the reply post type * @uses bbp_get_public_status_id() To get the public status id * @uses bbp_is_forum_category() To check if the forum is a ategory * @uses bbp_update_forum() To update the forums forum id * @return array An array of the status code and the message */ function bbp_admin_repair_freshness() { // Define variables $bbp_db = bbp_db(); $statement = __('Recomputing latest post in every topic and forum… %s', 'bbpress'); $result = __('Failed!', 'bbpress'); // First, delete everything. if (is_wp_error($bbp_db->query("DELETE FROM `{$bbp_db->postmeta}` WHERE `meta_key` IN ( '_bbp_last_reply_id', '_bbp_last_topic_id', '_bbp_last_active_id', '_bbp_last_active_time' );"))) { return array(1, sprintf($statement, $result)); } // Post types and status $fpt = bbp_get_forum_post_type(); $tpt = bbp_get_topic_post_type(); $rpt = bbp_get_reply_post_type(); $pps = bbp_get_public_status_id(); // Next, give all the topics with replies the ID their last reply. if (is_wp_error($bbp_db->query("INSERT INTO `{$bbp_db->postmeta}` (`post_id`, `meta_key`, `meta_value`)\n\t\t\t( SELECT `topic`.`ID`, '_bbp_last_reply_id', MAX( `reply`.`ID` )\n\t\t\tFROM `{$bbp_db->posts}` AS `topic` INNER JOIN `{$bbp_db->posts}` AS `reply` ON `topic`.`ID` = `reply`.`post_parent`\n\t\t\tWHERE `reply`.`post_status` = '{$pps}' AND `topic`.`post_type` = '{$tpt}' AND `reply`.`post_type` = '{$rpt}'\n\t\t\tGROUP BY `topic`.`ID` );"))) { return array(2, sprintf($statement, $result)); } // For any remaining topics, give a reply ID of 0. if (is_wp_error($bbp_db->query("INSERT INTO `{$bbp_db->postmeta}` (`post_id`, `meta_key`, `meta_value`)\n\t\t\t( SELECT `ID`, '_bbp_last_reply_id', 0\n\t\t\tFROM `{$bbp_db->posts}` AS `topic` LEFT JOIN `{$bbp_db->postmeta}` AS `reply`\n\t\t\tON `topic`.`ID` = `reply`.`post_id` AND `reply`.`meta_key` = '_bbp_last_reply_id'\n\t\t\tWHERE `reply`.`meta_id` IS NULL AND `topic`.`post_type` = '{$tpt}' );"))) { return array(3, sprintf($statement, $result)); } // Now we give all the forums with topics the ID their last topic. if (is_wp_error($bbp_db->query("INSERT INTO `{$bbp_db->postmeta}` (`post_id`, `meta_key`, `meta_value`)\n\t\t\t( SELECT `forum`.`ID`, '_bbp_last_topic_id', `topic`.`ID`\n\t\t\tFROM `{$bbp_db->posts}` AS `forum` INNER JOIN `{$bbp_db->posts}` AS `topic` ON `forum`.`ID` = `topic`.`post_parent`\n\t\t\tWHERE `topic`.`post_status` = '{$pps}' AND `forum`.`post_type` = '{$fpt}' AND `topic`.`post_type` = '{$tpt}'\n\t\t\tGROUP BY `forum`.`ID` );"))) { return array(4, sprintf($statement, $result)); } // For any remaining forums, give a topic ID of 0. if (is_wp_error($bbp_db->query("INSERT INTO `{$bbp_db->postmeta}` (`post_id`, `meta_key`, `meta_value`)\n\t\t\t( SELECT `ID`, '_bbp_last_topic_id', 0\n\t\t\tFROM `{$bbp_db->posts}` AS `forum` LEFT JOIN `{$bbp_db->postmeta}` AS `topic`\n\t\t\tON `forum`.`ID` = `topic`.`post_id` AND `topic`.`meta_key` = '_bbp_last_topic_id'\n\t\t\tWHERE `topic`.`meta_id` IS NULL AND `forum`.`post_type` = '{$fpt}' );"))) { return array(5, sprintf($statement, $result)); } // After that, we give all the topics with replies the ID their last reply (again, this time for a different reason). if (is_wp_error($bbp_db->query("INSERT INTO `{$bbp_db->postmeta}` (`post_id`, `meta_key`, `meta_value`)\n\t\t\t( SELECT `topic`.`ID`, '_bbp_last_active_id', MAX( `reply`.`ID` )\n\t\t\tFROM `{$bbp_db->posts}` AS `topic` INNER JOIN `{$bbp_db->posts}` AS `reply` ON `topic`.`ID` = `reply`.`post_parent`\n\t\t\tWHERE `reply`.`post_status` = '{$pps}' AND `topic`.`post_type` = '{$tpt}' AND `reply`.`post_type` = '{$rpt}'\n\t\t\tGROUP BY `topic`.`ID` );"))) { return array(6, sprintf($statement, $result)); } // For any remaining topics, give a reply ID of themself. if (is_wp_error($bbp_db->query("INSERT INTO `{$bbp_db->postmeta}` (`post_id`, `meta_key`, `meta_value`)\n\t\t\t( SELECT `ID`, '_bbp_last_active_id', `ID`\n\t\t\tFROM `{$bbp_db->posts}` AS `topic` LEFT JOIN `{$bbp_db->postmeta}` AS `reply`\n\t\t\tON `topic`.`ID` = `reply`.`post_id` AND `reply`.`meta_key` = '_bbp_last_active_id'\n\t\t\tWHERE `reply`.`meta_id` IS NULL AND `topic`.`post_type` = '{$tpt}' );"))) { return array(7, sprintf($statement, $result)); } // Give topics with replies their last update time. if (is_wp_error($bbp_db->query("INSERT INTO `{$bbp_db->postmeta}` (`post_id`, `meta_key`, `meta_value`)\n\t\t\t( SELECT `topic`.`ID`, '_bbp_last_active_time', MAX( `reply`.`post_date` )\n\t\t\tFROM `{$bbp_db->posts}` AS `topic` INNER JOIN `{$bbp_db->posts}` AS `reply` ON `topic`.`ID` = `reply`.`post_parent`\n\t\t\tWHERE `reply`.`post_status` = '{$pps}' AND `topic`.`post_type` = '{$tpt}' AND `reply`.`post_type` = '{$rpt}'\n\t\t\tGROUP BY `topic`.`ID` );"))) { return array(8, sprintf($statement, $result)); } // Give topics without replies their last update time. if (is_wp_error($bbp_db->query("INSERT INTO `{$bbp_db->postmeta}` (`post_id`, `meta_key`, `meta_value`)\n\t\t\t( SELECT `ID`, '_bbp_last_active_time', `post_date`\n\t\t\tFROM `{$bbp_db->posts}` AS `topic` LEFT JOIN `{$bbp_db->postmeta}` AS `reply`\n\t\t\tON `topic`.`ID` = `reply`.`post_id` AND `reply`.`meta_key` = '_bbp_last_active_time'\n\t\t\tWHERE `reply`.`meta_id` IS NULL AND `topic`.`post_type` = '{$tpt}' );"))) { return array(9, sprintf($statement, $result)); } // Forums need to know what their last active item is as well. Now it gets a bit more complex to do in the database. $forums = $bbp_db->get_col("SELECT `ID` FROM `{$bbp_db->posts}` WHERE `post_type` = '{$fpt}' and `post_status` != 'auto-draft';"); if (is_wp_error($forums)) { return array(10, sprintf($statement, $result)); } // Loop through forums foreach ($forums as $forum_id) { if (!bbp_is_forum_category($forum_id)) { bbp_update_forum(array('forum_id' => $forum_id)); } } // Loop through categories when forums are done foreach ($forums as $forum_id) { if (bbp_is_forum_category($forum_id)) { bbp_update_forum(array('forum_id' => $forum_id)); } } // Complete results return array(0, sprintf($statement, __('Complete!', 'bbpress'))); }
/** * Updates the counts of a forum. * * This calls a few internal functions that all run manual queries against the * database to get their results. As such, this function can be costly to run * but is necessary to keep everything accurate. * * @since bbPress (r2908) * * @param mixed $args Supports these arguments: * - forum_id: Forum id * - last_topic_id: Last topic id * - last_reply_id: Last reply id * - last_active_id: Last active post id * - last_active_time: last active time * @uses bbp_update_forum_last_topic_id() To update the forum last topic id * @uses bbp_update_forum_last_reply_id() To update the forum last reply id * @uses bbp_update_forum_last_active_id() To update the last active post id * @uses get_post_field() To get the post date of the last active id * @uses bbp_update_forum_last_active_time() To update the last active time * @uses bbp_update_forum_subforum_count() To update the subforum count * @uses bbp_update_forum_topic_count() To update the forum topic count * @uses bbp_update_forum_reply_count() To update the forum reply count * @uses bbp_update_forum_topic_count_hidden() To update the hidden topic count */ function bbp_update_forum($args = '') { // Parse arguments against default values $r = bbp_parse_args($args, array('forum_id' => 0, 'post_parent' => 0, 'last_topic_id' => 0, 'last_reply_id' => 0, 'last_active_id' => 0, 'last_active_time' => 0, 'last_active_status' => bbp_get_public_status_id()), 'update_forum'); // Last topic and reply ID's bbp_update_forum_last_topic_id($r['forum_id'], $r['last_topic_id']); bbp_update_forum_last_reply_id($r['forum_id'], $r['last_reply_id']); // Active dance $r['last_active_id'] = bbp_update_forum_last_active_id($r['forum_id'], $r['last_active_id']); // If no active time was passed, get it from the last_active_id if (empty($r['last_active_time'])) { $r['last_active_time'] = get_post_field('post_date', $r['last_active_id']); } if (bbp_get_public_status_id() === $r['last_active_status']) { bbp_update_forum_last_active_time($r['forum_id'], $r['last_active_time']); } // Counts bbp_update_forum_subforum_count($r['forum_id']); bbp_update_forum_reply_count($r['forum_id']); bbp_update_forum_topic_count($r['forum_id']); bbp_update_forum_topic_count_hidden($r['forum_id']); // Update the parent forum if one was passed if (!empty($r['post_parent']) && is_numeric($r['post_parent'])) { bbp_update_forum(array('forum_id' => $r['post_parent'], 'post_parent' => get_post_field('post_parent', $r['post_parent']))); } }
/** * Handle the moving of a topic from one forum to another. This includes walking * up the old and new branches and updating the counts. * * @param int $topic_id Topic id * @param int $old_forum_id Old forum id * @param int $new_forum_id New forum id * @uses bbp_get_topic_id() To get the topic id * @uses bbp_get_forum_id() To get the forum id * @uses bbp_get_stickies() To get the old forums sticky topics * @uses delete_post_meta() To delete the forum sticky meta * @uses update_post_meta() To update the old forum sticky meta * @uses bbp_stick_topic() To stick the topic in the new forum * @uses bbp_get_reply_post_type() To get the reply post type * @uses bbp_get_all_child_ids() To get the public child ids * @uses bbp_update_reply_forum_id() To update the reply forum id * @uses bbp_update_topic_forum_id() To update the topic forum id * @uses get_post_ancestors() To get the topic's ancestors * @uses bbp_is_forum() To check if the ancestor is a forum * @uses bbp_update_forum() To update the forum */ function bbp_move_topic_handler($topic_id, $old_forum_id, $new_forum_id) { // Validate parameters $topic_id = bbp_get_topic_id($topic_id); $old_forum_id = bbp_get_forum_id($old_forum_id); $new_forum_id = bbp_get_forum_id($new_forum_id); // Update topic forum's ID bbp_update_topic_forum_id($topic_id, $new_forum_id); /** Stickies **************************************************************/ // Get forum stickies $old_stickies = bbp_get_stickies($old_forum_id); // Only proceed if stickies are found if (!empty($old_stickies)) { // Define local variables $updated_stickies = array(); // Loop through stickies of forum and add misses to the updated array foreach ((array) $old_stickies as $sticky_topic_id) { if ($topic_id !== $sticky_topic_id) { $updated_stickies[] = $sticky_topic_id; } } // If stickies are different, update or delete them if ($updated_stickies !== $old_stickies) { // No more stickies so delete the meta if (empty($updated_stickies)) { delete_post_meta($old_forum_id, '_bbp_sticky_topics'); // Still stickies so update the meta } else { update_post_meta($old_forum_id, '_bbp_sticky_topics', $updated_stickies); } // Topic was sticky, so restick in new forum bbp_stick_topic($topic_id); } } /** Topic Replies *********************************************************/ // Get the topics replies $replies = bbp_get_all_child_ids($topic_id, bbp_get_reply_post_type()); // Update the forum_id of all replies in the topic foreach ($replies as $reply_id) { bbp_update_reply_forum_id($reply_id, $new_forum_id); } /** Old forum_id **********************************************************/ // Get topic ancestors $old_forum_ancestors = array_values(array_unique(array_merge(array($old_forum_id), (array) get_post_ancestors($old_forum_id)))); // Loop through ancestors and update them if (!empty($old_forum_ancestors)) { foreach ($old_forum_ancestors as $ancestor) { if (bbp_is_forum($ancestor)) { bbp_update_forum(array('forum_id' => $ancestor)); } } } /** New forum_id **********************************************************/ // Make sure we're not walking twice if (!in_array($new_forum_id, $old_forum_ancestors)) { // Get topic ancestors $new_forum_ancestors = array_values(array_unique(array_merge(array($new_forum_id), (array) get_post_ancestors($new_forum_id)))); // Make sure we're not walking twice $new_forum_ancestors = array_diff($new_forum_ancestors, $old_forum_ancestors); // Loop through ancestors and update them if (!empty($new_forum_ancestors)) { foreach ($new_forum_ancestors as $ancestor) { if (bbp_is_forum($ancestor)) { bbp_update_forum(array('forum_id' => $ancestor)); } } } } }
/** * Pass the forum attributes for processing * * @since bbPress (r2746) * * @param int $forum_id Forum id * @uses current_user_can() To check if the current user is capable of * editing the forum * @uses bbp_get_forum() To get the forum * @uses bbp_is_forum_closed() To check if the forum is closed * @uses bbp_is_forum_category() To check if the forum is a category * @uses bbp_is_forum_private() To check if the forum is private * @uses bbp_close_forum() To close the forum * @uses bbp_open_forum() To open the forum * @uses bbp_categorize_forum() To make the forum a category * @uses bbp_normalize_forum() To make the forum normal (not category) * @uses bbp_privatize_forum() To mark the forum as private * @uses bbp_publicize_forum() To mark the forum as public * @uses do_action() Calls 'bbp_forum_attributes_metabox_save' with the * forum id * @return int Forum id */ public function attributes_metabox_save($forum_id) { if ($this->bail()) { return $forum_id; } // Bail if doing an autosave if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) { return $forum_id; } // Bail if not a post request if ('POST' != strtoupper($_SERVER['REQUEST_METHOD'])) { return $forum_id; } // Nonce check if (empty($_POST['bbp_forum_metabox']) || !wp_verify_nonce($_POST['bbp_forum_metabox'], 'bbp_forum_metabox_save')) { return $forum_id; } // Only save for forum post-types if (!bbp_is_forum($forum_id)) { return $forum_id; } // Bail if current user cannot edit this forum if (!current_user_can('edit_forum', $forum_id)) { return $forum_id; } // Parent ID $parent_id = !empty($_POST['parent_id']) && is_numeric($_POST['parent_id']) ? (int) $_POST['parent_id'] : 0; // Update the forum meta bidness bbp_update_forum(array('forum_id' => $forum_id, 'post_parent' => (int) $parent_id)); do_action('bbp_forum_attributes_metabox_save', $forum_id); return $forum_id; }
function bbps_move_topic() { global $wpdb; $topic_id = $_POST['bbps_topic_id']; $new_forum_id = $_POST['bbp_forum_id']; $old_forum_id = $_POST['bbp_old_forum_id']; //move the topics we will need to run a recount to after this is done if ($topic_id != '' && $new_forum_id != '') { $wpdb->update('wp_posts', array('post_parent' => $new_forum_id), array('ID' => $topic_id)); update_post_meta($topic_id, '_bbp_forum_id', $new_forum_id); // update all the forum meta and counts for the old forum and the new forum bbp_update_forum(array('forum_id' => $new_forum_id)); bbp_update_forum(array('forum_id' => $old_forum_id)); } }
/** * Updates the counts of a forum. * * This calls a few internal functions that all run manual queries against the * database to get their results. As such, this function can be costly to run * but is necessary to keep everything accurate. * * @since bbPress (r2908) * * @param mixed $args Supports these arguments: * - forum_id: Forum id * - last_topic_id: Last topic id * - last_reply_id: Last reply id * - last_active_id: Last active post id * - last_active_time: last active time * @uses bbp_update_forum_last_topic_id() To update the forum last topic id * @uses bbp_update_forum_last_reply_id() To update the forum last reply id * @uses bbp_update_forum_last_active_id() To update the last active post id * @uses get_post_field() To get the post date of the last active id * @uses bbp_update_forum_last_active_time() To update the last active time * @uses bbp_update_forum_subforum_count() To update the subforum count * @uses bbp_update_forum_topic_count() To update the forum topic count * @uses bbp_update_forum_reply_count() To update the forum reply count * @uses bbp_update_forum_topic_count_hidden() To update the hidden topic count */ function bbp_update_forum($args = '') { $defaults = array('forum_id' => 0, 'post_parent' => 0, 'last_topic_id' => 0, 'last_reply_id' => 0, 'last_active_id' => 0, 'last_active_time' => 0, 'last_active_status' => bbp_get_public_status_id()); $r = bbp_parse_args($args, $defaults, 'update_forum'); extract($r); // Last topic and reply ID's bbp_update_forum_last_topic_id($forum_id, $last_topic_id); bbp_update_forum_last_reply_id($forum_id, $last_reply_id); // Active dance $last_active_id = bbp_update_forum_last_active_id($forum_id, $last_active_id); // If no active time was passed, get it from the last_active_id if (empty($last_active_time)) { $last_active_time = get_post_field('post_date', $last_active_id); } if (bbp_get_public_status_id() == $last_active_status) { bbp_update_forum_last_active_time($forum_id, $last_active_time); } // Counts bbp_update_forum_subforum_count($forum_id); bbp_update_forum_reply_count($forum_id); bbp_update_forum_topic_count($forum_id); bbp_update_forum_topic_count_hidden($forum_id); // Update the parent forum if one was passed if (!empty($post_parent) && is_numeric($post_parent)) { bbp_update_forum(array('forum_id' => $post_parent, 'post_parent' => get_post_field('post_parent', $post_parent))); } }
/** * Handle the moving of a topic from one forum to another. This includes walking * up the old and new branches and updating the counts. * * @since 2.0.0 bbPress (r2907) * * @param int $topic_id The topic id. * @param int $old_forum_id Old forum id. * @param int $new_forum_id New forum id. * @uses bbp_get_topic_id() To get the topic id * @uses bbp_get_forum_id() To get the forum id * @uses bbp_clean_post_cache() To clean the old and new forum post caches * @uses bbp_update_topic_forum_id() To update the topic forum id * @uses wp_update_post() To update the topic post parent` * @uses bbp_get_stickies() To get the old forums sticky topics * @uses delete_post_meta() To delete the forum sticky meta * @uses update_post_meta() To update the old forum sticky meta * @uses bbp_stick_topic() To stick the topic in the new forum * @uses bbp_get_reply_post_type() To get the reply post type * @uses bbp_get_all_child_ids() To get all the child ids * @uses bbp_update_reply_forum_id() To update the reply forum id * @uses get_post_ancestors() To get the topic's ancestors * @uses bbp_get_public_child_ids() To get all the public child ids * @uses get_post_field() To get the topic's post status * @uses bbp_get_public_status_id() To get the public status id * @uses bbp_decrease_forum_topic_count() To bump the forum topic count by -1 * @uses bbp_bump_forum_reply_count() To bump the forum reply count * @uses bbp_increase_forum_topic_count() To bump the forum topic count by 1 * @uses bbp_decrease_forum_topic_count_hidden() To bump the forum topic hidden count by -1 * @uses bbp_increase_forum_topic_count_hidden() To bump the forum topic hidden count by 1 * @uses bbp_is_forum() To check if the ancestor is a forum * @uses bbp_update_forum() To update the forum */ function bbp_move_topic_handler($topic_id, $old_forum_id, $new_forum_id) { // Validate parameters $topic_id = bbp_get_topic_id($topic_id); $old_forum_id = bbp_get_forum_id($old_forum_id); $new_forum_id = bbp_get_forum_id($new_forum_id); // Clean old and new forum caches before proceeding, to ensure subsequent // calls to forum objects are using updated data. bbp_clean_post_cache($old_forum_id); bbp_clean_post_cache($new_forum_id); // Update topic forum's ID bbp_update_topic_forum_id($topic_id, $new_forum_id); // Update topic post parent with the new forum ID wp_update_post(array('ID' => $topic_id, 'post_parent' => $new_forum_id)); /** Stickies **************************************************************/ // Get forum stickies $old_stickies = bbp_get_stickies($old_forum_id); // Only proceed if stickies are found if (!empty($old_stickies)) { // Define local variables $updated_stickies = array(); // Loop through stickies of forum and add misses to the updated array foreach ((array) $old_stickies as $sticky_topic_id) { if ($topic_id !== $sticky_topic_id) { $updated_stickies[] = $sticky_topic_id; } } // If stickies are different, update or delete them if ($updated_stickies !== $old_stickies) { // No more stickies so delete the meta if (empty($updated_stickies)) { delete_post_meta($old_forum_id, '_bbp_sticky_topics'); // Still stickies so update the meta } else { update_post_meta($old_forum_id, '_bbp_sticky_topics', $updated_stickies); } // Topic was sticky, so restick in new forum bbp_stick_topic($topic_id); } } /** Topic Replies *********************************************************/ // Get the topics replies $replies = bbp_get_all_child_ids($topic_id, bbp_get_reply_post_type()); // Update the forum_id of all replies in the topic foreach ($replies as $reply_id) { bbp_update_reply_forum_id($reply_id, $new_forum_id); } /** Old forum_id **********************************************************/ // Get topic ancestors $old_forum_ancestors = array_values(array_unique(array_merge(array($old_forum_id), (array) get_post_ancestors($old_forum_id)))); // Get reply count. $public_reply_count = count(bbp_get_public_child_ids($topic_id, bbp_get_reply_post_type())); // Topic status. $topic_status = get_post_field('post_status', $topic_id); // Update old/new forum counts. if ($topic_status === bbp_get_public_status_id()) { // Update old forum counts. bbp_decrease_forum_topic_count($old_forum_id); bbp_bump_forum_reply_count($old_forum_id, -$public_reply_count); // Update new forum counts. bbp_increase_forum_topic_count($new_forum_id); bbp_bump_forum_reply_count($new_forum_id, $public_reply_count); } else { // Update old forum counts. bbp_decrease_forum_topic_count_hidden($old_forum_id); // Update new forum counts. bbp_increase_forum_topic_count_hidden($new_forum_id); } // Loop through ancestors and update them if (!empty($old_forum_ancestors)) { foreach ($old_forum_ancestors as $ancestor) { if (bbp_is_forum($ancestor)) { bbp_update_forum(array('forum_id' => $ancestor)); } } } /** New forum_id **********************************************************/ // Make sure we're not walking twice if (!in_array($new_forum_id, $old_forum_ancestors)) { // Get topic ancestors $new_forum_ancestors = array_values(array_unique(array_merge(array($new_forum_id), (array) get_post_ancestors($new_forum_id)))); // Make sure we're not walking twice $new_forum_ancestors = array_diff($new_forum_ancestors, $old_forum_ancestors); // Loop through ancestors and update them if (!empty($new_forum_ancestors)) { foreach ($new_forum_ancestors as $ancestor) { if (bbp_is_forum($ancestor)) { bbp_update_forum(array('forum_id' => $ancestor)); } } } } }
/** * When inserting a new topic, 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']) { $topic_meta = array('author_ip' => bbp_current_author_ip(), 'forum_id' => $post['post_parent'], 'topic_id' => $post['ID'], 'voice_count' => 1, 'reply_count' => 0, 'reply_count_hidden' => 0, 'last_reply_id' => 0, 'last_active_id' => $post['ID'], 'last_active_time' => get_post_field('post_date', $post['ID'], 'db')); // Insert topic meta foreach ($topic_meta as $meta_key => $meta_value) { update_post_meta($post['ID'], '_bbp_' . $meta_key, $meta_value); } // Update the forum if (!empty($post['post_parent'])) { bbp_update_forum(array('forum_id' => $forum_id)); } } }
/** * Updates the counts of a forum. * * This calls a few internal functions that all run manual queries against the * database to get their results. As such, this function can be costly to run * but is necessary to keep everything accurate. * * @since 2.0.0 bbPress (r2908) * * @param array $args Supports these arguments: * - forum_id: Forum id * - last_topic_id: Last topic id * - last_reply_id: Last reply id * - last_active_id: Last active post id * - last_active_time: last active time * @uses bbp_update_forum_last_topic_id() To update the forum last topic id * @uses bbp_update_forum_last_reply_id() To update the forum last reply id * @uses bbp_update_forum_last_active_id() To update the last active post id * @uses get_post_field() To get the post date of the last active id * @uses bbp_update_forum_last_active_time() To update the last active time * @uses bbp_update_forum_subforum_count() To update the subforum count * @uses bbp_update_forum_topic_count() To update the forum topic count * @uses bbp_update_forum_reply_count() To update the forum reply count * @uses bbp_update_forum_topic_count_hidden() To update the hidden topic count */ function bbp_update_forum($args = array()) { // Parse arguments against default values $r = bbp_parse_args($args, array('forum_id' => 0, 'post_parent' => 0, 'last_topic_id' => 0, 'last_reply_id' => 0, 'last_active_id' => 0, 'last_active_time' => 0, 'last_active_status' => bbp_get_public_status_id()), 'update_forum'); // Last topic and reply ID's bbp_update_forum_last_topic_id($r['forum_id'], $r['last_topic_id']); bbp_update_forum_last_reply_id($r['forum_id'], $r['last_reply_id']); // Active dance $r['last_active_id'] = bbp_update_forum_last_active_id($r['forum_id'], $r['last_active_id']); // If no active time was passed, get it from the last_active_id if (empty($r['last_active_time'])) { $r['last_active_time'] = get_post_field('post_date', $r['last_active_id']); } if (bbp_get_public_status_id() === $r['last_active_status']) { bbp_update_forum_last_active_time($r['forum_id'], $r['last_active_time']); } // Counts bbp_update_forum_subforum_count($r['forum_id']); // Only update topic count if we're deleting a topic, or in the dashboard. if (in_array(current_filter(), array('bbp_deleted_topic', 'save_post'), true)) { bbp_update_forum_reply_count($r['forum_id']); bbp_update_forum_topic_count($r['forum_id']); bbp_update_forum_topic_count_hidden($r['forum_id']); } // Update the parent forum if one was passed if (!empty($r['post_parent']) && is_numeric($r['post_parent'])) { bbp_update_forum(array('forum_id' => $r['post_parent'], 'post_parent' => get_post_field('post_parent', $r['post_parent']))); } }
public function update_object($forum_id, $fields) { $fields['forum_id'] = $forum_id; return bbp_update_forum($fields); }