| 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: '<?php echo is_rtl() ? 'right' : 'left'; ?>', |
| 39 |
}, |
| 40 |
close() { |
| 41 |
return jQuery.ajax( { |
| 42 |
url: ajaxurl, |
| 43 |
method: 'POST', |
| 44 |
data: { |
| 45 |
action: 'image_optimizer_pointer_dismissed', |
| 46 |
data: { |
| 47 |
pointer: '<?php echo esc_attr( static::CURRENT_POINTER_SLUG ); ?>' |
| 48 |
}, |
| 49 |
nonce: '<?php echo esc_attr( wp_create_nonce( 'image-optimization-pointer-dismissed' ) ); ?>' |
| 50 |
} |
| 51 |
} ); |
| 52 |
} |
| 53 |
} ).pointer( 'open' ); |
| 54 |
}, 0) |
| 55 |
} ); |
| 56 |
</script> |
| 57 |
|
| 58 |
<style> |
| 59 |
.image-optimization-list-view-pointer .wp-pointer-arrow { |
| 60 |
inset-inline-start: 15px; |
| 61 |
} |
| 62 |
</style> |
| 63 |
<?php |
| 64 |
} |
| 65 |
|
| 66 |
private function is_dismissed(): bool { |
| 67 |
$meta = (array) get_user_meta( get_current_user_id(), Pointers::DISMISSED_POINTERS_META_KEY, true ); |
| 68 |
|
| 69 |
return key_exists( static::CURRENT_POINTER_SLUG, $meta ); |
| 70 |
} |
| 71 |
|
| 72 |
public function __construct() { |
| 73 |
add_action( 'in_admin_header', [ $this, 'admin_print_script' ] ); |
| 74 |
} |
| 75 |
} |
| 76 |
|