bbp_admin_repair_forum_meta()
Repair the parent forum meta for each topic and reply
Description Description
Return Return
(array) An array of the status code and the message
Source Source
File: includes/admin/tools/repair.php
function bbp_admin_repair_forum_meta() {
// Define variables
$bbp_db = bbp_db();
$statement = esc_html__( 'Recalculating the forum for each post… %s', 'bbpress' );
$result = esc_html__( 'Failed!', 'bbpress' );
// First, delete everything.
if ( is_wp_error( $bbp_db->query( "DELETE FROM `{$bbp_db->postmeta}` WHERE `meta_key` = '_bbp_forum_id'" ) ) ) {
return array( 1, sprintf( $statement, $result ) );
}
// Post types and status
$tpt = bbp_get_topic_post_type();
$rpt = bbp_get_reply_post_type();
// Next, give all the topics their parent forum id.
if ( is_wp_error( $bbp_db->query( "INSERT INTO `{$bbp_db->postmeta}` (`post_id`, `meta_key`, `meta_value`)
( SELECT `topic`.`ID`, '_bbp_forum_id', `topic`.`post_parent`
FROM `$bbp_db->posts`
AS `topic`
WHERE `topic`.`post_type` = '{$tpt}'
GROUP BY `topic`.`ID` )" ) ) ) {
return array( 2, sprintf( $statement, $result ) );
}
// Next, give all the replies their parent forum id.
if ( is_wp_error( $bbp_db->query( "INSERT INTO `{$bbp_db->postmeta}` (`post_id`, `meta_key`, `meta_value`)
( SELECT `reply`.`ID`, '_bbp_forum_id', `topic`.`post_parent`
FROM `$bbp_db->posts`
AS `reply`
INNER JOIN `$bbp_db->posts`
AS `topic`
ON `reply`.`post_parent` = `topic`.`ID`
WHERE `topic`.`post_type` = '{$tpt}'
AND `reply`.`post_type` = '{$rpt}'
GROUP BY `reply`.`ID` )" ) ) ) {
return array( 3, sprintf( $statement, $result ) );
}
// Complete results
return array( 0, sprintf( $statement, esc_html__( 'Complete!', 'bbpress' ) ) );
}
Changelog Changelog
| Version | Description |
|---|---|
| 2.1.0 | Introduced. |