bbp_admin_repair_forum_meta

Recaches the forum for each post.

Description

(array) bbp_admin_repair_forum_meta(); 

Returns (array)

An array of the status code and the message


Usage

  1. if ( !function_exists( 'bbp_admin_repair_forum_meta' ) ) { 
  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_forum_meta(); 
  7.  

Defined (1)

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

/includes/admin/tools.php  
  1. function bbp_admin_repair_forum_meta() { 
  2. global $wpdb; 
  3.  
  4. $statement = __( 'Recalculating the forum for each post … %s', bbpress ); 
  5. $result = __( 'Failed!', bbpress ); 
  6.  
  7. // First, delete everything. 
  8. if ( is_wp_error( $wpdb->query( "DELETE FROM `$wpdb->postmeta` WHERE `meta_key` = '_bbp_forum_id';" ) ) ) 
  9. return array( 1, sprintf( $statement, $result ) ); 
  10.  
  11. // Next, give all the topics with replies the ID their last reply. 
  12. if ( is_wp_error( $wpdb->query( "INSERT INTO `$wpdb->postmeta` (`post_id`, `meta_key`, `meta_value`) 
  13. ( SELECT `forum`.`ID`, '_bbp_forum_id', `forum`.`post_parent` 
  14. FROM `$wpdb->posts` 
  15. AS `forum` 
  16. WHERE `forum`.`post_type` = 'forum' 
  17. GROUP BY `forum`.`ID` );" ) ) ) 
  18. return array( 2, sprintf( $statement, $result ) ); 
  19.  
  20. // Next, give all the topics with replies the ID their last reply. 
  21. if ( is_wp_error( $wpdb->query( "INSERT INTO `$wpdb->postmeta` (`post_id`, `meta_key`, `meta_value`) 
  22. ( SELECT `topic`.`ID`, '_bbp_forum_id', `topic`.`post_parent` 
  23. FROM `$wpdb->posts` 
  24. AS `topic` 
  25. WHERE `topic`.`post_type` = 'topic' 
  26. GROUP BY `topic`.`ID` );" ) ) ) 
  27. return array( 3, sprintf( $statement, $result ) ); 
  28.  
  29. // Next, give all the topics with replies the ID their last reply. 
  30. if ( is_wp_error( $wpdb->query( "INSERT INTO `$wpdb->postmeta` (`post_id`, `meta_key`, `meta_value`) 
  31. ( SELECT `reply`.`ID`, '_bbp_forum_id', `topic`.`post_parent` 
  32. FROM `$wpdb->posts` 
  33. AS `reply` 
  34. INNER JOIN `$wpdb->posts` 
  35. AS `topic` 
  36. ON `reply`.`post_parent` = `topic`.`ID` 
  37. WHERE `topic`.`post_type` = 'topic' 
  38. AND `reply`.`post_type` = 'reply' 
  39. GROUP BY `reply`.`ID` );" ) ) ) 
  40. return array( 4, sprintf( $statement, $result ) ); 
  41.  
  42. // Complete results 
  43. return array( 0, sprintf( $statement, __( 'Complete!', bbpress ) ) );