| 291 | | 25 => array( 'bbp-group-forums', __( 'Repair BuddyPress Group Forum relationships', 'bbpress' ), 'bbp_admin_repair_group_forum_relationship' ), |
| 292 | | 30 => array( 'bbp-forum-topics', __( 'Count topics in each forum', 'bbpress' ), 'bbp_admin_repair_forum_topic_count' ), |
| 293 | | 35 => array( 'bbp-forum-replies', __( 'Count replies in each forum', 'bbpress' ), 'bbp_admin_repair_forum_reply_count' ), |
| 294 | | 40 => array( 'bbp-topic-replies', __( 'Count replies in each topic', 'bbpress' ), 'bbp_admin_repair_topic_reply_count' ), |
| 295 | | 45 => array( 'bbp-topic-voices', __( 'Count voices in each topic', 'bbpress' ), 'bbp_admin_repair_topic_voice_count' ), |
| 296 | | 50 => array( 'bbp-topic-hidden-replies', __( 'Count spammed & trashed replies in each topic', 'bbpress' ), 'bbp_admin_repair_topic_hidden_reply_count' ), |
| 297 | | 55 => array( 'bbp-user-topics', __( 'Count topics for each user', 'bbpress' ), 'bbp_admin_repair_user_topic_count' ), |
| 298 | | 60 => array( 'bbp-user-replies', __( 'Count replies for each user', 'bbpress' ), 'bbp_admin_repair_user_reply_count' ), |
| 299 | | 65 => array( 'bbp-user-favorites', __( 'Remove trashed topics from user favorites', 'bbpress' ), 'bbp_admin_repair_user_favorites' ), |
| 300 | | 70 => array( 'bbp-user-topic-subscriptions', __( 'Remove trashed topics from user subscriptions', 'bbpress' ), 'bbp_admin_repair_user_topic_subscriptions' ), |
| 301 | | 75 => array( 'bbp-user-forum-subscriptions', __( 'Remove trashed forums from user subscriptions', 'bbpress' ), 'bbp_admin_repair_user_forum_subscriptions' ), |
| 302 | | 80 => array( 'bbp-user-role-map', __( 'Remap existing users to default forum roles', 'bbpress' ), 'bbp_admin_repair_user_roles' ) |
| | 291 | 25 => array( 'bbp-sync-all-reply-positions', __( 'Recalculate the reply position of replies', 'bbpress' ), 'bbp_admin_repair_reply_menu_order' ), |
| | 292 | 30 => array( 'bbp-group-forums', __( 'Repair BuddyPress Group Forum relationships', 'bbpress' ), 'bbp_admin_repair_group_forum_relationship' ), |
| | 293 | 35 => array( 'bbp-forum-topics', __( 'Count topics in each forum', 'bbpress' ), 'bbp_admin_repair_forum_topic_count' ), |
| | 294 | 40 => array( 'bbp-forum-replies', __( 'Count replies in each forum', 'bbpress' ), 'bbp_admin_repair_forum_reply_count' ), |
| | 295 | 45 => array( 'bbp-topic-replies', __( 'Count replies in each topic', 'bbpress' ), 'bbp_admin_repair_topic_reply_count' ), |
| | 296 | 50 => array( 'bbp-topic-voices', __( 'Count voices in each topic', 'bbpress' ), 'bbp_admin_repair_topic_voice_count' ), |
| | 297 | 55 => array( 'bbp-topic-hidden-replies', __( 'Count spammed & trashed replies in each topic', 'bbpress' ), 'bbp_admin_repair_topic_hidden_reply_count' ), |
| | 298 | 60 => array( 'bbp-user-topics', __( 'Count topics for each user', 'bbpress' ), 'bbp_admin_repair_user_topic_count' ), |
| | 299 | 65 => array( 'bbp-user-replies', __( 'Count replies for each user', 'bbpress' ), 'bbp_admin_repair_user_reply_count' ), |
| | 300 | 70 => array( 'bbp-user-favorites', __( 'Remove trashed topics from user favorites', 'bbpress' ), 'bbp_admin_repair_user_favorites' ), |
| | 301 | 75 => array( 'bbp-user-topic-subscriptions', __( 'Remove trashed topics from user subscriptions', 'bbpress' ), 'bbp_admin_repair_user_topic_subscriptions' ), |
| | 302 | 80 => array( 'bbp-user-forum-subscriptions', __( 'Remove trashed forums from user subscriptions', 'bbpress' ), 'bbp_admin_repair_user_forum_subscriptions' ), |
| | 303 | 85 => array( 'bbp-user-role-map', __( 'Remap existing users to default forum roles', 'bbpress' ), 'bbp_admin_repair_user_roles' ) |
| | 1174 | * Recalculate reply menu order |
| | 1175 | * |
| | 1176 | * @since bbPress (rXXXX) |
| | 1177 | * |
| | 1178 | * @uses wpdb::query() To run our recount sql queries |
| | 1179 | * @uses is_wp_error() To check if the executed query returned {@link WP_Error} |
| | 1180 | * @uses bbp_get_reply_post_type() To get the reply post type |
| | 1181 | * @uses bbp_update_reply_position() To update the reply position |
| | 1182 | * @return array An array of the status code and the message |
| | 1183 | */ |
| | 1184 | function bbp_admin_repair_reply_menu_order() { |
| | 1185 | global $wpdb; |
| | 1186 | |
| | 1187 | $statement = __( 'Recalculating reply menu order … %s', 'bbpress' ); |
| | 1188 | $result = __( 'Failed!', 'bbpress' ); |
| | 1189 | |
| | 1190 | // Post types and status |
| | 1191 | $fpt = bbp_get_forum_post_type(); |
| | 1192 | $tpt = bbp_get_topic_post_type(); |
| | 1193 | $rpt = bbp_get_reply_post_type(); |
| | 1194 | |
| | 1195 | // Get an array of reply id's to update the menu oder for each reply |
| | 1196 | $replies = $wpdb->get_results( "SELECT `a`.`ID` FROM `{$wpdb->posts}` AS `a` |
| | 1197 | INNER JOIN ( |
| | 1198 | SELECT `menu_order`, `post_parent` |
| | 1199 | FROM `{$wpdb->posts}` |
| | 1200 | GROUP BY `menu_order`, `post_parent` |
| | 1201 | HAVING COUNT( * ) >1 |
| | 1202 | )`b` |
| | 1203 | ON `a`.`menu_order` = `b`.`menu_order` |
| | 1204 | AND `a`.`post_parent` = `b`.`post_parent` |
| | 1205 | WHERE `post_type` = '{$rpt}';", OBJECT_K ); |
| | 1206 | |
| | 1207 | // Recalculate the menu order position for each reply |
| | 1208 | if ( ! empty( $replies ) ) { |
| | 1209 | foreach ( $replies as $reply ) { |
| | 1210 | bbp_update_reply_position( $reply->ID ); |
| | 1211 | } |
| | 1212 | } else { |
| | 1213 | return array( 1, sprintf( $statement, $result ) ); |
| | 1214 | } |
| | 1215 | |
| | 1216 | // Cleanup |
| | 1217 | unset( $replies, $reply ); |
| | 1218 | |
| | 1219 | // Flush the cache; things are about to get ugly. |
| | 1220 | wp_cache_flush(); |
| | 1221 | |
| | 1222 | return array( 0, sprintf( $statement, __( 'Complete!', 'bbpress' ) ) ); |
| | 1223 | } |
| | 1224 | |
| | 1225 | /** |