PluginProbe
Imagify Image Optimization: Optimize Images | Compress & Convert to WebP/AVIF / 1.4.6
Imagify Image Optimization: Optimize Images | Compress & Convert to WebP/AVIF v1.4.6
2.3.4 2.3.3 2.3.2 2.3.1 2.3.0 2.2.9 2.2.8 trunk 1.10 1.3.3 1.3.4 1.3.5 1.3.5.1 1.3.5.2 1.3.6 1.3.6.1 1.4 1.4.1 1.4.2 1.4.3 1.4.4 1.4.5 1.4.6 1.4.7 1.5 All 103 releases
imagify / inc / admin / enqueue.php

enqueue.php in Imagify Image Optimization: Optimize Images | Compress & Convert to WebP/AVIF 1.4.6, at inc/admin/enqueue.php

280 lines 10.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 defined( 'ABSPATH' ) or die( 'Cheatin\' uh?' );
3
4 /**
5 * Add some CSS on the whole administration
6 *
7 * @since 1.0
8 */
9 add_action( 'admin_print_styles', '_imagify_admin_print_styles' );
10 function _imagify_admin_print_styles() {
11 global $pagenow;
12 $current_screen = get_current_screen();
13 $css_ext = ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? '.css' : '.min.css';
14 $js_ext = ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? '.js' : '.min.js';
15
16 wp_register_style(
17 'imagify-css-admin',
18 IMAGIFY_ASSETS_CSS_URL . 'admin' . $css_ext,
19 array(),
20 IMAGIFY_VERSION
21 );
22
23 wp_register_style(
24 'imagify-css-sweetalert',
25 IMAGIFY_ASSETS_CSS_URL . 'sweetalert' . $css_ext,
26 array(),
27 IMAGIFY_VERSION
28 );
29
30 wp_register_style(
31 'imagify-css-twentytwenty',
32 IMAGIFY_ASSETS_CSS_URL . 'twentytwenty' . $css_ext,
33 array(),
34 IMAGIFY_VERSION
35 );
36
37 wp_register_script(
38 'imagify-js-async',
39 IMAGIFY_ASSETS_JS_URL . 'imagify.min.js',
40 array(),
41 IMAGIFY_VERSION,
42 true
43 );
44
45 wp_register_script(
46 'imagify-js-admin',
47 IMAGIFY_ASSETS_JS_URL . 'admin' . $js_ext,
48 array(),
49 IMAGIFY_VERSION,
50 true
51 );
52
53 wp_register_script(
54 'imagify-js-options',
55 IMAGIFY_ASSETS_JS_URL . 'options' . $js_ext,
56 array(),
57 IMAGIFY_VERSION,
58 true
59 );
60
61 wp_register_script(
62 'imagify-js-upload',
63 IMAGIFY_ASSETS_JS_URL . 'upload' . $js_ext,
64 array( 'jquery' ),
65 IMAGIFY_VERSION,
66 true
67 );
68
69 wp_register_script(
70 'imagify-js-sweetalert',
71 IMAGIFY_ASSETS_JS_URL . 'sweetalert.min.js',
72 array( 'jquery' ),
73 IMAGIFY_VERSION,
74 true
75 );
76
77 wp_register_script(
78 'imagify-js-chart',
79 IMAGIFY_ASSETS_JS_URL . 'chart' . $js_ext,
80 array(),
81 IMAGIFY_VERSION,
82 true
83 );
84
85 wp_register_script(
86 'imagify-js-bulk',
87 IMAGIFY_ASSETS_JS_URL . 'bulk' . $js_ext,
88 array( 'jquery', 'imagify-js-chart' ),
89 IMAGIFY_VERSION,
90 true
91 );
92
93 wp_register_script(
94 'imagify-js-twentytwenty',
95 IMAGIFY_ASSETS_JS_URL . 'jquery.twentytwenty' . $js_ext,
96 array( 'jquery', 'imagify-js-event-move', 'imagify-js-chart' ),
97 IMAGIFY_VERSION,
98 true
99 );
100 wp_register_script(
101 'imagify-js-event-move',
102 IMAGIFY_ASSETS_JS_URL . 'jquery.event.move' . $js_ext,
103 array( 'jquery' ),
104 IMAGIFY_VERSION,
105 true
106 );
107
108 /*
109 * Styles loaded in the whole admnistration
110 */
111 wp_enqueue_style( 'imagify-css-admin' );
112 wp_enqueue_style( 'imagify-css-sweetalert' );
113
114 /*
115 * Scripts loaded in the whole admnistration
116 */
117 wp_enqueue_script( 'imagify-js-sweetalert' );
118 wp_enqueue_script( 'imagify-js-admin' );
119
120 $admin_data = array(
121 'signupTitle' => __( 'Let\'s get you started!', 'imagify' ),
122 'signupText' => __( 'Enter your email to get an API key:', 'imagify' ),
123 'signupConfirmButtonText' => __( 'Sign Up', 'imagify' ),
124 'signupErrorEmptyEmail' => __( 'You need to specify an email!', 'imagify' ),
125 'signupSuccessTitle' => __( 'Congratulations!', 'imagify' ),
126 'signupSuccessText' => __( 'Your account has been succesfully created. Please check your mailbox, you are going to receive an email with API key.', 'imagify' ),
127 'saveApiKeyTitle' => __( 'Connect to Imagify!', 'imagify' ),
128 'saveApiKeyText' => __( 'Paste your API key below:', 'imagify' ),
129 'saveApiKeyConfirmButtonText' => __( 'Connect me', 'imagify' ),
130 'waitApiKeyCheckText' => __( 'Check in progress...', 'imagify' ),
131 'ApiKeyCheckSuccessTitle' => __( 'Congratulations!', 'imagify' ),
132 'ApiKeyCheckSuccessText' => __( 'Your API key is valid. You can now configure the Imagify settings to optimize your images.', 'imagify' ),
133 'ValidApiKeyText' => __( 'Your API key is valid.', 'imagify' ),
134 'swalCancel' => __( 'Cancel' )
135
136 );
137 wp_localize_script( 'imagify-js-admin', 'imagify', $admin_data );
138 wp_enqueue_script( 'imagify-js-admin' );
139
140 /*
141 * Scripts loaded in /wp-admin/options-general.php?page=imagify
142 */
143 if ( isset( $current_screen ) && ( 'settings_page_imagify' === $current_screen->base || 'settings_page_imagify-network' === $current_screen->base ) ) {
144 wp_enqueue_script( 'imagify-js-chart' );
145 wp_enqueue_script( 'imagify-js-event-move' );
146 wp_enqueue_script( 'imagify-js-twentytwenty' );
147 wp_enqueue_script( 'imagify-js-options' );
148 wp_enqueue_style( 'imagify-css-twentytwenty' );
149
150 $options_data = array(
151 'noBackupTitle' => __( 'Don\'t Need a Parachute?', 'imagify' ),
152 'noBackupText' => __( 'If you keep this option deactivated, you won\'t be able to re-optimize your images to another compression level and restore your original images in case of need.', 'imagify' )
153 );
154
155 wp_localize_script( 'imagify-js-options', 'imagifyOptions', $options_data );
156 }
157
158 /**
159 * Scripts loaded in /wp-admin/upload.php and post.php
160 */
161 if ( isset( $current_screen ) && ( 'upload' === $current_screen->base || 'post' === $current_screen->base ) ) {
162 $upload_data = array(
163 'bulkActionsLabels' => array(
164 'optimize' => __( 'Optimize', 'imagify' ),
165 'restore' => __( 'Restore Original', 'imagify' ),
166 ),
167 );
168 wp_localize_script( 'imagify-js-upload', 'imagifyUpload', $upload_data );
169 wp_enqueue_script( 'imagify-js-chart' );
170 wp_enqueue_script( 'imagify-js-upload' );
171 }
172
173 /**
174 * Scripts loaded in:
175 * /wp-admin/post.php (for attachment post type)
176 * /wp-admin/upload.php (for attachments list)
177 *
178 */
179 if ( isset( $current_screen ) && ( ('post' === $current_screen -> base && 'attachment' === $current_screen -> post_type ) || 'upload' === $current_screen -> base ) ) {
180 wp_localize_script( 'imagify-js-twentytwenty', 'imagifyTTT', array(
181 'labels' => array(
182 'original_l' => esc_html__( 'Original Image', 'imagify' ),
183 'optimized_l' => esc_html__( 'Optimized Image', 'imagify' ),
184 'compare' => esc_html__( 'Compare Original VS Optimized', 'imagify' ),
185 'close' => esc_html__( 'Close', 'imagify' ),
186 'filesize' => esc_html__( 'File Size:', 'imagify' ),
187 'saving' => esc_html__( 'Original Saving:', 'imagify' ),
188 'optimize' => esc_html__( 'Optimize', 'imagify' )
189 )
190 ));
191 wp_enqueue_script( 'imagify-js-chart' );
192 wp_enqueue_script( 'imagify-js-event-move' );
193 wp_enqueue_script( 'imagify-js-twentytwenty' );
194 wp_enqueue_style( 'imagify-css-twentytwenty' );
195 }
196
197 /**
198 * Scripts loaded in /wp-admin/upload.php?page=imagify-bulk-optimization
199 */
200 if ( isset( $current_screen ) && 'media_page_imagify-bulk-optimization' === $current_screen->base ) {
201 wp_enqueue_script( 'heartbeat' );
202
203 $user = get_imagify_user();
204 $bulk_data = array(
205 'waitTitle' => __( 'Please wait...', 'imagify' ),
206 'waitText' => __( 'We are trying to get your unoptimized images, it may take time depending on the number of images.', 'imagify' ),
207 'waitImageUrl' => IMAGIFY_ASSETS_IMG_URL . 'popin-loader.svg',
208 'getUnoptimizedImagesErrorTitle' => __( 'Oops, There is something wrong!', 'imagify' ),
209 'getUnoptimizedImagesErrorText' => __( 'An unknow error occurred when we tried to get all your unoptimized images. Try again and if the issue still persist, please contact us!', 'imagify' ),
210 'overviewChartLabels' => array(
211 'optimized' => __( 'Optimized', 'imagify' ),
212 'unoptimized' => __( 'Unoptimized', 'imagify' ),
213 'error' => __( 'Error', 'imagify' ),
214 ),
215 'overQuotaTitle' => __( 'Oops, It\'s Over!', 'imagify' ),
216 'noAttachmentToOptimizeTitle' => __( 'Hold on!', 'imagify' ),
217 'noAttachmentToOptimizeText' => __( 'All your images have been optimized by Imagify. Congratulations!', 'imagify' ),
218 'pluginURL' => 'https://wordpress.org/plugins/imagify',
219 'textToShare' => __( 'Discover @imagify, the new compression tool to optimize your images for free. I saved %1$s out of %2$s!', 'imagify' ),
220 'totalOptimizedAttachments' => imagify_count_optimized_attachments(),
221 'totalUnoptimizedAttachments' => imagify_count_unoptimized_attachments(),
222 'totalErrorsAttachments' => imagify_count_error_attachments(),
223 'processing' => __( 'Imagify is still processing. Are you sure you want to leave this page?', 'imagify' ),
224 );
225
226 if ( imagify_valid_key() ) {
227 if ( is_wp_error( $user ) ) {
228 $bulk_data['overQuotaText'] = sprintf( __( 'To continue to optimize your images, log in to your Imagify account to %sbuy a pack or subscribe to a plan%s.', 'imagify' ), '<a href="' . IMAGIFY_APP_MAIN . '/#/subscription' . '">', '</a>' );
229 }
230 else {
231 $bulk_data['overQuotaText'] = sprintf( __( 'You have consumed all your credit for this month. You will have <strong>%s back on %s</strong>.', 'imagify' ), size_format( $user->quota * 1048576 ), date_i18n( __( 'F j, Y' ), strtotime( $user->next_date_update ) ) ) . '<br/><br/>' . sprintf( __( 'To continue to optimize your images, log in to your Imagify account to %sbuy a pack or subscribe to a plan%s.', 'imagify' ), '<a href="' . IMAGIFY_APP_MAIN . '/#/subscription' . '">', '</a>' );
232 }
233 }
234
235 wp_localize_script( 'imagify-js-bulk', 'imagifyBulk', $bulk_data );
236 wp_enqueue_script( 'imagify-js-chart' );
237 wp_enqueue_script( 'imagify-js-async' );
238 wp_enqueue_script( 'imagify-js-bulk' );
239 }
240 }
241
242 /**
243 * Add Intercom on Options page an Bulk Optimization
244 *
245 * @since 1.0
246 */
247 add_action( 'admin_footer-media_page_imagify-bulk-optimization', '_imagify_admin_print_intercom' );
248 add_action( 'admin_footer-settings_page_imagify', '_imagify_admin_print_intercom' );
249 function _imagify_admin_print_intercom() {
250 $user = get_imagify_user();
251
252 if ( ! imagify_valid_key() || empty( $user->is_intercom ) ) {
253 return;
254 }
255 ?>
256 <script>
257 window.intercomSettings = {
258 app_id: "cd6nxj3z",
259 user_id: <?php echo (int) $user->id; ?>,
260 };
261 </script>
262 <script>(function(){var w=window;var ic=w.Intercom;if(typeof ic==="function"){ic('reattach_activator');ic('update',intercomSettings);}else{var d=document;var i=function(){i.c(arguments)};i.q=[];i.c=function(args){i.q.push(args)};w.Intercom=i;function l(){var s=d.createElement('script');s.type='text/javascript';s.async=true;s.src='https://widget.intercom.io/widget/cd6nxj3z';var x=d.getElementsByTagName('script')[0];x.parentNode.insertBefore(s,x);}if(w.attachEvent){w.attachEvent('onload',l);}else{w.addEventListener('load',l,false);}}})()</script>
263 <?php
264 }
265
266 /**
267 * Remove Yoast SEO bugged script
268 *
269 * @since 1.4.1
270 */
271 add_action( 'wp_print_scripts', '_imagify_dequeue_yoastseo_script' );
272 function _imagify_dequeue_yoastseo_script() {
273 global $pagenow;
274 $current_screen = get_current_screen();
275
276 if ( isset( $current_screen ) && 'post' === $current_screen->base && 'attachment' === $current_screen->post_type ) {
277 wp_dequeue_script( 'yoast-seo' );
278 wp_deregister_script( 'yoast-seo' );
279 }
280 }