• I am trying to make Mailpoet process a shortcode in newsletters, that works in posts or pages, by creating a custom shortcode following http://support.mailpoet.com/knowledgebase/hook-to-add-your-own-shortcode/.
    The examples (my_name and blog_name) work fine, but the custom shortcode I made, that retrieves a list of the next 10 upcoming events from the Events Made Easy plugin, outputs the list to the upperleft of my browser window in a preview of the newsletter, instead of to the content of the newsletter.
    Also if I send an example of the newsletter it pops up a message like “Request error Not JSON ….”.

    Here’s the modified code I put in function.php:

    /**
     * This is an example of a custom shortcode parser for MailPoet newsletters.
     * It's really easy to implement.
     * We already automatically parse all shortcodes with this notation for you: [custom:my_value]
     * You just have to add a filter and return the value you prefer.
     * In the following example we added [custom:my_name] and [custom:blog_name] to our newsletter.
     * We have now to return the preferred values, as string.
     */
    // [custom:my_name]
    // [custom:blog_name]
    function mailpoet_shortcodes_custom_filter( $tag_value , $user_id) {
    
        // $tag_value contains the string after custom:
        // This function will be called the first time with $tag_value = my_name
        // The second time with $tag_value = blog_name
    
        // $user_id contains the corresponding MailPoet's subscriber id,
        // this could be useful to fetch extra data from the WordPress user's meta for instance
        // e.g.: https://gist.github.com/benheu/cf9eb925b0e17e6dbd6c
    
    	if ($tag_value === 'my_name') {
            $replacement = 'Maily';
        }
    
        if ($tag_value === 'blog_name') {
            $replacement = get_bloginfo('name');
        }
    
       	if ($tag_value === 'eme_events') {
            		$replacement = eme_get_events_list('limit=10');
    	}
    
        return $replacement;
    
    }
    add_filter('wysija_shortcodes', 'mailpoet_shortcodes_custom_filter',10 ,2);

    `

    Any help is most welcome…

    Peter

    https://wordpress.org/plugins/wysija-newsletters/

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter ikookmaar

    (@ikookmaar)

    The Events Made Easy developer suspects that maybe only simple strings are to be returned or the replacement should be encoded in some way…
    The Events Made Easy call returns html, maybe that is not allowed in newsletters?

    Exactly, our newsletter render will strip those HTML tags to avoid compatibility issues!

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘custom shortcodes in newsletters’ is closed to new replies.