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');
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) {
}
@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.
@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.
Hm but Mailpoet is installed and active.. We did not change the code, but it stopped working after upgrading Mailpoet.
Could it be that Mailpoet stops working completely only because WooCommerce is not the newest version? 😮
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…
okay this is really weird. We saw the Message but never expected that Mailpoet completely stops working then… Good to know :/
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.