[
self::DISMISSED => 'image-optimization-once',
self::CAPABILITY => 'install_plugins',
self::DEFINED => 'IMAGE_OPTIMIZATION_VERSION',
],
'image-optimization-once-media-modal' => [
self::DISMISSED => 'image-optimization-once-media-modal',
self::CAPABILITY => 'install_plugins',
self::DEFINED => 'IMAGE_OPTIMIZATION_VERSION',
],
'image-optimization' => [
self::DISMISSED => 'image_optimizer_hint',
self::CAPABILITY => 'install_plugins',
self::DEFINED => 'IMAGE_OPTIMIZATION_VERSION',
],
'image-optimization-connect' => [
self::DISMISSED => 'image_optimizer_hint',
self::CAPABILITY => 'manage_options',
self::NOT_DEFINED => 'IMAGE_OPTIMIZATION_VERSION',
self::NOT_HAS_OPTION => 'image_optimizer_access_token',
],
'image-optimization-media-modal' => [
self::DISMISSED => 'image-optimization-media-modal',
self::CAPABILITY => 'install_plugins',
self::DEFINED => 'IMAGE_OPTIMIZATION_VERSION',
],
'ally_heading_notice' => [
self::DISMISSED => 'ally_heading_notice',
self::CAPABILITY => 'install_plugins',
self::NOT_HAS_OPTION => 'ea11y_access_token',
],
];
if ( ! $hint_key ) {
return $hints;
}
return $hints[ $hint_key ] ?? [];
}
/**
* Get_notice_icon
*
* @return string
*/
public static function get_notice_icon(): string {
return '
';
}
/**
* Get_notice_template
*
* Print or Retrieve the notice template.
*
* @param array $notice
* @param bool $should_return
*
* @return string|void
*/
public static function get_notice_template( array $notice, bool $should_return = false ) {
$default_settings = [
'type' => 'info',
'icon' => false,
'heading' => '',
'content' => '',
'dismissible' => false,
'button_text' => '',
'button_event' => '',
'button_data' => [],
'display' => false,
];
$notice_settings = array_merge( $default_settings, $notice );
if ( empty( $notice_settings['heading'] ) && empty( $notice_settings['content'] ) ) {
return '';
}
if ( ! in_array( $notice_settings['type'], self::get_notice_types(), true ) ) {
$notice_settings['type'] = 'info';
}
$icon = '';
$heading = '';
$content = '';
$dismissible = '';
$button = '';
if ( $notice_settings['icon'] ) {
$icon = self::get_notice_icon();
}
if ( ! empty( $notice_settings['heading'] ) ) {
$heading = '' . $notice_settings['heading'] . '
';
}
if ( ! empty( $notice_settings['content'] ) ) {
$content = '' . $notice_settings['content'] . '
';
}
if ( ! empty( $notice_settings['button_text'] ) ) {
$button_settings = ( ! empty( $notice_settings['button_data'] ) ) ? ' data-settings="' . esc_attr( wp_json_encode( $notice_settings['button_data'] ) ) . '"' : '';
$button = '
';
}
if ( $notice_settings['dismissible'] ) {
$dismissible = '';
}
$notice_template = sprintf( '',
$notice_settings['type'],
$icon,
$heading,
$content,
$button,
$dismissible,
$notice_settings['display']
);
if ( $should_return ) {
return $notice_template;
}
echo wp_kses( $notice_template, self::get_notice_allowed_html() );
}
/**
* Get_plugin_install_url
*
* @param $plugin_slug
*
* @return string
*/
public static function get_plugin_install_url( $plugin_slug ): string {
$action = 'install-plugin';
return wp_nonce_url(
add_query_arg(
[
'action' => $action,
'plugin' => $plugin_slug,
],
admin_url( 'update.php' )
),
$action . '_' . $plugin_slug
);
}
/**
* Get_plugin_activate_url
*
* @param $plugin_slug
*
* @return string
*/
public static function get_plugin_activate_url( $plugin_slug ): string {
$path = "$plugin_slug/$plugin_slug.php";
return wp_nonce_url(
admin_url( 'plugins.php?action=activate&plugin=' . $path ),
'activate-plugin_' . $path
);
}
/**
* Is_dismissed
*
* @param $key
*
* @return bool
*/
public static function is_dismissed( $key ): bool {
$dismissed = User::get_dismissed_editor_notices();
return in_array( $key, $dismissed, true );
}
/**
* Should_display_hint
*
* @param $hint_key
*
* @return bool
*/
public static function should_display_hint( $hint_key ): bool {
$hint = self::get_hints( $hint_key );
if ( empty( $hint ) ) {
return false;
}
foreach ( $hint as $key => $value ) {
switch ( $key ) {
case self::DISMISSED:
if ( self::is_dismissed( $value ) ) {
return false;
}
break;
case self::CAPABILITY:
if ( ! current_user_can( $value ) ) {
return false;
}
break;
case self::DEFINED:
if ( defined( $value ) ) {
return false;
}
break;
case self::NOT_DEFINED:
if ( ! defined( $value ) ) {
return false;
}
break;
case self::PLUGIN_INSTALLED:
if ( ! self::is_plugin_installed( $value ) ) {
return false;
}
break;
case self::PLUGIN_ACTIVE:
if ( ! self::is_plugin_active( $value ) ) {
return false;
}
break;
case self::NOT_HAS_OPTION:
$option = get_option( $value );
if ( ! empty( $option ) ) {
return false;
}
break;
}
}
return true;
}
private static function is_conflict_plugin_installed(): bool {
if ( ! Utils::has_pro() ) {
return false;
}
$conflicting_plugins = [
'imagify/imagify.php',
'optimole-wp/optimole-wp.php',
'ewww-image-optimizer/ewww-image-optimizer.php',
'ewww-image-optimizer-cloud/ewww-image-optimizer-cloud.php',
'kraken-image-optimizer/kraken.php',
'shortpixel-image-optimiser/wp-shortpixel.php',
'wp-smushit/wp-smush.php',
'wp-smush-pro/wp-smush.php',
'tiny-compress-images/tiny-compress-images.php',
];
foreach ( $conflicting_plugins as $plugin ) {
if ( self::is_plugin_active( $plugin ) ) {
return true;
}
}
return false;
}
/**
* Is_plugin_installed
*
* @param $plugin
*
* @return bool
*/
public static function is_plugin_installed( $plugin ): bool {
if ( ! function_exists( 'get_plugins' ) ) {
require_once ABSPATH . 'wp-admin/includes/plugin.php';
}
$plugins = get_plugins();
$plugin = self::ensure_plugin_folder( $plugin );
return ! empty( $plugins[ $plugin ] );
}
/**
* Is_plugin_active
*
* @param $plugin
*
* @return bool
*/
public static function is_plugin_active( $plugin ): bool {
$plugin = self::ensure_plugin_folder( $plugin );
return is_plugin_active( $plugin );
}
/**
* Get_plugin_action_url
*
* @param $plugin
*
* @return string
*/
public static function get_plugin_action_url( $plugin ): string {
if ( ! self::is_plugin_installed( $plugin ) ) {
return self::get_plugin_install_url( $plugin );
}
if ( ! self::is_plugin_active( $plugin ) ) {
return self::get_plugin_activate_url( $plugin );
}
return '';
}
/**
* Ensure_plugin_folder
*
* @param $plugin
*
* @return string
*/
private static function ensure_plugin_folder( $plugin ): string {
if ( false === strpos( $plugin, '/' ) ) {
$plugin = $plugin . '/' . $plugin . '.php';
}
return $plugin;
}
/**
* Get_notice_allowed_html
*
* @return array[]
*/
public static function get_notice_allowed_html(): array {
return [
'div' => [
'class' => [],
'data-display' => [],
],
'svg' => [
'width' => [],
'height' => [],
'viewbox' => [],
'fill' => [],
'xmlns' => [],
],
'path' => [
'd' => [],
'stroke' => [],
'stroke-width' => [],
'stroke-linecap' => [],
'stroke-linejoin' => [],
],
'button' => [
'class' => [],
'data-event' => [],
'data-settings' => [],
'data-tooltip' => [],
],
'i' => [
'class' => [],
'aria-hidden' => [],
],
'span' => [
'class' => [],
],
'a' => [
'href' => [],
'style' => [],
'target' => [],
],
];
}
public static function is_plugin_connected( $option_prefix ): bool {
return ! empty( get_option( $option_prefix . '_access_token' ) );
}
private static function get_all_widget_content( $step ) {
$steps = [
self::INSTALL => esc_html__( 'Install Ally to add an accessibility widget visitors can use to navigate your site.', 'elementor' ),
self::ACTIVATE => esc_html__( 'Activate the Ally plugin to turn its accessibility features on across your site.', 'elementor' ),
self::CONNECT => esc_html__( "Connect the Ally plugin to your account to access all of it's accessibility features.", 'elementor' ),
self::CUSTOMIZE => esc_html__( "Customize the widget's look, position and the capabilities available for your visitors.", 'elementor' ),
];
return $steps[ $step ];
}
private static function get_all_widget_action_button( $step ) {
$steps = [
self::INSTALL => esc_html__( 'install Now', 'elementor' ),
self::ACTIVATE => esc_html__( 'Activate', 'elementor' ),
self::CONNECT => esc_html__( 'Connect', 'elementor' ),
self::CUSTOMIZE => esc_html__( 'Customize', 'elementor' ),
];
return $steps[ $step ];
}
private static function get_all_widget_action_url( $step ) {
if ( in_array( $step, [ self::INSTALL, self::ACTIVATE ], true ) ) {
$campaign_data = [
'name' => 'elementor_ea11y_campaign',
'campaign' => 'acc-usability-widget-plg-ally',
'source' => 'editor-ally-widget',
'medium' => 'editor',
];
return Admin_Notices::add_plg_campaign_data( self::get_plugin_action_url( 'pojo-accessibility' ), $campaign_data );
}
return self::CONNECT === $step ? admin_url( 'admin.php?page=accessibility-settings' ) : admin_url( 'admin.php?page=accessibility-settings#design' );
}
private static function get_ally_cta_button( $step ) {
return [
'text' => self::get_all_widget_action_button( $step ),
'url' => self::get_all_widget_action_url( $step ),
'classes' => [ 'elementor-button' ],
];
}
public static function get_ally_action_data(): array {
$plugin_slug = 'pojo-accessibility';
$is_installed = self::is_plugin_installed( $plugin_slug );
$is_active = self::is_plugin_active( $plugin_slug );
$is_connected = self::is_plugin_connected( 'ea11y' );
if ( ! $is_installed ) {
$step = self::INSTALL;
} elseif ( ! $is_active ) {
$step = self::ACTIVATE;
} elseif ( ! $is_connected ) {
$step = self::CONNECT;
} else {
$step = self::CUSTOMIZE;
}
$data = [
'title' => __( 'Ally web accessibility', 'elementor' ),
'content' => self::get_all_widget_content( $step ),
'action_button' => self::get_ally_cta_button( $step ),
];
return $data;
}
}