bbp_admin_repair_reply_menu_order()
Recalculate reply menu order
Description
Return
(array) An array of the status code and the message
Source
File: bp-forums/admin/tools.php
function bbp_admin_repair_reply_menu_order() { global $wpdb; $statement = __( 'Recalculating reply menu order … %s', 'buddyboss' ); $result = __( 'No reply positions to recalculate!', 'buddyboss' ); // Delete cases where `_bbp_reply_to` was accidentally set to itself if ( is_wp_error( $wpdb->query( "DELETE FROM `{$wpdb->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 = $wpdb->get_results( "SELECT `a`.`ID` FROM `{$wpdb->posts}` AS `a` INNER JOIN ( SELECT `menu_order`, `post_parent` FROM `{$wpdb->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 ); // Flush the cache; things are about to get ugly. wp_cache_flush(); return array( 0, sprintf( $statement, __( 'Complete!', 'buddyboss' ) ) ); }
Changelog
Version | Description |
---|---|
bbPress (r5367) | Introduced. |
Questions?
We're always happy to help with code or other questions you might have! Search our developer docs, contact support, or connect with our sales team.