bbp_admin_repair_user_roles()
This repair tool will map each user of the current site to their respective forums role. By default, Admins will be Key Masters, and every other role will be the default role defined in Settings > Forums (Participant).
Description
Source
File: bp-forums/admin/tools.php
1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 | function bbp_admin_repair_user_roles() { $statement = __( 'Remapping forum role for each user on this site… %s' , 'buddyboss' ); $changed = 0; $role_map = bbp_get_user_role_map(); $default_role = bbp_get_default_role(); // Bail if no role map exists if ( empty ( $role_map ) ) return array ( 1, sprintf( $statement , __( 'Failed!' , 'buddyboss' ) ) ); // Iterate through each role... foreach ( array_keys ( bbp_get_blog_roles() ) as $role ) { // Reset the offset $offset = 0; // If no role map exists, give the default forum role (bbp-participant) $new_role = isset( $role_map [ $role ] ) ? $role_map [ $role ] : $default_role ; // Get users of this site, limited to 1000 while ( $users = get_users( array ( 'role' => $role , 'fields' => 'ID' , 'number' => 1000, 'offset' => $offset ) ) ) { // Iterate through each user of $role and try to set it foreach ( ( array ) $users as $user_id ) { if ( bbp_set_user_role( $user_id , $new_role ) ) { ++ $changed ; // Keep a count to display at the end } } // Bump the offset for the next query iteration $offset = $offset + 1000; } } $result = sprintf( __( 'Complete! %s users updated.' , 'buddyboss' ), bbp_number_format( $changed ) ); return array ( 0, sprintf( $statement , $result ) ); } |
Changelog
Version | Description |
---|---|
bbPress (r4340) | 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.