uo-groups-user-role
Filters the default user role used by the plugin, allowing customization of initial user permissions.
add_filter( 'uo-groups-user-role', $callback, 10, 1 );
Description
Allows developers to modify the default user role assigned to new users added to groups. This filter applies before the user is created or updated, providing a point to dynamically set roles based on custom logic or context. The default role is retrieved from WordPress's `default_role` option.
Usage
add_filter( 'uo-groups-user-role', 'your_function_name', 10, 1 );
Return Value
The filtered value.
Examples
<?php
/**
* Example of modifying the default user role when adding users to groups.
*
* This function demonstrates how to hook into the 'uo-groups-user-role'
* filter to change the role assigned to newly added users.
*
* @param string $default_role The current default role.
* @return string The modified user role.
*/
add_filter( 'uo-groups-user-role', function( $default_role ) {
// Check if the user making the request has a specific capability,
// for example, to assign an 'editor' role.
if ( current_user_can( 'manage_options' ) ) {
// If the current user can manage options, we might want to assign
// a more privileged role by default for this bulk action.
// Let's say we want to assign 'editor' instead of the site's default.
// You could also conditionally change this based on other factors
// like the specific group being added to, or data submitted in $_POST.
return 'editor';
}
// Otherwise, return the original default role.
return $default_role;
}, 10, 1 ); // Priority 10, accepts 1 argument.
Placement
This code should be placed in the functions.php file of your active theme, a custom plugin, or using a code snippets plugin.
Source Code
src/classes/group-management/management-group-multi-add-users.php:47
src/classes/group-management/class-group-management-helpers.php:191
src/classes/group-management/class-group-management-helpers.php:698
$passwords = $_REQUEST['uo_password'];
$uo_custom_bulk_fields = isset( $_REQUEST['uo_custom_bulk_fields'] ) && is_array( $_REQUEST['uo_custom_bulk_fields'] ) ? $_REQUEST['uo_custom_bulk_fields'] : array();
$error_results = array();
$password_length_warnings = array();
$insert_results = array();
if ( $emails ) {
$role = apply_filters( 'uo-groups-user-role', get_option( 'default_role', 'subscriber' ) );
foreach ( $emails as $k => $email ) {
if ( ! empty( $email ) ) {
$email = stripcslashes( $email );
if ( is_email( $email ) ) {
$first = $first_names[ $k ];
$last = $last_names[ $k ];
$email = sanitize_email( $email );