| @@ -1,18 +1,15 @@ | ||
| 1 | 1 | <?php |
| 2 | -namespace Elementor\Core\Utils; | |
| 2 | +namespace elementor\core\utils; | |
| 3 | 3 | |
| 4 | 4 | if ( ! defined( 'ABSPATH' ) ) { |
| 5 | 5 | exit; // Exit if accessed directly. |
| 6 | 6 | } |
| 7 | 7 | |
| 8 | -use Elementor\Plugin; | |
| 9 | 8 | use Elementor\User; |
| 10 | 9 | use Elementor\Utils; |
| 11 | -use Elementor\Core\Admin\Admin_Notices; | |
| 12 | 10 | |
| 13 | 11 | class Hints { |
| 14 | - | |
| 15 | 12 | const INFO = 'info'; |
| 16 | 13 | const SUCCESS = 'success'; |
| 17 | 14 | const WARNING = 'warning'; |
| 18 | 15 | const DANGER = 'danger'; |
| @@ -17,23 +14,15 @@ | ||
| 17 | 14 | const WARNING = 'warning'; |
| 18 | 15 | const DANGER = 'danger'; |
| 19 | 16 | |
| 20 | 17 | const DEFINED = 'defined'; |
| 21 | - const NOT_DEFINED = 'not_defined'; | |
| 22 | 18 | const DISMISSED = 'dismissed'; |
| 23 | 19 | const CAPABILITY = 'capability'; |
| 24 | 20 | const PLUGIN_INSTALLED = 'plugin_installed'; |
| 25 | 21 | const PLUGIN_ACTIVE = 'plugin_active'; |
| 26 | - const NOT_HAS_OPTION = 'not_has_option'; | |
| 27 | 22 | |
| 28 | - const INSTALL = 'install'; | |
| 29 | - const ACTIVATE = 'activate'; | |
| 30 | - const CONNECT = 'connect'; | |
| 31 | - const CUSTOMIZE = 'customize'; | |
| 32 | - | |
| 33 | 23 | /** |
| 34 | - * Get_notice_types | |
| 35 | - * | |
| 24 | + * get_notice_types | |
| 36 | 25 | * @return string[] |
| 37 | 26 | */ |
| 38 | 27 | public static function get_notice_types(): array { |
| 39 | 28 | return [ |
| @@ -44,9 +33,9 @@ | ||
| 44 | 33 | ]; |
| 45 | 34 | } |
| 46 | 35 | |
| 47 | 36 | /** |
| 48 | - * Get_hints | |
| 37 | + * get_hints | |
| 49 | 38 | * |
| 50 | 39 | * @param $hint_key |
| 51 | 40 | * |
| 52 | 41 | * @return array|string[]|\string[][] |
| @@ -67,24 +56,13 @@ | ||
| 67 | 56 | self::DISMISSED => 'image_optimizer_hint', |
| 68 | 57 | self::CAPABILITY => 'install_plugins', |
| 69 | 58 | self::DEFINED => 'IMAGE_OPTIMIZATION_VERSION', |
| 70 | 59 | ], |
| 71 | - 'image-optimization-connect' => [ | |
| 72 | - self::DISMISSED => 'image_optimizer_hint', | |
| 73 | - self::CAPABILITY => 'manage_options', | |
| 74 | - self::NOT_DEFINED => 'IMAGE_OPTIMIZATION_VERSION', | |
| 75 | - self::NOT_HAS_OPTION => 'image_optimizer_access_token', | |
| 76 | - ], | |
| 77 | 60 | 'image-optimization-media-modal' => [ |
| 78 | 61 | self::DISMISSED => 'image-optimization-media-modal', |
| 79 | 62 | self::CAPABILITY => 'install_plugins', |
| 80 | 63 | self::DEFINED => 'IMAGE_OPTIMIZATION_VERSION', |
| 81 | 64 | ], |
| 82 | - 'ally_heading_notice' => [ | |
| 83 | - self::DISMISSED => 'ally_heading_notice', | |
| 84 | - self::CAPABILITY => 'install_plugins', | |
| 85 | - self::NOT_HAS_OPTION => 'ea11y_access_token', | |
| 86 | - ], | |
| 87 | 65 | ]; |
| 88 | 66 | if ( ! $hint_key ) { |
| 89 | 67 | return $hints; |
| 90 | 68 | } |
| @@ -92,10 +70,9 @@ | ||
| 92 | 70 | return $hints[ $hint_key ] ?? []; |
| 93 | 71 | } |
| 94 | 72 | |
| 95 | 73 | /** |
| 96 | - * Get_notice_icon | |
| 97 | - * | |
| 74 | + * get_notice_icon | |
| 98 | 75 | * @return string |
| 99 | 76 | */ |
| 100 | 77 | public static function get_notice_icon(): string { |
| 101 | 78 | return '<div class="elementor-control-notice-icon"> |
| @@ -105,18 +82,17 @@ | ||
| 105 | 82 | </div>'; |
| 106 | 83 | } |
| 107 | 84 | |
| 108 | 85 | /** |
| 109 | - * Get_notice_template | |
| 86 | + * get_notice_template | |
| 110 | 87 | * |
| 111 | 88 | * Print or Retrieve the notice template. |
| 112 | - * | |
| 113 | 89 | * @param array $notice |
| 114 | - * @param bool $should_return | |
| 90 | + * @param bool $return | |
| 115 | 91 | * |
| 116 | 92 | * @return string|void |
| 117 | 93 | */ |
| 118 | - public static function get_notice_template( array $notice, bool $should_return = false ) { | |
| 94 | + public static function get_notice_template( array $notice, bool $return = false ) { | |
| 119 | 95 | $default_settings = [ |
| 120 | 96 | 'type' => 'info', |
| 121 | 97 | 'icon' => false, |
| 122 | 98 | 'heading' => '', |
| @@ -155,9 +131,9 @@ | ||
| 155 | 131 | $content = '<div class="elementor-control-notice-main-content">' . $notice_settings['content'] . '</div>'; |
| 156 | 132 | } |
| 157 | 133 | |
| 158 | 134 | if ( ! empty( $notice_settings['button_text'] ) ) { |
| 159 | - $button_settings = ( ! empty( $notice_settings['button_data'] ) ) ? ' data-settings="' . esc_attr( wp_json_encode( $notice_settings['button_data'] ) ) . '"' : ''; | |
| 135 | + $button_settings = ( ! empty( $notice_settings['button_data'] ) ) ? ' data-settings="' . esc_attr( json_encode( $notice_settings['button_data'] ) ) . '"' : ''; | |
| 160 | 136 | $button = '<div class="elementor-control-notice-main-actions"> |
| 161 | 137 | <button type="button" class="e-btn e-' . $notice_settings['type'] . ' e-btn-1" data-event="' . $notice_settings['button_event'] . '"' . $button_settings . '> |
| 162 | 138 | ' . $notice_settings['button_text'] . ' |
| 163 | 139 | </button> |
| @@ -164,10 +140,11 @@ | ||
| 164 | 140 | </div>'; |
| 165 | 141 | } |
| 166 | 142 | |
| 167 | 143 | if ( $notice_settings['dismissible'] ) { |
| 168 | - $dismissible = '<button class="elementor-control-notice-dismiss tooltip-target" data-event="' . $notice_settings['dismissible'] . '" data-tooltip="' . esc_attr__( 'Don’t show again.', 'elementor' ) . '" aria-label="' . esc_attr__( 'Don’t show again.', 'elementor' ) . '"> | |
| 144 | + $dismissible = '<button class="elementor-control-notice-dismiss tooltip-target" data-event="' . $notice_settings['dismissible'] . '" data-tooltip="' . esc_attr__( 'Don’t show again.', 'elementor' ) . '"> | |
| 169 | 145 | <i class="eicon eicon-close" aria-hidden="true"></i> |
| 146 | + <span class="elementor-screen-only">' . esc_html__( 'Don’t show again.', 'elementor' ) . '</span> | |
| 170 | 147 | </button>'; |
| 171 | 148 | } |
| 172 | 149 | |
| 173 | 150 | $notice_template = sprintf( '<div class="elementor-control-notice elementor-control-notice-type-%1$s" data-display="%7$s"> |
| @@ -187,9 +164,9 @@ | ||
| 187 | 164 | $dismissible, |
| 188 | 165 | $notice_settings['display'] |
| 189 | 166 | ); |
| 190 | 167 | |
| 191 | - if ( $should_return ) { | |
| 168 | + if ( $return ) { | |
| 192 | 169 | return $notice_template; |
| 193 | 170 | } |
| 194 | 171 | echo wp_kses( $notice_template, self::get_notice_allowed_html() ); |
| 195 | 172 | } |
| @@ -194,10 +171,9 @@ | ||
| 194 | 171 | echo wp_kses( $notice_template, self::get_notice_allowed_html() ); |
| 195 | 172 | } |
| 196 | 173 | |
| 197 | 174 | /** |
| 198 | - * Get_plugin_install_url | |
| 199 | - * | |
| 175 | + * get_plugin_install_url | |
| 200 | 176 | * @param $plugin_slug |
| 201 | 177 | * |
| 202 | 178 | * @return string |
| 203 | 179 | */ |
| @@ -215,10 +191,9 @@ | ||
| 215 | 191 | ); |
| 216 | 192 | } |
| 217 | 193 | |
| 218 | 194 | /** |
| 219 | - * Get_plugin_activate_url | |
| 220 | - * | |
| 195 | + * get_plugin_activate_url | |
| 221 | 196 | * @param $plugin_slug |
| 222 | 197 | * |
| 223 | 198 | * @return string |
| 224 | 199 | */ |
| @@ -230,10 +205,9 @@ | ||
| 230 | 205 | ); |
| 231 | 206 | } |
| 232 | 207 | |
| 233 | 208 | /** |
| 234 | - * Is_dismissed | |
| 235 | - * | |
| 209 | + * is_dismissed | |
| 236 | 210 | * @param $key |
| 237 | 211 | * |
| 238 | 212 | * @return bool |
| 239 | 213 | */ |
| @@ -242,10 +216,9 @@ | ||
| 242 | 216 | return in_array( $key, $dismissed, true ); |
| 243 | 217 | } |
| 244 | 218 | |
| 245 | 219 | /** |
| 246 | - * Should_display_hint | |
| 247 | - * | |
| 220 | + * should_display_hint | |
| 248 | 221 | * @param $hint_key |
| 249 | 222 | * |
| 250 | 223 | * @return bool |
| 251 | 224 | */ |
| @@ -260,53 +233,29 @@ | ||
| 260 | 233 | case self::DISMISSED: |
| 261 | 234 | if ( self::is_dismissed( $value ) ) { |
| 262 | 235 | return false; |
| 263 | 236 | } |
| 264 | - | |
| 265 | 237 | break; |
| 266 | - | |
| 267 | 238 | case self::CAPABILITY: |
| 268 | 239 | if ( ! current_user_can( $value ) ) { |
| 269 | 240 | return false; |
| 270 | 241 | } |
| 271 | - | |
| 272 | 242 | break; |
| 273 | - | |
| 274 | 243 | case self::DEFINED: |
| 275 | 244 | if ( defined( $value ) ) { |
| 276 | 245 | return false; |
| 277 | 246 | } |
| 278 | - | |
| 279 | 247 | break; |
| 280 | - | |
| 281 | - case self::NOT_DEFINED: | |
| 282 | - if ( ! defined( $value ) ) { | |
| 283 | - return false; | |
| 284 | - } | |
| 285 | - | |
| 286 | - break; | |
| 287 | - | |
| 288 | 248 | case self::PLUGIN_INSTALLED: |
| 289 | 249 | if ( ! self::is_plugin_installed( $value ) ) { |
| 290 | 250 | return false; |
| 291 | 251 | } |
| 292 | - | |
| 293 | 252 | break; |
| 294 | - | |
| 295 | 253 | case self::PLUGIN_ACTIVE: |
| 296 | 254 | if ( ! self::is_plugin_active( $value ) ) { |
| 297 | 255 | return false; |
| 298 | 256 | } |
| 299 | - | |
| 300 | 257 | break; |
| 301 | - | |
| 302 | - case self::NOT_HAS_OPTION: | |
| 303 | - $option = get_option( $value ); | |
| 304 | - if ( ! empty( $option ) ) { | |
| 305 | - return false; | |
| 306 | - } | |
| 307 | - | |
| 308 | - break; | |
| 309 | 258 | } |
| 310 | 259 | } |
| 311 | 260 | return true; |
| 312 | 261 | } |
| @@ -337,19 +286,14 @@ | ||
| 337 | 286 | return false; |
| 338 | 287 | } |
| 339 | 288 | |
| 340 | 289 | /** |
| 341 | - * Is_plugin_installed | |
| 342 | - * | |
| 290 | + * is_plugin_installed | |
| 343 | 291 | * @param $plugin |
| 344 | 292 | * |
| 345 | 293 | * @return bool |
| 346 | 294 | */ |
| 347 | - public static function is_plugin_installed( $plugin ): bool { | |
| 348 | - if ( ! function_exists( 'get_plugins' ) ) { | |
| 349 | - require_once ABSPATH . 'wp-admin/includes/plugin.php'; | |
| 350 | - } | |
| 351 | - | |
| 295 | + public static function is_plugin_installed( $plugin ) : bool { | |
| 352 | 296 | $plugins = get_plugins(); |
| 353 | 297 | $plugin = self::ensure_plugin_folder( $plugin ); |
| 354 | 298 | return ! empty( $plugins[ $plugin ] ); |
| 355 | 299 | } |
| @@ -354,26 +298,20 @@ | ||
| 354 | 298 | return ! empty( $plugins[ $plugin ] ); |
| 355 | 299 | } |
| 356 | 300 | |
| 357 | 301 | /** |
| 358 | - * Is_plugin_active | |
| 359 | - * | |
| 302 | + * is_plugin_active | |
| 360 | 303 | * @param $plugin |
| 361 | 304 | * |
| 362 | 305 | * @return bool |
| 363 | 306 | */ |
| 364 | 307 | public static function is_plugin_active( $plugin ): bool { |
| 365 | - if ( ! function_exists( 'is_plugin_active' ) ) { | |
| 366 | - require_once ABSPATH . 'wp-admin/includes/plugin.php'; | |
| 367 | - } | |
| 368 | - | |
| 369 | 308 | $plugin = self::ensure_plugin_folder( $plugin ); |
| 370 | 309 | return is_plugin_active( $plugin ); |
| 371 | 310 | } |
| 372 | 311 | |
| 373 | 312 | /** |
| 374 | - * Get_plugin_action_url | |
| 375 | - * | |
| 313 | + * get_plugin_action_url | |
| 376 | 314 | * @param $plugin |
| 377 | 315 | * |
| 378 | 316 | * @return string |
| 379 | 317 | */ |
| @@ -389,10 +327,9 @@ | ||
| 389 | 327 | return ''; |
| 390 | 328 | } |
| 391 | 329 | |
| 392 | 330 | /** |
| 393 | - * Ensure_plugin_folder | |
| 394 | - * | |
| 331 | + * ensure_plugin_folder | |
| 395 | 332 | * @param $plugin |
| 396 | 333 | * |
| 397 | 334 | * @return string |
| 398 | 335 | */ |
| @@ -403,10 +340,9 @@ | ||
| 403 | 340 | return $plugin; |
| 404 | 341 | } |
| 405 | 342 | |
| 406 | 343 | /** |
| 407 | - * Get_notice_allowed_html | |
| 408 | - * | |
| 344 | + * get_notice_allowed_html | |
| 409 | 345 | * @return array[] |
| 410 | 346 | */ |
| 411 | 347 | public static function get_notice_allowed_html(): array { |
| 412 | 348 | return [ |
| @@ -446,100 +382,6 @@ | ||
| 446 | 382 | 'style' => [], |
| 447 | 383 | 'target' => [], |
| 448 | 384 | ], |
| 449 | 385 | ]; |
| 450 | - } | |
| 451 | - | |
| 452 | - public static function is_plugin_connected( $option_prefix ): bool { | |
| 453 | - return ! empty( get_option( $option_prefix . '_access_token' ) ); | |
| 454 | - } | |
| 455 | - | |
| 456 | - public static function is_plugin_connected_to_one_subscription(): bool { | |
| 457 | - return self::is_plugin_connected( 'elementor_one' ); | |
| 458 | - } | |
| 459 | - | |
| 460 | - private static function get_all_widget_content( $step, $one_subscription = false ) { | |
| 461 | - if ( $one_subscription ) { | |
| 462 | - $steps = [ | |
| 463 | - self::INSTALL => esc_html__( 'Want to create an inclusive experience? Install Web Accessibility, included in ONE, and add an accessibility widget to your site.', 'elementor' ), | |
| 464 | - self::ACTIVATE => esc_html__( 'Your ONE subscription includes Web Accessibility. Activate it to place an accessibility widget on your site.', 'elementor' ), | |
| 465 | - self::CONNECT => esc_html__( "Connect the Web Accessibility plugin to your account to access all of it's accessibility features.", 'elementor' ), | |
| 466 | - self::CUSTOMIZE => esc_html__( "Customize the widget's look, position and the capabilities available for your visitors.", 'elementor' ), | |
| 467 | - ]; | |
| 468 | - } else { | |
| 469 | - $steps = [ | |
| 470 | - self::INSTALL => esc_html__( 'Install Web Accessibility to add an accessibility widget visitors can use to navigate your site.', 'elementor' ), | |
| 471 | - self::ACTIVATE => esc_html__( 'Activate the Web Accessibility plugin to turn its accessibility features on across your site.', 'elementor' ), | |
| 472 | - self::CONNECT => esc_html__( "Connect the Web Accessibility plugin to your account to access all of it's accessibility features.", 'elementor' ), | |
| 473 | - self::CUSTOMIZE => esc_html__( "Customize the widget's look, position and the capabilities available for your visitors.", 'elementor' ), | |
| 474 | - ]; | |
| 475 | - } | |
| 476 | - return $steps[ $step ]; | |
| 477 | - } | |
| 478 | - | |
| 479 | - private static function get_all_widget_action_button( $step ) { | |
| 480 | - $steps = [ | |
| 481 | - self::INSTALL => esc_html__( 'Install now', 'elementor' ), | |
| 482 | - self::ACTIVATE => esc_html__( 'Activate now', 'elementor' ), | |
| 483 | - self::CONNECT => esc_html__( 'Connect now', 'elementor' ), | |
| 484 | - self::CUSTOMIZE => esc_html__( 'Customize', 'elementor' ), | |
| 485 | - ]; | |
| 486 | - return $steps[ $step ]; | |
| 487 | - } | |
| 488 | - | |
| 489 | - private static function get_all_widget_action_url( $step, $one_subscription = false ) { | |
| 490 | - if ( in_array( $step, [ self::INSTALL, self::ACTIVATE ], true ) ) { | |
| 491 | - $action = ( self::INSTALL === $step ? 'install' : 'activate' ); | |
| 492 | - if ( $one_subscription ) { | |
| 493 | - $campaign_data = [ | |
| 494 | - 'name' => 'elementor_ea11y_campaign', | |
| 495 | - 'campaign' => 'acc-usability-widget-plg-ally-one-' . $action, | |
| 496 | - 'source' => 'editor-ally-widget-one-' . $action, | |
| 497 | - 'medium' => 'editor-one', | |
| 498 | - ]; | |
| 499 | - } else { | |
| 500 | - $campaign_data = [ | |
| 501 | - 'name' => 'elementor_ea11y_campaign', | |
| 502 | - 'campaign' => 'acc-usability-widget-plg-ally', | |
| 503 | - 'source' => 'editor-ally-widget', | |
| 504 | - 'medium' => 'editor', | |
| 505 | - ]; | |
| 506 | - } | |
| 507 | - return Admin_Notices::add_plg_campaign_data( self::get_plugin_action_url( 'pojo-accessibility' ), $campaign_data ); | |
| 508 | - } | |
| 509 | - return self::CONNECT === $step ? admin_url( 'admin.php?page=accessibility-settings' ) : admin_url( 'admin.php?page=accessibility-settings#design' ); | |
| 510 | - } | |
| 511 | - | |
| 512 | - private static function get_ally_cta_button( $step, $one_subscription = false ) { | |
| 513 | - return [ | |
| 514 | - 'text' => self::get_all_widget_action_button( $step ), | |
| 515 | - 'url' => self::get_all_widget_action_url( $step, $one_subscription ), | |
| 516 | - 'classes' => [ 'elementor-button' ], | |
| 517 | - ]; | |
| 518 | - } | |
| 519 | - | |
| 520 | - public static function get_ally_action_data(): array { | |
| 521 | - $plugin_slug = 'pojo-accessibility'; | |
| 522 | - $is_installed = self::is_plugin_installed( $plugin_slug ); | |
| 523 | - $is_active = self::is_plugin_active( $plugin_slug ); | |
| 524 | - $is_connected = self::is_plugin_connected( 'ea11y' ); | |
| 525 | - $one_subscription = self::is_plugin_connected_to_one_subscription(); | |
| 526 | - | |
| 527 | - if ( ! $is_installed ) { | |
| 528 | - $step = self::INSTALL; | |
| 529 | - } elseif ( ! $is_active ) { | |
| 530 | - $step = self::ACTIVATE; | |
| 531 | - } elseif ( ! $is_connected ) { | |
| 532 | - $step = self::CONNECT; | |
| 533 | - } else { | |
| 534 | - $step = self::CUSTOMIZE; | |
| 535 | - } | |
| 536 | - | |
| 537 | - $data = [ | |
| 538 | - 'title' => __( 'Web accessibility', 'elementor' ), | |
| 539 | - 'content' => self::get_all_widget_content( $step, $one_subscription ), | |
| 540 | - 'action_button' => self::get_ally_cta_button( $step, $one_subscription ), | |
| 541 | - ]; | |
| 542 | - | |
| 543 | - return $data; | |
| 544 | 386 | } |
| 545 | 387 | } |