• Resolved Rick

    (@murlyn)


    So a couple tiny versions back, like 3.63 I was able to code up something like this:

    $newsletters = Newsletter::getArchives();
    $previewUrl = NewsletterUrl::getViewInBrowserUrl($newsletters[0], false, false);

    and it would give us the URL of the latest newsletter. With 3.64 that no longer works and I can’t figure out how to do this for the life of me anymore. Can anyone help on how to do this?

Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter Rick

    (@murlyn)

    Ok I was able to find another helper class that.. well.. helped, but I was hoping to use just MailPoet functions/classes to pull the data instead of $wpdb, but I couldn’t figure it out:

    global $wpdb;
    $newsletter = $wpdb->get_results("SELECT id, hash from ". MP_NEWSLETTERS_TABLE ." WHERE status = 'sent' ORDER BY sent_at DESC LIMIT 1");
    if (!empty($newsletter)) {
    	$data = [$newsletter[0]->id, $newsletter[0]->hash];
    	$previewURL = Router::buildRequest(
    	      ViewInBrowserEndpoint::ENDPOINT,
    	      ViewInBrowserEndpoint::ACTION_VIEW,
    	      $data
    	   );
    	return $previewURL;
    }
    • This reply was modified 3 years, 4 months ago by Rick.
    Plugin Author MailPoet

    (@mailpoet)

    Hi @murlyn, the code you used before was refactored in 3.64.0 and can no longer be called statically.

    I don’t think there is an easier solution than what you found, however, as these static methods are not meant to be used publicly (we only offer a limited public API), they can change in the future and even your current solution can stop working.

    Thread Starter Rick

    (@murlyn)

    Ok thank you, hopefully you don’t break it any time soon then ??

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Get the latest newsletter URL’ is closed to new replies.