PluginProbe
Image Optimizer – Compress Images and Convert to WebP or AVIF / 1.7.7
Image Optimizer – Compress Images and Convert to WebP or AVIF v1.7.7
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 / core / components / not-connected.php

not-connected.php in Image Optimizer – Compress Images and Convert to WebP or AVIF 1.7.7, at modules/core/components/not-connected.php

128 lines 3.6 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 use ImageOptimization\Classes\Image\Image_Query_Builder;
6 use ImageOptimization\Classes\Utils;
7 use ImageOptimization\Plugin;
8
9 if ( ! defined( 'ABSPATH' ) ) {
10 exit; // Exit if accessed directly.
11 }
12
13 class Not_Connected {
14 const NOT_CONNECTED_NOTICE_SLUG = 'image-optimizer-not-connected';
15
16 public function render_not_connected_notice() {
17 if ( Pointers::is_dismissed( self::NOT_CONNECTED_NOTICE_SLUG ) ) {
18 return;
19 }
20
21 ?>
22 <div class="notice notice-info notice is-dismissible image-optimizer__notice image-optimizer__notice--pink"
23 data-notice-slug="<?php echo esc_attr( self::NOT_CONNECTED_NOTICE_SLUG ); ?>">
24 <div class="image-optimizer__icon-block">
25 <svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
26 <path d="M12 0C5.37 0 0 5.37 0 12C0 18.63 5.37 24 12 24C18.63 24 24 18.63 24 12C24 5.37 18.63 0 12 0ZM8.4 18H6V6H8.4V18ZM18 18H10.8V15.6H18V18ZM18 13.2H10.8V10.8H18V13.2ZM18 8.4H10.8V6H18V8.4Z" fill="#ED01EE"/>
27 </svg>
28 </div>
29
30 <p>
31 <b>
32 <?php esc_html_e(
33 'Image Optimization is not connected right now. To start optimizing your images, please connect your account.',
34 'image-optimization'
35 ); ?>
36 </b>
37
38 <span>
39 <a href="<?php echo esc_url( admin_url( 'admin.php?page=' . \ImageOptimization\Modules\Settings\Module::SETTING_BASE_SLUG . '&action=connect' ) ); ?>">
40 <?php esc_html_e(
41 'Connect now',
42 'image-optimization'
43 ); ?>
44 </a>
45 </span>
46 </p>
47 </div>
48
49 <script>
50 const onNotConnectedNoticeClose = () => {
51 const pointer = '<?php echo esc_js( self::NOT_CONNECTED_NOTICE_SLUG ); ?>';
52
53 return wp.ajax.post( 'image_optimizer_pointer_dismissed', {
54 data: {
55 pointer,
56 },
57 nonce: '<?php echo esc_js( wp_create_nonce( 'image-optimization-pointer-dismissed' ) ); ?>',
58 } );
59 }
60
61 jQuery( document ).ready( function( $ ) {
62 setTimeout(() => {
63 const $closeButton = $( '[data-notice-slug="<?php echo esc_js( self::NOT_CONNECTED_NOTICE_SLUG ); ?>"] .notice-dismiss' )
64
65 $closeButton
66 .first()
67 .on( 'click', onNotConnectedNoticeClose )
68
69 $( '[data-notice-slug="<?php echo esc_js( self::NOT_CONNECTED_NOTICE_SLUG ); ?>"] a' )
70 .first()
71 .on( 'click', function ( e ) {
72 e.preventDefault();
73
74 onNotConnectedNoticeClose().promise().done(() => {
75 window.open( $( this ).attr( 'href' ), '_self' ).focus();
76
77 $closeButton.click();
78 });
79 })
80 }, 0);
81 } );
82 </script>
83 <?php
84 }
85
86 public function add_media_menu_badge( $parent_file ) {
87 global $menu;
88
89 foreach ( $menu as &$item ) {
90 if ( 'upload.php' === $item[2] ) {
91 $item[0] .= ' <span class="update-plugins count-1"><span class="plugin-count">1</span></span>';
92 break;
93 }
94 }
95
96 return $parent_file;
97 }
98
99
100 public function __construct() {
101 add_action('current_screen', function () {
102 if ( ! Utils::user_is_admin() ) {
103 return;
104 }
105
106 // @var ImageOptimizer/Modules/ConnectManager/Module
107 $module = Plugin::instance()->modules_manager->get_modules( 'connect-manager' );
108
109 if ( $module->connect_instance->is_connected() || ! $module->connect_instance->is_valid_home_url() ) {
110 return;
111 }
112
113 add_filter( 'parent_file', [ $this, 'add_media_menu_badge' ] );
114
115 if (
116 Utils::is_media_page() ||
117 Utils::is_plugin_page() ||
118 Utils::is_single_attachment_page() ||
119 Utils::is_media_upload_page() ||
120 Utils::is_wp_dashboard_page() ||
121 Utils::is_wp_updates_page()
122 ) {
123 add_action( 'admin_notices', [ $this, 'render_not_connected_notice' ] );
124 }
125 });
126 }
127 }
128