Automattic\WooCommerce\Admin\Features

LaunchYourStore::is_mailpoet_connected()privateWC 1.0

Check if the Mailpoet is connected.

Метод класса: LaunchYourStore{}

Хуков нет.

Возвращает

true|false. true if Mailpoet is fully connected, meaning the API key is valid and approved.

Использование

// private - только в коде основоного (родительского) класса
$result = $this->is_mailpoet_connected();

Код LaunchYourStore::is_mailpoet_connected() WC 9.7.1

private function is_mailpoet_connected() {
	if ( ! class_exists( '\MailPoet\DI\ContainerWrapper' ) || ! class_exists( '\MailPoet\Settings\SettingsController' ) ) {
		return false;
	}

	$container = \MailPoet\DI\ContainerWrapper::getInstance( WP_DEBUG );

	// SettingController retrieves data from wp_mailpoet_settings table.
	$settings = $container->get( \MailPoet\Settings\SettingsController::class );

	if ( false === $settings instanceof \MailPoet\Settings\SettingsController ) {
		return false;
	}

	$mta       = $settings->get( 'mta' );
	$api_state = $mta['mailpoet_api_key_state'] ?? null;

	if ( ! $api_state || ! isset( $api_state['state'], $api_state['code'] ) ) {
		return false;
	}

	return 'valid' === $api_state['state'] && 200 === $api_state['code'];
}