bbp_admin_repair_reply_menu_order()
Recalculate reply menu order
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_reply_menu_order() {
// Define variables
$bbp_db = bbp_db();
$statement = esc_html__( 'Recalculating reply menu order… %s', 'bbpress' );
$result = esc_html__( 'No reply positions to recalculate.', 'bbpress' );
// Delete cases where `_bbp_reply_to` was accidentally set to itself
if ( is_wp_error( $bbp_db->query( "DELETE FROM `{$bbp_db->postmeta}` WHERE `meta_key` = '_bbp_reply_to' AND `post_id` = `meta_value`" ) ) ) {
return array( 1, sprintf( $statement, $result ) );
}
// Post type
$rpt = bbp_get_reply_post_type();
// Get an array of reply id's to update the menu oder for each reply
$replies = $bbp_db->get_results( "SELECT `a`.`ID` FROM `{$bbp_db->posts}` AS `a`
INNER JOIN (
SELECT `menu_order`, `post_parent`
FROM `{$bbp_db->posts}`
GROUP BY `menu_order`, `post_parent`
HAVING COUNT( * ) >1
)`b`
ON `a`.`menu_order` = `b`.`menu_order`
AND `a`.`post_parent` = `b`.`post_parent`
WHERE `post_type` = '{$rpt}'", OBJECT_K );
// Bail if no replies returned
if ( empty( $replies ) ) {
return array( 1, sprintf( $statement, $result ) );
}
// Recalculate the menu order position for each reply
foreach ( $replies as $reply ) {
bbp_update_reply_position( $reply->ID );
}
// Cleanup
unset( $replies, $reply );
// Complete results
return array( 0, sprintf( $statement, esc_html__( 'Complete!', 'bbpress' ) ) );
}
Changelog Changelog
| Version | Description |
|---|---|
| 2.5.4 | Introduced. |