bbp_admin_repair_topic_hidden_reply_count

Recount topic hidden replies (spammed/trashed).

Description

(array) bbp_admin_repair_topic_hidden_reply_count(); 

Returns (array)

An array of the status code and the message


Usage

  1. if ( !function_exists( 'bbp_admin_repair_topic_hidden_reply_count' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'bbpress/includes/admin/tools.php'; 
  3.  
  4.  
  5. // NOTICE! Understand what this does before running. 
  6. $result = bbp_admin_repair_topic_hidden_reply_count(); 
  7.  

Defined (1)

The function is defined in the following location(s).

/includes/admin/tools.php  
  1. function bbp_admin_repair_topic_hidden_reply_count() { 
  2. global $wpdb; 
  3.  
  4. $statement = __( 'Counting the number of spammed and trashed replies in each topic… %s', bbpress ); 
  5. $result = __( 'Failed!', bbpress ); 
  6.  
  7. $sql_delete = "DELETE FROM `{$wpdb->postmeta}` WHERE `meta_key` = '_bbp_reply_count_hidden';"; 
  8. if ( is_wp_error( $wpdb->query( $sql_delete ) ) ) 
  9. return array( 1, sprintf( $statement, $result ) ); 
  10.  
  11. $sql = "INSERT INTO `{$wpdb->postmeta}` (`post_id`, `meta_key`, `meta_value`) (SELECT `post_parent`, '_bbp_reply_count_hidden', COUNT(`post_status`) as `meta_value` FROM `{$wpdb->posts}` WHERE `post_type` = '" . bbp_get_reply_post_type() . "' AND `post_status` IN ( '" . implode( "', '", array( bbp_get_trash_status_id(), bbp_get_spam_status_id() ) ) . "') GROUP BY `post_parent`);"; 
  12. if ( is_wp_error( $wpdb->query( $sql ) ) ) 
  13. return array( 2, sprintf( $statement, $result ) ); 
  14.  
  15. return array( 0, sprintf( $statement, __( 'Complete!', bbpress ) ) );