Thanks for the reply Jay, definitely pointed me in the right direction. I’ll outline the solution I used if it helps anyone else. Quick disclaimer, this is definitely not the only way to achieve this and almost certainly not the best/safest way as it involves changing some of the “core” php files in the plugin.
adding a custom element to the TinyMCE email variables:
add this to main functions.php file, or using a code snippet plugin
function insert_list_name_into_mass_email() {
return '[email_list_name]';
}
add_action('uwpm_register_custom_element', 'register_my_custom_element');
function register_my_custom_element() {
uwpm_register_custom_element( 'email_list_name', array( 'label' => 'Email List Name', '', 'callback_function' => 'insert_list_name_into_mass_email' ) );
}
This will create a custom shortcode available in the “email variables” dropdown called [email_list_name]. The substitution that happens in insert_list_name_into_mass_email() doesn’t really matter, so I just have it return the same value as the original shortcode (ie, [email_list_name] becomes [email_list_name]. You’ll see why it doesn’t matter next.
This is where I’m sure there are better ways to do it but it works for me. Modify the file: /plugins/ultimate-wp-mail/includes/Ajax.class
around line 126, just before the $params = array( bit of the email_user_list function, add the following:
// check for presence of custom shortcode
if(strpos($_POST['email_content'], '[email_list_name]') !== false && is_numeric($_POST['list_id'])) {
// get all list data from wp_options table
$getlists = array_filter( (array) get_option( 'ewd-uwpm-email-lists' ) );
// get array key based on list id
$mykey = array_search($_POST['list_id'], array_column($getlists, 'id'));
if(is_numeric($mykey)) {
$getlist_name = sanitize_text_field($getlists[$mykey]->name);
if(!empty($getlist_name)) {
// replace shortcode with list name
$_POST['email_content'] = str_replace('[email_list_name]', $getlist_name, $_POST['email_content']);
}
}
}
Keep a copy of this file (Ajax.class) on your local computer or in a redundant folder on the web host as it will probably be overwritten when updating the plugin.