bbp_admin_repair_closed_topics()
Repair closed topics
Description Description
Closed topics that are missing the post-meta "_bbp_status" key value "publish" result in unexpected behavior, primarily this would have only occurred if you had imported forums from another forum package previous to bbPress v2.6, https://bbpress.trac.wordpress.org/ticket/2577
Return Return
(array) An array of the status code and the message
Source Source
File: includes/admin/tools/repair.php
function bbp_admin_repair_closed_topics() { // Define variables $bbp_db = bbp_db(); $statement = esc_html__( 'Repairing closed topics… %s', 'bbpress' ); $result = esc_html__( 'No closed topics to repair.', 'bbpress' ); $changed = 0; // Results $query = "SELECT ID FROM `{$bbp_db->posts}` WHERE `post_type` = %s AND `post_status` = %s"; $prepare = $bbp_db->prepare( $query, bbp_get_topic_post_type(), bbp_get_closed_status_id() ); $closed_topics = $bbp_db->get_col( $prepare ); // Bail if no closed topics found if ( empty( $closed_topics ) || is_wp_error( $closed_topics ) ) { return array( 1, sprintf( $statement, $result ) ); } // Loop through each closed topic foreach ( $closed_topics as $closed_topic ) { // Check if the closed topic already has a postmeta _bbp_status value $topic_status = get_post_meta( $closed_topic, '_bbp_status', true ); // If we don't have a postmeta _bbp_status value if( empty( $topic_status ) ) { update_post_meta( $closed_topic, '_bbp_status', 'publish' ); ++$changed; // Keep a count to display at the end } } // Cleanup unset( $closed_topics, $closed_topic, $topic_status ); // Complete results $result = sprintf( _n( 'Complete! %d closed topic repaired.', 'Complete! %d closed topics repaired.', $changed, 'bbpress' ), $changed ); return array( 0, sprintf( $statement, $result ) ); }
Changelog Changelog
Version | Description |
---|---|
2.6.0 | Introduced. |