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
1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 | 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.