Support » Plugin: Ultimate WP Mail » How do I use “Custom Elements”?

  • Resolved tva36012

    (@tva36012)


    Hey,

    What I want to accomplish with Ultimate WP Mail is to send my clients a monthly “marketing report” email, which includes a URL link to their confidential, real-time marketing campaign report, and have that URL be different for each user – I set the URLs myself on the WordPress backend.

    I understand this can be accomplished using “Custom Elements.” However, there’s nothing I see in Ultimate WP Mail where I can easily create a custom element and set it for each user.

    I tried to work in a fix using the “Pods” plugin, but that didn’t work – where it would render on an ordinary WP page, the email body just displays the shortcode.

    The plugin documentation directs me here for help with this feature.
    How do I create and set a Custom Element in Ultimate WP Mail?

    Best!

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author Rustaurius

    (@rustaurius)

    Hi tva,

    What’s your programming comfort level?

    We don’t have a tonne of documentation available on the custom elements, but based on your description I think you should be able to accomplish what you’re trying to do using them if you don’t mind writing a bit of code.

    You’re going to need to add two bits of code to your site. First, you’ going to have the section where you register your custom element. Something like:

    
    add_action('uwpm_register_custom_element', 'register_my_custom_element');
    function register_my_custom_element() {
        uwpm_register_custom_element( 'my_element', array( 'label' => 'My Element', , 'callback_function' => 'create_individual_report_urls' ) );		
    }
    

    That bit will register your custom element. The ‘uwpm_register_custom_element’ function takes two arguments. The first is the element slug, and the second is an array of element params.

    Next, you’re going to need to add in a function that actually put the report URL into your emails. I don’t know exactly what the function is going to look like; it’ll depend on where your URLs are stored. Assuming that they’re saved as user meta data, it would look something like:

    
    function create_individual_report_urls( $params, $user) {
        return get_user_meta( $user->ID, '_user_custom_report_url', true );
    }
    

    You’ll definitely need to update the bottom function. At the very least, you’d need the correct meta key for your report URLs, but you also might need to do something more complicated. Let me know how it goes!

    tva36012

    (@tva36012)

    Thank you so much for the help.

    I don’t mind doing a bit of coding.
    However, I’m new to WP hooks.
    My question is: do I need to edit the hooks into the plugin files? Or do I edit them into the theme?
    Ideally what I would like is to not put them into the theme, as I use plugins and themes that I update regularly.

    If not in the plugin files or the theme files, where exactly do I place this code – is it in the email post in question and as PHP?

    Best!

    Plugin Author Rustaurius

    (@rustaurius)

    Hi tva,

    For the hooks, usually you’d put the extra code into your theme’s functions.php file, but if you’re worried about overwriting the added code, then a simple solution might be to create a mini plugin of your own that just adds in the custom element code. Here’s a guide on how to do it:

    https://www.smashingmagazine.com/2011/09/how-to-create-a-wordpress-plugin/

    It’s a bit old at this point, but covers the basics that you would need, such as the information to put at the top of your file.

    You definitely don’t want to put the code into the post, as the hooks won’t be run when your emails are sent.

    @rustaurius , you are a godsend. I created my own WP plugin exactly as advised and it did the trick. Thank you SOOOOOO much for your input and help!

    Now everyone will understand this feature better. 🙂

    I do have another issue re: subject lines and will cover it in a separate thread.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘How do I use “Custom Elements”?’ is closed to new replies.