PluginProbe
Image Optimization – Compress Images and Convert to WebP or AVIF / 1.1.0
Image Optimization – Compress Images and Convert to WebP or AVIF v1.1.0
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 1.6.6 All 32 releases
image-optimization / modules / optimization / components / list-view-pointer.php

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

71 lines 1.9 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
7 if ( ! defined( 'ABSPATH' ) ) {
8 exit; // Exit if accessed directly.
9 }
10
11 class List_View_Pointer {
12 const CURRENT_POINTER_SLUG = 'image-optimizer-list-view';
13
14 public function admin_print_script() {
15 if ( $this->is_dismissed() ) {
16 return;
17 }
18
19 wp_enqueue_script( 'wp-pointer' );
20 wp_enqueue_style( 'wp-pointer' );
21
22 $pointer_content = '<h3>' . esc_html__( 'Switch to list view', 'image-optimization' ) . '</h3>';
23 $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>';
24
25 $allowed_tags = [
26 'h3' => [],
27 'p' => [],
28 ];
29 ?>
30 <script>
31 jQuery( document ).ready( function( $ ) {
32 setTimeout(() => {
33 $( '#wp-media-grid div.media-toolbar.wp-filter' ).first().pointer( {
34 content: '<?php echo wp_kses( $pointer_content, $allowed_tags ); ?>',
35 pointerClass: 'image-optimization-list-view-pointer',
36 position: {
37 edge: 'top',
38 align: 'left'
39 },
40 close() {
41 wp.ajax.post( 'image_optimizer_pointer_dismissed', {
42 data: {
43 pointer: '<?php echo esc_attr( static::CURRENT_POINTER_SLUG ); ?>',
44 },
45 nonce: '<?php echo esc_attr( wp_create_nonce( 'image-optimization-pointer-dismissed' ) ); ?>',
46 } );
47 }
48 } ).pointer( 'open' );
49 }, 0)
50 } );
51 </script>
52
53 <style>
54 .image-optimization-list-view-pointer .wp-pointer-arrow {
55 left: 15px;
56 }
57 </style>
58 <?php
59 }
60
61 private function is_dismissed(): bool {
62 $meta = (array) get_user_meta( get_current_user_id(), Pointers::DISMISSED_POINTERS_META_KEY, true );
63
64 return key_exists( static::CURRENT_POINTER_SLUG, $meta );
65 }
66
67 public function __construct() {
68 add_action( 'in_admin_header', [ $this, 'admin_print_script' ] );
69 }
70 }
71