• Resolved wp_user1

    (@wp_user1)


    After updating MailPoet we got an error – what should we do here?

    MailPoet 5.7.1/5.8.0

    Here is the source code:

    if (class_exists(\MailPoet\API\API::class)) {
    $mailpoet_api = \MailPoet\API\API::MP('v1');
    }
    try {
    $fil=array(
    'status'=>'subscribed',
    'listId'=>$listid
    );
    $subscribers = $mailpoet_api->getSubscribers($fil,500);
    } catch (\Exception $e) {
    echo 'error';
    }
Viewing 9 replies - 1 through 9 (of 9 total)
  • Plugin Support kellymetal a11n

    (@kellymetal)

    Hi there @wp_user1,

    What is the specific error message you are receiving?

    I just tested on my site with the latest version 5.8.0 of the MailPoet plugin with the following snippet, and it wrote my list of subscribed subscribers to the log:

    function kel_test_footer_action() {
    if (class_exists(\MailPoet\API\API::class)) {
    try {
    $mailpoet_api = \MailPoet\API\API::MP('v1');

    $fil = array(
    'status' => 'subscribed',
    'listId' => '1'
    );
    $subscribers = $mailpoet_api->getSubscribers($fil, 500);

    error_log(print_r($subscribers, true));
    } catch (\Exception $e) {
    // Log the actual error
    }
    }
    }
    add_action( 'wp_footer', 'kel_test_footer_action');
    Thread Starter wp_user1

    (@wp_user1)

    I get this error message:

    Fatal error: Uncaught Error: Call to a member function getSubscribers() on null in /var/www/html/wp-content/themes/xxx/functions.php:3504

    Here is the code:

    if (class_exists(\MailPoet\API\API::class)) {
      $mailpoet_api = \MailPoet\API\API::MP('v1');
    }
      try {
        $get_subscribers = $mailpoet_api->getSubscribers(array('listId'=>3), 999);
      } catch (\Exception $e) {
    
      }
    Plugin Author Ján Miklá?

    (@neosinner)

    @wp_user1 in your code, the whole try/catch code needs to be inside the if. As you have it, when the MailPoet API class doesn’t exist, you’ll still call the API, which results in the error you see.

    So it should be like this:

    if (class_exists(\MailPoet\API\API::class)) {
    $mailpoet_api = \MailPoet\API\API::MP('v1');

    try {
    $get_subscribers = $mailpoet_api->getSubscribers(array('listId'=>3), 999);
    } catch (\Exception $e) {

    }
    }

    This will prevent the error from happening when the MailPoet API doesn’t exist.

    Plugin Author Ján Miklá?

    (@neosinner)

    @wp_user1 one other thing. At the time, you are calling this code, the MailPoet is very likely not yet loaded, so the MailPoet API won’t work. You need to ensure, that MailPoet plugin is loaded before you try to call the API.

    Thread Starter wp_user1

    (@wp_user1)

    Hm but Mailpoet is installed and active.. We did not change the code, but it stopped working after upgrading Mailpoet.

    Thread Starter wp_user1

    (@wp_user1)

    Could it be that Mailpoet stops working completely only because WooCommerce is not the newest version? ??

    Plugin Author Ján Miklá?

    (@neosinner)

    Could it be that Mailpoet stops working completely only because WooCommerce is not the newest version? ??

    MailPoet supports the latest and the previous WooCommerce version (so at the moment, 9.6.2 and 9.7.1) so if you have an older version, then yes, MailPoet will disable itself, and you should see this notice on your admin pages:

    MailPoet plugin requires WooCommerce version 9.6.2 or newer. Please update your WooCommerce plugin version…

    Thread Starter wp_user1

    (@wp_user1)

    okay this is really weird. We saw the Message but never expected that Mailpoet completely stops working then… Good to know :/

    Plugin Support Gui A. a11n

    (@guicmazeredo)

    Yes. Please have that in mind from now on and you shouldn’t have issues. If you do, let us know. For now, I’m marking this thread as resolved.

Viewing 9 replies - 1 through 9 (of 9 total)
  • You must be logged in to reply to this topic.