PluginProbe
Image Optimization – Compress Images and Convert to WebP or AVIF / 1.6.6
Image Optimization – Compress Images and Convert to WebP or AVIF v1.6.6
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 / settings / components / settings-pointer.php

settings-pointer.php in Image Optimization – Compress Images and Convert to WebP or AVIF 1.6.6, at modules/settings/components/settings-pointer.php

94 lines 2.5 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\Settings\Components;
4
5 use ImageOptimization\Modules\Core\Components\Pointers;
6 use ImageOptimization\Modules\Settings\Module;
7
8 if ( ! defined( 'ABSPATH' ) ) {
9 exit; // Exit if accessed directly.
10 }
11
12 class Settings_Pointer {
13 const CURRENT_POINTER_SLUG = 'image-optimizer-settings';
14
15 public function admin_print_script() {
16
17 if ( ! current_user_can( 'manage_options' ) ) {
18 return;
19 }
20
21 if ( $this->is_dismissed() ) {
22 return;
23 }
24
25 wp_enqueue_script( 'wp-pointer' );
26 wp_enqueue_style( 'wp-pointer' );
27
28 $pointer_content = '<h3>' . esc_html__( 'Image Optimization settings', 'image-optimization' ) . '</h3>';
29 $pointer_content .= '<p>' . esc_html__( 'Head over to the Image Optimization Settings to fine-tune how your media uploads are managed.', 'image-optimization' ) . '</p>';
30
31 $pointer_content .= sprintf(
32 '<p><a class="button button-primary image-optimization-pointer-settings-link" href="%s">%s</a></p>',
33 admin_url( 'admin.php?page=' . Module::SETTING_BASE_SLUG ),
34 esc_html__( 'Take me there', 'image-optimization' )
35 );
36 $allowed_tags = [
37 'h3' => [],
38 'p' => [],
39 'a' => [
40 'class' => [],
41 'href' => [],
42 ],
43 ];
44 ?>
45 <script>
46 const onClose = () => {
47 return jQuery.ajax( {
48 url: ajaxurl,
49 method: 'POST',
50 data: {
51 action: 'image_optimizer_pointer_dismissed',
52 data: {
53 pointer: '<?php echo esc_attr( static::CURRENT_POINTER_SLUG ); ?>'
54 },
55 nonce: '<?php echo esc_attr( wp_create_nonce( 'image-optimization-pointer-dismissed' ) ); ?>'
56 }
57 } );
58 }
59
60 jQuery( document ).ready( function( $ ) {
61 $( '#menu-media' ).pointer( {
62 content: '<?php echo wp_kses( $pointer_content, $allowed_tags ); ?>',
63 position: {
64 edge: <?php echo is_rtl() ? "'right'" : "'left'"; ?>,
65 align: 'center'
66 },
67 close: onClose
68 } ).pointer( 'open' );
69
70 $( '.image-optimization-pointer-settings-link' ).first().on( 'click', function( e ) {
71 e.preventDefault();
72
73 $(this).attr( 'disabled', true );
74
75 onClose().promise().done(() => {
76 location = $(this).attr( 'href' );
77 });
78 })
79 } );
80 </script>
81 <?php
82 }
83
84 public function is_dismissed(): bool {
85 $meta = (array) get_user_meta( get_current_user_id(), Pointers::DISMISSED_POINTERS_META_KEY, true );
86
87 return key_exists( static::CURRENT_POINTER_SLUG, $meta );
88 }
89
90 public function __construct() {
91 add_action( 'in_admin_header', [ $this, 'admin_print_script' ] );
92 }
93 }
94