ulgm_group_management_email_users_from_name
Filters the 'from' name used when emailing users from a group, allowing customization of the sender's name.
add_filter( 'ulgm_group_management_email_users_from_name', $callback, 10, 1 );
Description
Filters the "From" name used in emails sent by the group management feature. Developers can use this hook to customize the sender name beyond the default blog name or group leader's name. This hook fires after a potential default name is determined but before it's finalized for the email.
Usage
add_filter( 'ulgm_group_management_email_users_from_name', 'your_function_name', 10, 1 );
Return Value
The filtered value.
Examples
/**
* Example of how to filter the 'ulgm_group_management_email_users_from_name' hook.
* This example demonstrates how to prepend a prefix to the sender's name
* when an email is being sent from a group leader.
*/
add_filter( 'ulgm_group_management_email_users_from_name', function( $from_name, $group_id ) {
// Check if the current user is a group leader (though the original function already handles this,
// this is an example of how you might add further conditional logic based on the group_id).
// For a more robust check, you'd typically ensure a user is logged in or passed through.
// In a real-world scenario, you might fetch the group leader's ID associated with the $group_id.
// For this example, let's assume we have a function `get_group_leader_for_group($group_id)`
// that returns the user ID of the group leader.
$current_user_id = get_current_user_id(); // Get the currently logged-in user's ID.
// We'll assume the original function already determined if the sender is a group leader.
// If $from_name is already the group leader's full name, we'll prepend a prefix.
// Otherwise, we'll leave it as is (either from site options or blog name).
// Let's add a prefix like "[Group Lead]" before the name if it's from a group leader.
// The original function *already* sets $return to the group leader's name if $user_id is provided and is a group leader.
// So, we can check if the $from_name *looks like* a full name. A more robust check would involve comparing against get_user_by('ID', $user_id) from the original function.
// For simplicity here, we'll assume if it's not the site name, it might be a user's name.
// A more accurate way would be to pass the $user_id to the filter if possible,
// but based on the provided function signature, only $group_id is passed.
// If the original function's logic for determining group leader name is applied,
// and $from_name is now the group leader's name, we can modify it.
// Let's imagine the original function's logic has *already* been executed,
// and $from_name contains either the ulgm_name_from, blog name, or the group leader's name.
// We'll add a prefix if it's the group leader's name.
// A simple heuristic: if the name contains a space and is not the blog name, it's likely a user's name.
$blog_name = get_bloginfo('name');
// If the current $from_name is NOT the blog name and contains at least one space,
// we can infer it's a user's name (potentially a group leader's name).
if ( $from_name !== $blog_name && strpos( $from_name, ' ' ) !== false ) {
$from_name = '[Group Lead] ' . $from_name;
}
return $from_name;
}, 10, 2 ); // Priority 10, accepts 2 arguments: $return and $group_id
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/helpers/shared-functions.php:1169
public static function ulgm_group_management_email_users_from_name( $group_id = null, $user_id = 0 ) {
$from_name = get_option( 'ulgm_name_from', '' );
$return = ! empty( $from_name ) ? $from_name : get_bloginfo( 'name' );
if ( $user_id && 0 < $user_id && learndash_is_group_leader_user( $user_id ) ) {
$user = get_user_by( 'ID', $user_id );
$return = $user->first_name . ' ' . $user->last_name;
}
return apply_filters(
'ulgm_group_management_email_users_from_name',
$return,
$group_id
);
}