uo_tincanny_reporting_validate_wp_user
Filters user email validation for Tincanny reporting, allowing customization of the process before WordPress user data is used.
add_filter( 'uo_tincanny_reporting_validate_wp_user', $callback, 10, 2 );
Description
Filters the WordPress user object found by email before it's used for Tin Can reporting. Developers can modify the found user object or return a different user based on the provided email address. This hook fires after an email address is cleaned of 'mailto:' prefixes but before the user object is validated for use.
Usage
add_filter( 'uo_tincanny_reporting_validate_wp_user', 'your_function_name', 10, 2 );
Parameters
-
$userEmail(mixed) - This parameter is the WordPress user object, retrieved using the user's email address.
-
$userEmail(mixed) - This parameter contains the WordPress user object found by their email address, or null if no user is found.
Return Value
The filtered value.
Examples
add_filter( 'uo_tincanny_reporting_validate_wp_user', 'my_custom_tincanny_user_validation', 10, 2 );
/**
* Custom validation for Tincanny WordPress user lookup.
*
* This function intercepts the WordPress user object returned by get_user_by('email')
* and can be used to perform additional checks or modifications before it's finalized.
* For example, you might want to ensure the user has a specific role or is active.
*
* @param WP_User|null $wpUser The WordPress user object found by email, or null if not found.
* @param string $userEmail The email address being used to find the WordPress user.
*
* @return WP_User|null The validated (or modified) WordPress user object, or null if validation fails.
*/
function my_custom_tincanny_user_validation( $wpUser, $userEmail ) {
// If no user was found by email, we can't do much.
if ( ! $wpUser instanceof WP_User ) {
// Log an error or warning if you suspect this is an issue.
// error_log( "Tincanny user validation failed: No WP_User found for email: " . $userEmail );
return null;
}
// Example: Check if the user has a specific role (e.g., 'subscriber').
// You could adapt this to check for any role or a combination of roles.
if ( ! in_array( 'subscriber', (array) $wpUser->roles ) ) {
// If the user doesn't have the required role, prevent further processing.
// error_log( "Tincanny user validation failed: User " . $wpUser->user_login . " does not have the required role for email: " . $userEmail );
return null;
}
// Example: Check if the user account is active.
if ( $wpUser->user_status != 0 ) {
// User account might be inactive or suspended.
// error_log( "Tincanny user validation failed: User account " . $wpUser->user_login . " is not active for email: " . $userEmail );
return null;
}
// If all checks pass, return the WP_User object.
return $wpUser;
}
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/uncanny-tincan/classes/TinCanRequest.php:165
}
if ( ! $userEmail ) {
return;
}
$userEmail = str_replace( 'mailto:', '', $userEmail );
$wpUser = apply_filters( 'uo_tincanny_reporting_validate_wp_user' , get_user_by( 'email', $userEmail ), $userEmail);
if ( ! is_object($wpUser) || ! $wpUser->ID || ! ($wpUser instanceof WP_User) ) {
return;
}
$user_id = $wpUser->ID;
$this->user_id = $user_id;