• Resolved jjci

    (@jjci)


    I have progressively developed a customer shortcode that has worked correctly so far in a simple newsletter. However, I have added code (from ‘github’, originally without any changes) code in order to retrieve basic WordPress user meta data. However, I just cannot make it work.

    I am not clear on how the WordPress ‘user_id’ value is established for use within the shortcode. That is, is it a stand-alone value that can just be used or must it be derived based on the ‘subscriber id’? If the latter, how is each ‘subscriber_id’ in the subscriber list passed into the shortcode in order to generate each email?

    I can get my code to work if I can find a way to establish, within the shortcode, the WordPress user id value related to each subscriber in the newsletter subscriber list.

    Any help would be appreciated.

Viewing 10 replies - 1 through 10 (of 10 total)
  • Hi,

    Could you please share your code?

    Regards,
    MailPoet Team.

    Thread Starter jjci

    (@jjci)

    I think my confusion is based on the sample code provided on the MailPoet website regarding custom shortcodes, as follows:

    add_filter(‘mailpoet_newsletter_shortcode’, ‘mailpoet_custom_shortcode’, 10, 5);
    function mailpoet_custom_shortcode($shortcode, $newsletter, $subscriber, $queue, $newsletter_body) {…

    How are the parameters, other than $shortcode, accessed by this code? I know that there is no reference to these other parameter values in the body of the code. However, I have tried to add code to display the other inbound parameter values, but they don’t appear to be populated.
    I have tried to execute the custom shortcode specifying a value for $subscriber, but the code does not recognize any inbound value other than $shortcode.

    I can resolve my original issue if I can access the Subscriber value as each email is generated as the relevant list. However, I am now confused about how the custom shortcodes pass parameter values.

    Re,

    All of these parameters are populated when the shortcode is executed. You cannot modify them but they you surely can access them:

    1. Add [custom:foo] shortcode to your newsletter
    2. Add the following to your functions.php or elsewhere:

    
    add_filter('mailpoet_newsletter_shortcode', 'mailpoet_custom_shortcode', 10, 5);
    function mailpoet_custom_shortcode($shortcode, $newsletter, $subscriber, $queue, $newsletter_body) {
      // always return the shortcode if it doesn't match your own
      if ($shortcode !== '[custom:foo]') return $shortcode;
    
      var_dump($newsletter); // this will output the object when you preview the newsletter;
    }
    

    Regards,
    MailPoet Team.

    Thread Starter jjci

    (@jjci)

    How do I access the $subscriber value?
    I have tried to use it within the code, but it’s null.

    Is it null during sending or when you preview the newsletter? Can you access other variables? They should all be populated (except for $queue that appears only during sending).

    Thread Starter jjci

    (@jjci)

    So far, I have been testing my newsletter by sending a preview to a specific email address.

    Thread Starter jjci

    (@jjci)

    1)
    From the main email menu, for this newsletter, I clicked on ‘Preview’.
    I received a PHP error regarding a circular reference.

    2)
    I updated the newsletter details to use a test user list, and then sent it.
    The email arrived, but there was no value displayed for the ‘subscriber’ parameter.

    Try the above code but instead of dumping $newsletter, dump $subscriber. Test it by previewing your email in browser (do not sent it). If you still can’t see the contents of the $subscriber object, please use the blue feedback button on any of the plugin pages to get in touch with us directly.

    Thread Starter jjci

    (@jjci)

    I have sent the output of the var_dump($subscriber) in a separate email.

    Thread Starter jjci

    (@jjci)

    Issue resolved.
    The support was very good regarding the clarification of the default parameters and how to access specific elements of them.

Viewing 10 replies - 1 through 10 (of 10 total)
  • The topic ‘Cannot retrieve user meta in shortcode’ is closed to new replies.