get_plugin()->is_active();
}
/**
* The ActiveLayer plugin.
*
* @since 4.10.0
*
* @return ActiveLayer
*/
private function get_plugin() {
static $plugin;
if ( $plugin === null ) {
$plugin = new ActiveLayer();
}
return $plugin;
}
/**
* Whether the ActiveLayer plugin is installed (present, active or not).
*
* @since 4.9.0
*
* @return bool
*/
private function is_activelayer_installed() {
return $this->get_plugin()->is_installed();
}
/**
* Whether ActiveLayer has a validated API key connected.
*
* Mirrors ActiveLayer's own validation checks via cheap option reads,
* without booting any ActiveLayer classes.
*
* @since 4.9.0
*
* @return bool
*/
private function is_api_key_connected() {
$settings = get_option( 'activelayer_global_settings', [] );
$api_key = '';
if ( is_array( $settings ) && isset( $settings['api_key'] ) && is_string( $settings['api_key'] ) ) {
$api_key = trim( $settings['api_key'] );
}
if ( empty( $api_key ) ) {
return false;
}
$validation = get_option( 'activelayer_api_key_validated', [] );
return is_array( $validation ) &&
! empty( $validation['is_valid'] ) &&
! empty( $validation['key'] ) &&
$validation['key'] === $api_key;
}
/**
* Absolute URL of the ActiveLayer settings page (connect-account CTA).
*
* @since 4.9.0
*
* @return string
*/
private function get_settings_url() {
return admin_url( 'admin.php?page=' . self::SETTINGS_PAGE );
}
/**
* Absolute URL of the ActiveLayer integrations page (connected-state link).
*
* @since 4.9.0
*
* @return string
*/
private function get_integrations_url() {
return admin_url( 'admin.php?page=' . self::INTEGRATIONS_PAGE );
}
/**
* Resolve the render state for the current site and user.
*
* @since 4.9.0
*
* @return string One of 'install', 'activate', 'connect', 'connected', or '' to hide.
*/
private function get_state() {
if ( $this->is_activelayer_active() ) {
return $this->is_api_key_connected() ? 'connected' : 'connect';
}
// This section is a guest on the WooCommerce settings page, with no modal of ours
// to explain a refusal.
if ( ! $this->get_plugin()->current_user_can_install_or_activate() ) {
return '';
}
return $this->is_activelayer_installed() ? 'activate' : 'install';
}
/**
* Whether the section should be displayed for the current user.
*
* @since 4.9.0
*
* @return bool
*/
private function should_display() {
/**
* Filters whether the ActiveLayer education section is rendered on the
* WooCommerce Accounts & Privacy settings tab.
*
* @since 4.9.0
*
* @param bool $should_display Whether the section should be displayed.
*/
if ( ! apply_filters( 'wp_mail_smtp_admin_woo_commerce_active_layer_education_should_display', true ) ) {
return false;
}
if ( get_user_meta( get_current_user_id(), self::DISMISS_META, true ) ) {
return false;
}
return $this->get_state() !== '';
}
/**
* Output the section after the WooCommerce account settings block.
*
* Fires on woocommerce_settings_account_registration_options_after, which
* WooCommerce runs after the section's closing table tag, so free-form
* markup is safe here.
*
* @since 4.9.0
*/
public function output_section() {
if ( ! $this->should_display() ) {
return;
}
$state = $this->get_state();
?>
output_state( $state ); ?>
should_display() ) { return; } wp_enqueue_style( 'wp-mail-smtp-activelayer-wc', wp_mail_smtp()->assets_url . '/css/smtp-activelayer-wc.min.css', [], WPMS_PLUGIN_VER ); wp_enqueue_script( 'wp-mail-smtp-activelayer-wc', wp_mail_smtp()->assets_url . '/js/smtp-activelayer-wc' . WP::asset_min() . '.js', [ 'jquery' ], WPMS_PLUGIN_VER, true ); wp_localize_script( 'wp-mail-smtp-activelayer-wc', 'wp_mail_smtp_activelayer_wc', [ 'ajax_url' => admin_url( 'admin-ajax.php' ), 'nonce' => wp_create_nonce( 'wp-mail-smtp-admin' ), 'plugin' => $this->get_plugin()->get_basename(), 'download_url' => $this->get_plugin()->get_download_url(), 'settings_url' => $this->get_settings_url(), 'wporg_url' => $this->get_plugin()->get_wporg_url(), 'installing' => esc_html__( 'Installing...', 'wp-mail-smtp' ), 'activating' => esc_html__( 'Activating...', 'wp-mail-smtp' ), 'goto_settings' => esc_html__( 'Connect Your Free Account', 'wp-mail-smtp' ), 'get_activelayer' => esc_html__( 'Get ActiveLayer', 'wp-mail-smtp' ), 'error_install' => esc_html__( 'Could not install ActiveLayer. Please download it from WordPress.org and install manually.', 'wp-mail-smtp' ), 'error_activate' => esc_html__( 'Could not activate ActiveLayer. Please activate it from the Plugins page.', 'wp-mail-smtp' ), ] ); } /** * AJAX: dismiss the section for the current user. * * @since 4.9.0 */ public function ajax_dismiss() { if ( check_ajax_referer( 'wp-mail-smtp-admin', 'nonce', false ) === false ) { wp_send_json_error( esc_html__( 'Could not dismiss the section. Please reload the page and try again.', 'wp-mail-smtp' ) ); } update_user_meta( get_current_user_id(), self::DISMISS_META, time() ); wp_send_json_success(); } }