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 / core / components / pointers.php

pointers.php in Image Optimization – Compress Images and Convert to WebP or AVIF 1.1.0, at modules/core/components/pointers.php

40 lines 1.1 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\Core\Components;
4
5 if ( ! defined( 'ABSPATH' ) ) {
6 exit; // Exit if accessed directly.
7 }
8
9 class Pointers {
10 const DISMISSED_POINTERS_META_KEY = 'image_optimizer_dismissed_pointers';
11
12 public function dismiss_pointers() {
13 if ( empty( $_POST['nonce'] ) || ! wp_verify_nonce( sanitize_text_field( wp_unslash( $_POST['nonce'] ) ), 'image-optimization-pointer-dismissed' ) ) {
14 wp_send_json_error( [ 'message' => 'Invalid nonce' ] );
15 }
16
17 $pointer = sanitize_text_field( $_POST['data']['pointer'] ) ?? null;
18
19 if ( empty( $pointer ) ) {
20 wp_send_json_error( [ 'message' => 'The pointer id must be provided' ] );
21 }
22
23 $user_dismissed_meta = get_user_meta( get_current_user_id(), self::DISMISSED_POINTERS_META_KEY, true );
24
25 if ( ! $user_dismissed_meta ) {
26 $user_dismissed_meta = [];
27 }
28
29 $user_dismissed_meta[ $pointer ] = true;
30
31 update_user_meta( get_current_user_id(), self::DISMISSED_POINTERS_META_KEY, $user_dismissed_meta );
32
33 wp_send_json_success( [] );
34 }
35
36 public function __construct() {
37 add_action( 'wp_ajax_image_optimizer_pointer_dismissed', [ $this, 'dismiss_pointers' ] );
38 }
39 }
40