diff --git a/changelog/fix-mailpoet-error-on-plugin-activation b/changelog/fix-mailpoet-error-on-plugin-activation new file mode 100644 index 0000000000..dba54b316a --- /dev/null +++ b/changelog/fix-mailpoet-error-on-plugin-activation @@ -0,0 +1,4 @@ +Significance: patch +Type: fixed + +Fix error when activating MailPoet diff --git a/includes/class-sensei.php b/includes/class-sensei.php index 8936a38ad2..abfff73155 100644 --- a/includes/class-sensei.php +++ b/includes/class-sensei.php @@ -845,10 +845,19 @@ public function initialize_global_objects() { * @return {bool} Whether to enable feature. */ if ( apply_filters( 'sensei_email_mailpoet_feature', true ) ) { - if ( class_exists( \MailPoet\API\API::class ) ) { - $mailpoet_api = \MailPoet\API\API::MP( 'v1' ); - new Sensei\Emails\MailPoet\Main( $mailpoet_api ); - } + add_action( 'mailpoet_initialized', [ $this, 'initialize_mailpoet' ] ); + } + } + + /** + * Initialize MailPoet integration. + * + * @since $$next-version$$ + */ + public function initialize_mailpoet() { + if ( class_exists( \MailPoet\API\API::class ) ) { + $mailpoet_api = \MailPoet\API\API::MP( 'v1' ); + new Sensei\Emails\MailPoet\Main( $mailpoet_api ); } }