| 166 | | 25 => array( 'bbp-group-forums', __( 'Repair BuddyPress Group Forum relationships', 'bbpress' ), 'bbp_admin_repair_group_forum_relationship' ), |
| 167 | | 30 => array( 'bbp-forum-topics', __( 'Count topics in each forum', 'bbpress' ), 'bbp_admin_repair_forum_topic_count' ), |
| 168 | | 35 => array( 'bbp-forum-replies', __( 'Count replies in each forum', 'bbpress' ), 'bbp_admin_repair_forum_reply_count' ), |
| 169 | | 40 => array( 'bbp-topic-replies', __( 'Count replies in each topic', 'bbpress' ), 'bbp_admin_repair_topic_reply_count' ), |
| 170 | | 45 => array( 'bbp-topic-voices', __( 'Count voices in each topic', 'bbpress' ), 'bbp_admin_repair_topic_voice_count' ), |
| 171 | | 50 => array( 'bbp-topic-hidden-replies', __( 'Count spammed & trashed replies in each topic', 'bbpress' ), 'bbp_admin_repair_topic_hidden_reply_count' ), |
| 172 | | 55 => array( 'bbp-user-topics', __( 'Count topics for each user', 'bbpress' ), 'bbp_admin_repair_user_topic_count' ), |
| 173 | | 60 => array( 'bbp-user-replies', __( 'Count replies for each user', 'bbpress' ), 'bbp_admin_repair_user_reply_count' ), |
| 174 | | 65 => array( 'bbp-user-favorites', __( 'Remove trashed topics from user favorites', 'bbpress' ), 'bbp_admin_repair_user_favorites' ), |
| 175 | | 70 => array( 'bbp-user-topic-subscriptions', __( 'Remove trashed topics from user subscriptions', 'bbpress' ), 'bbp_admin_repair_user_topic_subscriptions' ), |
| 176 | | 75 => array( 'bbp-user-forum-subscriptions', __( 'Remove trashed forums from user subscriptions', 'bbpress' ), 'bbp_admin_repair_user_forum_subscriptions' ), |
| 177 | | 80 => array( 'bbp-user-role-map', __( 'Remap existing users to default forum roles', 'bbpress' ), 'bbp_admin_repair_user_roles' ) |
| | 166 | 25 => array( 'bbp-sync-all-reply-positions', __( 'Recalculate the reply position hierarchy', 'bbpress' ), 'bbp_admin_repair_reply_menu_order' ), |
| | 167 | 30 => array( 'bbp-group-forums', __( 'Repair BuddyPress Group Forum relationships', 'bbpress' ), 'bbp_admin_repair_group_forum_relationship' ), |
| | 168 | 35 => array( 'bbp-forum-topics', __( 'Count topics in each forum', 'bbpress' ), 'bbp_admin_repair_forum_topic_count' ), |
| | 169 | 40 => array( 'bbp-forum-replies', __( 'Count replies in each forum', 'bbpress' ), 'bbp_admin_repair_forum_reply_count' ), |
| | 170 | 45 => array( 'bbp-topic-replies', __( 'Count replies in each topic', 'bbpress' ), 'bbp_admin_repair_topic_reply_count' ), |
| | 171 | 50 => array( 'bbp-topic-voices', __( 'Count voices in each topic', 'bbpress' ), 'bbp_admin_repair_topic_voice_count' ), |
| | 172 | 55 => array( 'bbp-topic-hidden-replies', __( 'Count spammed & trashed replies in each topic', 'bbpress' ), 'bbp_admin_repair_topic_hidden_reply_count' ), |
| | 173 | 60 => array( 'bbp-user-topics', __( 'Count topics for each user', 'bbpress' ), 'bbp_admin_repair_user_topic_count' ), |
| | 174 | 65 => array( 'bbp-user-replies', __( 'Count replies for each user', 'bbpress' ), 'bbp_admin_repair_user_reply_count' ), |
| | 175 | 70 => array( 'bbp-user-favorites', __( 'Remove trashed topics from user favorites', 'bbpress' ), 'bbp_admin_repair_user_favorites' ), |
| | 176 | 75 => array( 'bbp-user-topic-subscriptions', __( 'Remove trashed topics from user subscriptions', 'bbpress' ), 'bbp_admin_repair_user_topic_subscriptions' ), |
| | 177 | 80 => array( 'bbp-user-forum-subscriptions', __( 'Remove trashed forums from user subscriptions', 'bbpress' ), 'bbp_admin_repair_user_forum_subscriptions' ), |
| | 178 | 85 => array( 'bbp-user-role-map', __( 'Remap existing users to default forum roles', 'bbpress' ), 'bbp_admin_repair_user_roles' ) |
| | 1133 | /** |
| | 1134 | * Recalculate reply menu order |
| | 1135 | * |
| | 1136 | * @since bbPress (r5367) |
| | 1137 | * |
| | 1138 | * @uses wpdb::query() To run our recount sql queries |
| | 1139 | * @uses is_wp_error() To check if the executed query returned {@link WP_Error} |
| | 1140 | * @uses bbp_get_reply_post_type() To get the reply post type |
| | 1141 | * @uses bbp_update_reply_position() To update the reply position |
| | 1142 | * @return array An array of the status code and the message |
| | 1143 | */ |
| | 1144 | function bbp_admin_repair_reply_menu_order() { |
| | 1145 | global $wpdb; |
| | 1146 | |
| | 1147 | $statement = __( 'Recalculating reply menu order … %s', 'bbpress' ); |
| | 1148 | $result = __( 'No reply hierachy to recalculate!', 'bbpress' ); |
| | 1149 | |
| | 1150 | // Post type |
| | 1151 | $rpt = bbp_get_reply_post_type(); |
| | 1152 | |
| | 1153 | // Get an array of reply id's to update the menu oder for each reply |
| | 1154 | $replies = $wpdb->get_results( "SELECT `a`.`ID` FROM `{$wpdb->posts}` AS `a` |
| | 1155 | INNER JOIN ( |
| | 1156 | SELECT `menu_order`, `post_parent` |
| | 1157 | FROM `{$wpdb->posts}` |
| | 1158 | GROUP BY `menu_order`, `post_parent` |
| | 1159 | HAVING COUNT( * ) >1 |
| | 1160 | )`b` |
| | 1161 | ON `a`.`menu_order` = `b`.`menu_order` |
| | 1162 | AND `a`.`post_parent` = `b`.`post_parent` |
| | 1163 | WHERE `post_type` = '{$rpt}';", OBJECT_K ); |
| | 1164 | |
| | 1165 | // Bail if no replies returned |
| | 1166 | if ( empty( $replies ) ) { |
| | 1167 | return array( 1, sprintf( $statement, $result ) ); |
| | 1168 | } |
| | 1169 | |
| | 1170 | // Recalculate the menu order position for each reply |
| | 1171 | foreach ( $replies as $reply ) { |
| | 1172 | bbp_update_reply_position( $reply->ID ); |
| | 1173 | } |
| | 1174 | |
| | 1175 | // Cleanup |
| | 1176 | unset( $replies, $reply ); |
| | 1177 | |
| | 1178 | // Flush the cache; things are about to get ugly. |
| | 1179 | wp_cache_flush(); |
| | 1180 | |
| | 1181 | return array( 0, sprintf( $statement, __( 'Complete!', 'bbpress' ) ) ); |
| | 1182 | } |
| | 1183 | |