bbp_admin_repair_reply_menu_order

Recalculate reply menu order.

Description

(array) bbp_admin_repair_reply_menu_order(); 

Returns (array)

An array of the status code and the message


Usage

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

Defined (1)

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

/includes/admin/tools.php  
  1. function bbp_admin_repair_reply_menu_order() { 
  2. global $wpdb; 
  3.  
  4. $statement = __( 'Recalculating reply menu order … %s', bbpress ); 
  5. $result = __( 'No reply positions to recalculate!', bbpress ); 
  6.  
  7. // Delete cases where `_bbp_reply_to` was accidentally set to itself 
  8. if ( is_wp_error( $wpdb->query( "DELETE FROM `{$wpdb->postmeta}` WHERE `meta_key` = '_bbp_reply_to' AND `post_id` = `meta_value`;" ) ) ) { 
  9. return array( 1, sprintf( $statement, $result ) );  
  10.  
  11. // Post type 
  12.  
  13. // Get an array of reply id's to update the menu oder for each reply 
  14. $replies = $wpdb->get_results( "SELECT `a`.`ID` FROM `{$wpdb->posts}` AS `a` 
  15. INNER JOIN ( 
  16. SELECT `menu_order`, `post_parent` 
  17. FROM `{$wpdb->posts}` 
  18. GROUP BY `menu_order`, `post_parent` 
  19. HAVING COUNT( * ) >1 
  20. )`b` 
  21. ON `a`.`menu_order` = `b`.`menu_order` 
  22. AND `a`.`post_parent` = `b`.`post_parent` 
  23. WHERE `post_type` = '{$rpt}';", OBJECT_K ); 
  24.  
  25. // Bail if no replies returned 
  26. if ( empty( $replies ) ) { 
  27. return array( 1, sprintf( $statement, $result ) ); 
  28.  
  29. // Recalculate the menu order position for each reply 
  30. foreach ( $replies as $reply ) { 
  31. bbp_update_reply_position( $reply->ID ); 
  32.  
  33. // Cleanup 
  34. unset( $replies, $reply ); 
  35.  
  36. // Flush the cache; things are about to get ugly. 
  37. wp_cache_flush(); 
  38.  
  39. return array( 0, sprintf( $statement, __( 'Complete!', bbpress ) ) );