Changeset 4341
- Timestamp:
- 11/05/2012 06:01:44 AM (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/includes/admin/tools.php
r4279 r4341 161 161 5 => array( 'bbp-sync-forum-meta', __( 'Recalculate the parent forum for each post', 'bbpress' ), 'bbp_admin_repair_forum_meta' ), 162 162 10 => array( 'bbp-sync-forum-visibility', __( 'Recalculate private and hidden forums', 'bbpress' ), 'bbp_admin_repair_forum_visibility' ), 163 15 => array( 'bbp-forum-topics', __( 'Count topics in each forum', 'bbpress' ), 'bbp_admin_repair_forum_topic_count' ), 164 20 => array( 'bbp-forum-replies', __( 'Count replies in each forum', 'bbpress' ), 'bbp_admin_repair_forum_reply_count' ), 165 25 => array( 'bbp-topic-replies', __( 'Count replies in each topic', 'bbpress' ), 'bbp_admin_repair_topic_reply_count' ), 166 30 => array( 'bbp-topic-voices', __( 'Count voices in each topic', 'bbpress' ), 'bbp_admin_repair_topic_voice_count' ), 167 35 => array( 'bbp-topic-hidden-replies', __( 'Count spammed & trashed replies in each topic', 'bbpress' ), 'bbp_admin_repair_topic_hidden_reply_count' ), 168 40 => array( 'bbp-user-replies', __( 'Count topics for each user', 'bbpress' ), 'bbp_admin_repair_user_topic_count' ), 169 45 => array( 'bbp-user-topics', __( 'Count replies for each user', 'bbpress' ), 'bbp_admin_repair_user_reply_count' ), 170 50 => array( 'bbp-user-favorites', __( 'Remove trashed topics from user favorites', 'bbpress' ), 'bbp_admin_repair_user_favorites' ), 171 55 => array( 'bbp-user-subscriptions', __( 'Remove trashed topics from user subscriptions', 'bbpress' ), 'bbp_admin_repair_user_subscriptions' ), 172 60 => array( 'bbp-sync-all-topics-forums', __( 'Recalculate last activity in each topic and forum', 'bbpress' ), 'bbp_admin_repair_freshness' ) 163 15 => array( 'bbp-sync-all-topics-forums', __( 'Recalculate last activity in each topic and forum', 'bbpress' ), 'bbp_admin_repair_freshness' ), 164 20 => array( 'bbp-forum-topics', __( 'Count topics in each forum', 'bbpress' ), 'bbp_admin_repair_forum_topic_count' ), 165 25 => array( 'bbp-forum-replies', __( 'Count replies in each forum', 'bbpress' ), 'bbp_admin_repair_forum_reply_count' ), 166 30 => array( 'bbp-topic-replies', __( 'Count replies in each topic', 'bbpress' ), 'bbp_admin_repair_topic_reply_count' ), 167 35 => array( 'bbp-topic-voices', __( 'Count voices in each topic', 'bbpress' ), 'bbp_admin_repair_topic_voice_count' ), 168 40 => array( 'bbp-topic-hidden-replies', __( 'Count spammed & trashed replies in each topic', 'bbpress' ), 'bbp_admin_repair_topic_hidden_reply_count' ), 169 45 => array( 'bbp-user-replies', __( 'Count topics for each user', 'bbpress' ), 'bbp_admin_repair_user_topic_count' ), 170 50 => array( 'bbp-user-topics', __( 'Count replies for each user', 'bbpress' ), 'bbp_admin_repair_user_reply_count' ), 171 55 => array( 'bbp-user-favorites', __( 'Remove trashed topics from user favorites', 'bbpress' ), 'bbp_admin_repair_user_favorites' ), 172 60 => array( 'bbp-user-subscriptions', __( 'Remove trashed topics from user subscriptions', 'bbpress' ), 'bbp_admin_repair_user_subscriptions' ), 173 65 => array( 'bbp-user-role-map', __( 'Remap existing users to default forum roles', 'bbpress' ), 'bbp_admin_repair_user_roles' ) 173 174 ); 174 175 ksort( $repair_list ); 175 176 // DO NOT USE: Legacy filter177 $repair_list = apply_filters( 'bbp_recount_list', $repair_list );178 176 179 177 return (array) apply_filters( 'bbp_repair_list', $repair_list ); … … 575 573 576 574 $result = __( 'Complete!', 'bbpress' ); 575 return array( 0, sprintf( $statement, $result ) ); 576 } 577 578 /** 579 * This repair tool will map each user of the current site to their respective 580 * forums role. By default, Admins will be Key Masters, and every other role 581 * will be the default role defined in Settings > Forums (Participant). 582 * 583 * @since bbPress (r4340) 584 * 585 * @uses bbp_get_user_role_map() To get the map of user roles 586 * @uses get_editable_roles() To get the current WordPress roles 587 * @uses get_users() To get the users of each role (limited to ID field) 588 * @uses bbp_set_user_role() To set each user's forums role 589 */ 590 function bbp_admin_repair_user_roles() { 591 592 $statement = __( 'Remapping forum role for each user on this site… %s', 'bbpress' ); 593 $result = __( 'Failed!', 'bbpress' ); 594 $changed = 0; 595 $role_map = bbp_get_user_role_map(); 596 597 // Bail if no role map exists 598 if ( empty( $role_map ) ) 599 return array( 1, sprintf( $statement, $result ) ); 600 601 // Iterate through each role... 602 foreach ( array_keys( get_editable_roles() ) as $role ) { 603 604 // Get users of 605 $users = get_users( array( 'role' => $role, 'fields' => 'ID' ) ); 606 607 // Keep iterating if no users exist for this role 608 if ( empty( $users ) ) 609 continue; 610 611 // Iterate through each user of $role and try to set it 612 foreach ( $users as $user_id ) { 613 if ( bbp_set_user_role( $user_id, $role_map[$role] ) ) { 614 ++$changed; // Keep a count to display at the end 615 } 616 } 617 } 618 619 $result = sprintf( __( 'Complete! %s users updated.', 'bbpress' ), bbp_number_format( $changed ) ); 577 620 return array( 0, sprintf( $statement, $result ) ); 578 621 }
Note: See TracChangeset
for help on using the changeset viewer.