Filter uncanny-learndash-groups

ulgm_allow_email_field_update_edit_user

Filters whether the email field can be updated when editing a user.

add_filter( 'ulgm_allow_email_field_update_edit_user', $callback, 10, 2 );

Description

Filters whether the email field is editable on the user edit screen for group members. Developers can return `false` to prevent group leaders from changing a user's email address, even if the general option is enabled. This hook fires after checking the core option to allow email updates.


Usage

add_filter( 'ulgm_allow_email_field_update_edit_user', 'your_function_name', 10, 2 );

Parameters

$email_field_allowed (mixed)
This parameter is a boolean indicating whether the email field is allowed to be updated for the user being edited.
$ulgm_current_managed_group_id (mixed)
This parameter determines whether the email field is allowed to be updated for a user being edited within a group management context.

Return Value

The filtered value.


Examples

<?php
/**
 * Filters whether the email field is allowed to be updated when editing a user.
 *
 * This example allows email field updates only if the current user is an administrator
 * and the 'allow_group_leader_change_email' option is set to 'yes'.
 *
 * @param bool $email_field_allowed The current status of whether the email field is allowed to be updated.
 * @param int  $ulgm_current_managed_group_id The ID of the currently managed group.
 * @return bool True if the email field update should be allowed, false otherwise.
 */
add_filter( 'ulgm_allow_email_field_update_edit_user', function( $email_field_allowed, $ulgm_current_managed_group_id ) {

	// Check if the current user has the 'manage_options' capability (typically administrators).
	if ( current_user_can( 'manage_options' ) ) {
		// Also check if the global option to allow group leaders to change emails is enabled.
		if ( 'yes' === get_option( 'allow_group_leader_change_email', 'no' ) ) {
			return true; // Allow email field update.
		}
	}

	// By default, if the above conditions are not met, disallow the email field update.
	return false;

}, 10, 2 ); // Priority 10, accepts 2 arguments.

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/templates/frontend-uo_groups/users-table-actions.php:574

<?php
										$email_field_allowed = false;
										if ( 'yes' === get_option( 'allow_group_leader_change_email', 'no' ) ) {
											$email_field_allowed = true;
										}

										$email_field_editing_allowed = apply_filters( 'ulgm_allow_email_field_update_edit_user', $email_field_allowed, GroupManagementInterface::$ulgm_current_managed_group_id );
										?>

										<div class="uo-row <?php echo ! $email_field_editing_allowed ? ' uo-row-disabled' : ''; ?>">
											<label for="edit-email">
												<div class="uo-row__title">
													<?php _e( 'Email*', 'uncanny-learndash-groups' ); ?>
												</div>

Scroll to Top