| @@ -12,8 +12,9 @@ | ||
| 12 | 12 | use Elementor\Plugin; |
| 13 | 13 | use Elementor\Settings; |
| 14 | 14 | use Elementor\User; |
| 15 | 15 | use Elementor\Utils; |
| 16 | +use Elementor\Core\Utils\Hints; | |
| 16 | 17 | |
| 17 | 18 | if ( ! defined( 'ABSPATH' ) ) { |
| 18 | 19 | exit; // Exit if accessed directly. |
| 19 | 20 | } |
| @@ -149,8 +150,10 @@ | ||
| 149 | 150 | wp_enqueue_script( 'elementor-admin' ); |
| 150 | 151 | |
| 151 | 152 | wp_set_script_translations( 'elementor-admin', 'elementor' ); |
| 152 | 153 | |
| 154 | + $this->maybe_enqueue_hints(); | |
| 155 | + | |
| 153 | 156 | $this->print_config(); |
| 154 | 157 | } |
| 155 | 158 | |
| 156 | 159 | /** |
| @@ -944,6 +947,55 @@ | ||
| 944 | 947 | } |
| 945 | 948 | |
| 946 | 949 | private function register_menu() { |
| 947 | 950 | $this->menus['main'] = new MainMenu(); |
| 951 | + } | |
| 952 | + | |
| 953 | + private function maybe_enqueue_hints() { | |
| 954 | + if ( ! Hints::should_display_hint( 'image-optimization-once-media-modal' ) && ! Hints::should_display_hint( 'image-optimization-media-modal' ) ) { | |
| 955 | + return; | |
| 956 | + } | |
| 957 | + | |
| 958 | + wp_register_script( | |
| 959 | + 'media-hints', | |
| 960 | + $this->get_js_assets_url( 'media-hints' ), | |
| 961 | + [], | |
| 962 | + ELEMENTOR_VERSION, | |
| 963 | + true | |
| 964 | + ); | |
| 965 | + | |
| 966 | + $once_dismissed = Hints::is_dismissed( 'image-optimization-once-media-modal' ); | |
| 967 | + $content = $once_dismissed ? | |
| 968 | + sprintf("%1\$s <a href='%2\$s' class='e-btn-1' target='_blank'>%3\$s</a> %4\$s", | |
| 969 | + __( 'This image is large and may slow things down.', 'elementor' ), | |
| 970 | + Hints::get_plugin_action_url( 'image-optimization' ), | |
| 971 | + ( Hints::is_plugin_installed( 'image-optimization' ) ? __( 'Activate', 'elementor' ) : __( 'Install', 'elementor' ) ) . ' ' . __( 'Image Optimizer', 'elementor' ), | |
| 972 | + __( 'to reduce size without losing quality.', 'elementor' ) | |
| 973 | + ) : | |
| 974 | + sprintf("%1\$s <a class='e-btn-1' href='%2\$s' target='_blank'>%3\$s</a>!", | |
| 975 | + __( 'Don’t let unoptimized images be the downfall of your site’s performance.', 'elementor' ), | |
| 976 | + Hints::get_plugin_action_url( 'image-optimization' ), | |
| 977 | + ( Hints::is_plugin_installed( 'image-optimization' ) ? __( 'Activate', 'elementor' ) : __( 'Install', 'elementor' ) ) . ' ' . __( 'Image Optimizer', 'elementor' ) | |
| 978 | + ); | |
| 979 | + | |
| 980 | + $dismissible = $once_dismissed ? 'image-optimization-media-modal' : 'image-optimization-once-media-modal'; | |
| 981 | + | |
| 982 | + wp_localize_script( 'media-hints', 'elementorAdminHints', [ | |
| 983 | + 'mediaHint' => [ | |
| 984 | + 'display' => ! $once_dismissed, | |
| 985 | + 'type' => $once_dismissed ? 'warning' : 'info', | |
| 986 | + 'content' => $content, | |
| 987 | + 'icon' => true, | |
| 988 | + 'dismissible' => $dismissible, | |
| 989 | + 'dismiss' => __( 'Dismiss this notice.', 'elementor' ), | |
| 990 | + 'button_event' => $dismissible, | |
| 991 | + 'button_data' => base64_encode( | |
| 992 | + json_encode( [ | |
| 993 | + 'action_url' => Hints::get_plugin_action_url( 'image-optimization' ), | |
| 994 | + ] ), | |
| 995 | + ), | |
| 996 | + ], | |
| 997 | + ] ); | |
| 998 | + | |
| 999 | + wp_enqueue_script( 'media-hints' ); | |
| 948 | 1000 | } |
| 949 | 1001 | } |