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
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.