• Resolved jasemcnotty

    (@jasemcnotty)


    Thanks for a great plugin.

    I’m trying to create an email template that can reference the name of the List that it is sent to, as it is sent.

    I’ve modified the List builder slightly to allow admins to filter users by which course they’re signed up for in an LMS plugin. The idea is to create a single email template, and multiple Lists. Each List will be for a separate course. When the email is sent to a List, I’d like the name of the List (the same name as the course) to be included in the email without needing to hard code it each time. Is this something that can be done with email variables, snippets or custom elements? Accessing the user record won’t work as they could be signed up to multiple courses. I’m hoping the Lists are saved in the post table and the ID can be referenced somehow to get the post title.

    Any suggestions much appreciated.

    Thanks for reading.

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Support jaysupport

    (@jaysupport)

    Hi Jase,

    What you want to do is likely possible, although we haven’t ever tested or tried to do something like that, so I don’t think we could really help to implement that kind of customization.

    Your lists are stored in the wp_options table, in a setting called: ewd-uwpm-email-lists. That being said, I don’t know if it would even be necessary to call it from there.

    If you look at the admin-send-mail.php template, you’ll see the code used to generate the area that lets you select which list to send an email to. This template is modifiable in a non-destructive way. You could just create a ewd-uwpm-templates folder in your theme folder and put a copy of the template file in that folder. Then you could modify that file how you want and that file will be used instead of the one in the plugin.

    Thread Starter jasemcnotty

    (@jasemcnotty)

    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.

    Plugin Support jaysupport

    (@jaysupport)

    Thanks for sharing your solution! The Ajax.class file will definitely be overwritten if you update the plugin, so, if you will be modifying it in this way, then you’d definitely want to keep a backup of the code you changed/added.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Reference “List Name” in emal template’ is closed to new replies.