bbp_admin_repair_topic_hidden_reply_count()
Recount non-public replies per topic (pending/spammed/trashed)
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_topic_hidden_reply_count() {
// Define variables
$bbp_db = bbp_db();
$statement = esc_html__( 'Counting the number of pending, spammed, and trashed replies in each topic… %s', 'bbpress' );
$result = esc_html__( 'Failed!', 'bbpress' );
$sql_delete = "DELETE FROM `{$bbp_db->postmeta}` WHERE `meta_key` = '_bbp_reply_count_hidden'";
if ( is_wp_error( $bbp_db->query( $sql_delete ) ) ) {
return array( 1, sprintf( $statement, $result ) );
}
// Post types and status
$rpt = bbp_get_reply_post_type();
$sta = bbp_get_non_public_topic_statuses();
// SQL
$sql_status = "'" . implode( "','", $sta ) . "'";
$sql = "INSERT INTO `{$bbp_db->postmeta}` (`post_id`, `meta_key`, `meta_value`) (SELECT `post_parent`, '_bbp_reply_count_hidden', COUNT(`post_status`) as `meta_value` FROM `{$bbp_db->posts}` WHERE `post_type` = '{$rpt}' AND `post_status` IN ({$sql_status}) GROUP BY `post_parent`)";
if ( is_wp_error( $bbp_db->query( $sql ) ) ) {
return array( 2, sprintf( $statement, $result ) );
}
return array( 0, sprintf( $statement, esc_html__( 'Complete!', 'bbpress' ) ) );
}
Changelog Changelog
| Version | Description |
|---|---|
| 2.0.0 | Introduced. |