PluginProbe
Imagify Image Optimization: Optimize Images | Compress & Convert to WebP/AVIF / 1.4.2
Imagify Image Optimization: Optimize Images | Compress & Convert to WebP/AVIF v1.4.2
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.2, at inc/admin/enqueue.php

274 lines 10.2 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.min.js',
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
135 );
136 wp_localize_script( 'imagify-js-admin', 'imagify', $admin_data );
137 wp_enqueue_script( 'imagify-js-admin' );
138
139 /*
140 * Scripts loaded in /wp-admin/options-general.php?page=imagify
141 */
142 if ( isset( $current_screen ) && ( 'settings_page_imagify' === $current_screen->base || 'settings_page_imagify-network' === $current_screen->base ) ) {
143 wp_enqueue_script( 'imagify-js-chart' );
144 wp_enqueue_script( 'imagify-js-event-move' );
145 wp_enqueue_script( 'imagify-js-twentytwenty' );
146 wp_enqueue_script( 'imagify-js-options' );
147 wp_enqueue_style( 'imagify-css-twentytwenty' );
148
149 $options_data = array(
150 'noBackupTitle' => __( 'Don\'t Need a Parachute?', 'imagify' ),
151 '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' )
152 );
153
154 wp_localize_script( 'imagify-js-options', 'imagifyOptions', $options_data );
155 }
156
157 /**
158 * Scripts loaded in /wp-admin/upload.php and post.php
159 */
160 if ( isset( $current_screen ) && ( 'upload' === $current_screen->base || 'post' === $current_screen->base ) ) {
161 $upload_data = array(
162 'bulkActionsLabels' => array(
163 'optimize' => __( 'Optimize', 'imagify' ),
164 'restore' => __( 'Restore Original', 'imagify' ),
165 ),
166 );
167 wp_localize_script( 'imagify-js-upload', 'imagifyUpload', $upload_data );
168 wp_enqueue_script( 'imagify-js-chart' );
169 wp_enqueue_script( 'imagify-js-upload' );
170 }
171
172 /**
173 * Scripts loaded in /wp-admin/post.php (for attachment post type)
174 */
175 if ( isset( $current_screen ) && 'post' === $current_screen->base && 'attachment' === $current_screen->post_type ) {
176 wp_localize_script( 'imagify-js-twentytwenty', 'imagifyTTT', array(
177 'labels' => array(
178 'original_l' => esc_html__( 'Original Image', 'imagify' ),
179 'optimized_l' => esc_html__( 'Optimized Image', 'imagify' ),
180 'compare' => esc_html__( 'Compare Original VS Optimized', 'imagify' ),
181 'close' => esc_html__( 'Close', 'imagify' ),
182 'filesize' => esc_html__( 'File Size:', 'imagify' ),
183 'saving' => esc_html__( 'Original Saving:', 'imagify' ),
184 'optimize' => esc_html__( 'Optimize', 'imagify' )
185 )
186 ));
187 wp_enqueue_script( 'imagify-js-chart' );
188 wp_enqueue_script( 'imagify-js-event-move' );
189 wp_enqueue_script( 'imagify-js-twentytwenty' );
190 wp_enqueue_style( 'imagify-css-twentytwenty' );
191 }
192
193 /**
194 * Scripts loaded in /wp-admin/upload.php?page=imagify-bulk-optimization
195 */
196 if ( isset( $current_screen ) && 'media_page_imagify-bulk-optimization' === $current_screen->base ) {
197 $user = get_imagify_user();
198 $bulk_data = array(
199 'waitTitle' => __( 'Please wait...', 'imagify' ),
200 'waitText' => __( 'We are trying to get your unoptimized images, it may take time depending on the number of images.', 'imagify' ),
201 'waitImageUrl' => IMAGIFY_ASSETS_IMG_URL . 'popin-loader.svg',
202 'getUnoptimizedImagesErrorTitle' => __( 'Oops, There is something wrong!', 'imagify' ),
203 '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' ),
204 'overviewChartLabels' => array(
205 'optimized' => __( 'Optimized', 'imagify' ),
206 'unoptimized' => __( 'Unoptimized', 'imagify' ),
207 'error' => __( 'Error', 'imagify' ),
208 ),
209 'overQuotaTitle' => __( 'Oops, It\'s Over!', 'imagify' ),
210 'noAttachmentToOptimizeTitle' => __( 'Hold on!', 'imagify' ),
211 'noAttachmentToOptimizeText' => __( 'All your images have been optimized by Imagify. Congratulations!', 'imagify' ),
212 'pluginURL' => 'https://wordpress.org/plugins/imagify',
213 'textToShare' => __( 'Discover @imagify, the new compression tool to optimize your images for free. I saved %1$s out of %2$s!', 'imagify' ),
214 'totalOptimizedAttachments' => imagify_count_optimized_attachments(),
215 'totalUnoptimizedAttachments' => imagify_count_unoptimized_attachments(),
216 'totalErrorsAttachments' => imagify_count_error_attachments(),
217 'processing' => __( 'Imagify is still processing. Are you sure you want to leave this page?', 'imagify' ),
218 );
219
220 if ( imagify_valid_key() ) {
221 if ( is_wp_error( $user ) ) {
222 $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>' );
223 }
224 else {
225 $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>' );
226 }
227 }
228
229 wp_localize_script( 'imagify-js-bulk', 'imagifyBulk', $bulk_data );
230 wp_enqueue_script( 'imagify-js-chart' );
231 wp_enqueue_script( 'imagify-js-async' );
232 wp_enqueue_script( 'imagify-js-bulk' );
233 }
234 }
235
236 /**
237 * Add Intercom on Options page an Bulk Optimization
238 *
239 * @since 1.0
240 */
241 add_action( 'admin_footer-media_page_imagify-bulk-optimization', '_imagify_admin_print_intercom' );
242 add_action( 'admin_footer-settings_page_imagify', '_imagify_admin_print_intercom' );
243 function _imagify_admin_print_intercom() {
244 $user = get_imagify_user();
245
246 if ( ! imagify_valid_key() || empty( $user->is_intercom ) ) {
247 return;
248 }
249 ?>
250 <script>
251 window.intercomSettings = {
252 app_id: "cd6nxj3z",
253 user_id: <?php echo (int) $user->id; ?>,
254 };
255 </script>
256 <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>
257 <?php
258 }
259
260 /**
261 * Remove Yoast SEO bugged script
262 *
263 * @since 1.4.1
264 */
265 add_action( 'wp_print_scripts', '_imagify_dequeue_yoastseo_script' );
266 function _imagify_dequeue_yoastseo_script() {
267 global $pagenow;
268 $current_screen = get_current_screen();
269
270 if ( isset( $current_screen ) && 'post' === $current_screen->base && 'attachment' === $current_screen->post_type ) {
271 wp_dequeue_script( 'yoast-seo' );
272 wp_deregister_script( 'yoast-seo' );
273 }
274 }