PluginProbe
Image Optimizer – Compress Images and Convert to WebP or AVIF / 1.7.4
Image Optimizer – Compress Images and Convert to WebP or AVIF v1.7.4
1.7.7 1.7.6 1.7.5 1.7.4 trunk 1.0.0 1.0.1 1.0.2 1.1.0 1.2.0 1.2.1 1.3.0 1.4.0 1.4.1 1.5.0 1.5.1 1.5.2 1.5.3 1.5.4 1.6.0 1.6.1 1.6.2 1.6.3 1.6.4 1.6.5 All 33 releases
image-optimization / modules / optimization / components / list-view-pointer.php

list-view-pointer.php in Image Optimizer – Compress Images and Convert to WebP or AVIF 1.7.4, at modules/optimization/components/list-view-pointer.php

81 lines 2.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace ImageOptimization\Modules\Optimization\Components;
4
5 use ImageOptimization\Modules\Core\Components\Pointers;
6 use ImageOptimization\Modules\Core\Module as Core_Module;
7
8 if ( ! defined( 'ABSPATH' ) ) {
9 exit; // Exit if accessed directly.
10 }
11
12 class List_View_Pointer {
13 const CURRENT_POINTER_SLUG = 'image-optimizer-list-view';
14
15 public function admin_print_script() {
16 if ( Core_Module::is_elementor_one() ) {
17 return;
18 }
19
20 if ( $this->is_dismissed() ) {
21 return;
22 }
23
24 wp_enqueue_script( 'wp-pointer' );
25 wp_enqueue_style( 'wp-pointer' );
26
27 $pointer_content = '<h3>' . esc_html__( 'Switch to list view', 'image-optimization' ) . '</h3>';
28 $pointer_content .= '<p>' . esc_html__( 'Get the most out of your optimizing options. Use the List view to quickly optimize your uploaded images with Image Optimizer.', 'image-optimization' ) . '</p>';
29
30 $allowed_tags = [
31 'h3' => [],
32 'p' => [],
33 ];
34 ?>
35 <script>
36 jQuery( document ).ready( function( $ ) {
37 setTimeout(() => {
38 $( '#wp-media-grid div.media-toolbar.wp-filter' ).first().pointer( {
39 content: '<?php echo wp_kses( $pointer_content, $allowed_tags ); ?>',
40 pointerClass: 'image-optimization-list-view-pointer',
41 position: {
42 edge: 'top',
43 align: '<?php echo is_rtl() ? 'right' : 'left'; ?>',
44 },
45 close() {
46 return jQuery.ajax( {
47 url: ajaxurl,
48 method: 'POST',
49 data: {
50 action: 'image_optimizer_pointer_dismissed',
51 data: {
52 pointer: '<?php echo esc_attr( static::CURRENT_POINTER_SLUG ); ?>'
53 },
54 nonce: '<?php echo esc_attr( wp_create_nonce( 'image-optimization-pointer-dismissed' ) ); ?>'
55 }
56 } );
57 }
58 } ).pointer( 'open' );
59 }, 0)
60 } );
61 </script>
62
63 <style>
64 .image-optimization-list-view-pointer .wp-pointer-arrow {
65 inset-inline-start: 15px;
66 }
67 </style>
68 <?php
69 }
70
71 private function is_dismissed(): bool {
72 $meta = (array) get_user_meta( get_current_user_id(), Pointers::DISMISSED_POINTERS_META_KEY, true );
73
74 return key_exists( static::CURRENT_POINTER_SLUG, $meta );
75 }
76
77 public function __construct() {
78 add_action( 'in_admin_header', [ $this, 'admin_print_script' ] );
79 }
80 }
81