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

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

129 lines 3.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\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="32" height="32" fill="none" role="presentation">
26 <rect width="32" height="32" fill="#FF7BE5" rx="16"/>
27 <path fill="#fff" d="M10.508 4.135a.125.125 0 0 0-.236 0l-1.183 3.42a.125.125 0 0 1-.078.078L5.553 8.8a.125.125 0 0 0 0 .237l3.458 1.166a.125.125 0 0 1 .078.078l1.183 3.42a.125.125 0 0 0 .236 0l1.182-3.42a.125.125 0 0 1 .078-.078l3.458-1.166a.125.125 0 0 0 0-.237l-3.458-1.167a.125.125 0 0 1-.078-.077l-1.182-3.421ZM17.425 12.738v3.683l-4.073 4.582L26.495 9.598a.125.125 0 0 1 .207.094v14.851a.125.125 0 0 1-.125.125H5.874a.125.125 0 0 1-.09-.212l11.427-11.805a.125.125 0 0 1 .214.087Z"/>
28 </svg>
29 </div>
30
31 <p>
32 <b>
33 <?php esc_html_e(
34 'Image Optimizer is not connected right now. To start optimizing your images, please connect your account.',
35 'image-optimization'
36 ); ?>
37 </b>
38
39 <span>
40 <a href="<?php echo admin_url( 'admin.php?page=' . \ImageOptimization\Modules\Settings\Module::SETTING_BASE_SLUG . '&action=connect' ); ?>">
41 <?php esc_html_e(
42 'Connect now',
43 'image-optimization'
44 ); ?>
45 </a>
46 </span>
47 </p>
48 </div>
49
50 <script>
51 const onNotConnectedNoticeClose = () => {
52 const pointer = '<?php echo esc_js( self::NOT_CONNECTED_NOTICE_SLUG ); ?>';
53
54 return wp.ajax.post( 'image_optimizer_pointer_dismissed', {
55 data: {
56 pointer,
57 },
58 nonce: '<?php echo esc_js( wp_create_nonce( 'image-optimization-pointer-dismissed' ) ); ?>',
59 } );
60 }
61
62 jQuery( document ).ready( function( $ ) {
63 setTimeout(() => {
64 const $closeButton = $( '[data-notice-slug="<?php echo esc_js( self::NOT_CONNECTED_NOTICE_SLUG ); ?>"] .notice-dismiss' )
65
66 $closeButton
67 .first()
68 .on( 'click', onNotConnectedNoticeClose )
69
70 $( '[data-notice-slug="<?php echo esc_js( self::NOT_CONNECTED_NOTICE_SLUG ); ?>"] a' )
71 .first()
72 .on( 'click', function ( e ) {
73 e.preventDefault();
74
75 onNotConnectedNoticeClose().promise().done(() => {
76 window.open( $( this ).attr( 'href' ), '_blank' ).focus();
77
78 $closeButton.click();
79 });
80 })
81 }, 0);
82 } );
83 </script>
84 <?php
85 }
86
87 public function add_media_menu_badge( $parent_file ) {
88 global $menu;
89
90 foreach ( $menu as &$item ) {
91 if ( 'upload.php' === $item[2] ) {
92 $item[0] .= ' <span class="update-plugins count-1"><span class="plugin-count">1</span></span>';
93 break;
94 }
95 }
96
97 return $parent_file;
98 }
99
100
101 public function __construct() {
102 add_action('current_screen', function () {
103 if ( ! Utils::user_is_admin() ) {
104 return;
105 }
106
107 // @var ImageOptimizer/Modules/ConnectManager/Module
108 $module = Plugin::instance()->modules_manager->get_modules( 'connect-manager' );
109
110 if ( $module->connect_instance->is_connected() || ! $module->connect_instance->is_valid_home_url() ) {
111 return;
112 }
113
114 add_filter( 'parent_file', [ $this, 'add_media_menu_badge' ] );
115
116 if (
117 Utils::is_media_page() ||
118 Utils::is_plugin_page() ||
119 Utils::is_single_attachment_page() ||
120 Utils::is_media_upload_page() ||
121 Utils::is_wp_dashboard_page() ||
122 Utils::is_wp_updates_page()
123 ) {
124 add_action( 'admin_notices', [ $this, 'render_not_connected_notice' ] );
125 }
126 });
127 }
128 }
129