PluginProbe ʕ •ᴥ•ʔ
Smush – Image Optimization, Compression, Lazy Load, WebP & CDN / 3.14.1
Smush – Image Optimization, Compression, Lazy Load, WebP & CDN v3.14.1
4.1.0 4.0.3 4.0.2 2.8.1 2.9.1 3.0.0 3.0.1 3.0.2 3.1.1 3.10.1 3.10.2 3.10.3 3.11.1 3.12.3 3.12.4 3.12.5 3.12.6 3.13.0 3.13.1 3.13.2 3.14.0 3.14.1 3.14.2 3.15.0 3.15.1 3.15.2 3.15.3 3.15.4 3.15.5 3.16.2 3.16.4 3.16.5 3.16.6 3.17.0 3.17.1 3.18.0 3.18.1 3.2.0.1 3.2.1 3.2.2.1 3.2.4 3.20.0 3.21.1 3.22.1 3.22.3 3.23.0 3.23.1 3.23.2 3.23.3 3.23.4 3.24.0 3.24.0-beta.2 3.3.0 3.3.1 3.3.2 3.4.1 3.4.2 3.6.1 3.6.3 3.7.0 3.7.1 3.7.2 3.7.3 3.8.2 3.8.3 3.8.4 3.8.5 3.8.7 3.8.8 3.9.0 3.9.1 3.9.11 3.9.2 3.9.4 3.9.5 3.9.8 3.9.9 trunk 1.0.0 1.0.1 1.0.2 1.1 1.1.1 1.1.2 1.1.3 1.2 1.2.1 1.2.10 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.2.7 1.2.8 1.2.9 1.3.1 1.3.2 1.3.3 1.3.4 1.4.0 1.4.1 1.4.2 1.4.3 1.5.0 1.6.0 1.6.1 1.6.2 1.6.3 1.6.4 1.6.5 1.6.5.1 1.6.5.2 1.6.5.3 1.6.5.4 1.7 1.7.1 1.7.1.1 2.0 2.0.1 2.0.3 2.0.4 2.0.5 2.0.6 2.0.6.2 2.0.6.3 2.0.6.5 2.0.7 2.0.7.1 2.1 2.1.1 2.1.2 2.1.3 2.1.4 2.1.5 2.2 2.2.1 2.2.2 2.3 2.3.1 2.4 2.4.2 2.4.3 2.4.4 2.4.5 2.5.2 2.5.3 2.6.1 2.6.2 2.6.3 2.7 2.7.1 2.7.4 2.7.4.1 2.7.5 2.7.6 2.7.8 2.7.8.1 2.7.9.1 2.8.0 2.8.0.1
wp-smushit / app / class-admin.php
wp-smushit / app Last commit date
assets 2 years ago common 2 years ago modals 2 years ago pages 2 years ago views 2 years ago class-abstract-page.php 2 years ago class-abstract-summary-page.php 2 years ago class-admin.php 2 years ago class-ajax.php 2 years ago class-interface-page.php 2 years ago class-media-library.php 2 years ago
class-admin.php
785 lines
1 <?php
2 /**
3 * Admin class.
4 *
5 * @package Smush\App
6 */
7
8 namespace Smush\App;
9
10 use Smush\Core\Core;
11 use Smush\Core\Error_Handler;
12 use Smush\Core\Helper;
13 use Smush\Core\Settings;
14 use Smush\Core\Stats\Global_Stats;
15 use WP_Smush;
16
17 if ( ! defined( 'WPINC' ) ) {
18 die;
19 }
20
21 /**
22 * Class Admin
23 */
24 class Admin {
25
26 /**
27 * Plugin pages.
28 *
29 * @var array
30 */
31 public $pages = array();
32
33 /**
34 * AJAX module.
35 *
36 * @var Ajax
37 */
38 public $ajax;
39
40 /**
41 * List of smush settings pages.
42 *
43 * @var array $plugin_pages
44 */
45 public static $plugin_pages = array(
46 'gallery_page_wp-smush-nextgen-bulk',
47 'nextgen-gallery_page_wp-smush-nextgen-bulk', // Different since NextGen 3.3.6.
48 'toplevel_page_smush',
49 'toplevel_page_smush-network',
50 );
51
52 /**
53 * Admin constructor.
54 *
55 * @param Media_Library $media_lib Media uploads library.
56 */
57 public function __construct( Media_Library $media_lib ) {
58 add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_scripts' ) );
59
60 add_action( 'admin_menu', array( $this, 'add_menu_pages' ) );
61 add_action( 'network_admin_menu', array( $this, 'add_menu_pages' ) );
62
63 add_action( 'admin_init', array( $this, 'smush_i18n' ) );
64 // Add information to privacy policy page (only during creation).
65 add_action( 'admin_init', array( $this, 'add_policy' ) );
66
67 if ( wp_doing_ajax() ) {
68 $this->ajax = new Ajax();
69 }
70
71 // Init media library UI.
72 $media_lib->init_ui();
73
74 add_filter( 'plugin_action_links_' . WP_SMUSH_BASENAME, array( $this, 'settings_link' ) );
75 add_filter( 'network_admin_plugin_action_links_' . WP_SMUSH_BASENAME, array( $this, 'settings_link' ) );
76 add_filter( 'plugin_row_meta', array( $this, 'add_plugin_meta_links' ), 10, 2 );
77
78 // Prints a membership validation issue notice in Media Library.
79 add_action( 'admin_notices', array( $this, 'media_library_membership_notice' ) );
80
81 // Plugin conflict notice.
82 add_action( 'admin_notices', array( $this, 'show_plugin_conflict_notice' ) );
83 add_action( 'admin_notices', array( $this, 'show_parallel_unavailability_notice' ) );
84 add_action( 'admin_notices', array( $this, 'show_background_unavailability_notice' ) );
85 add_action( 'smush_check_for_conflicts', array( $this, 'check_for_conflicts_cron' ) );
86 add_action( 'activated_plugin', array( $this, 'check_for_conflicts_cron' ) );
87 add_action( 'deactivated_plugin', array( $this, 'check_for_conflicts_cron' ) );
88
89 // Filter built-in wpmudev branding script.
90 add_filter( 'wpmudev_whitelabel_plugin_pages', array( $this, 'builtin_wpmudev_branding' ) );
91
92 add_action( 'wp_smush_header_notices', array( $this, 'show_php_deprecated_notice' ) );
93 }
94
95 /**
96 * Load translation files.
97 */
98 public function smush_i18n() {
99 load_plugin_textdomain(
100 'wp-smushit',
101 false,
102 dirname( WP_SMUSH_BASENAME ) . '/languages'
103 );
104 }
105
106 /**
107 * Register JS and CSS.
108 */
109 private function register_scripts() {
110 global $wp_version;
111 /**
112 * Queue clipboard.js from your plugin if WP's version is below 5.2.0
113 * since it's only included from 5.2.0 on.
114 *
115 * Use 'clipboard' as the handle so it matches WordPress' handle for the script.
116 *
117 * @since 3.8.0
118 */
119 if ( version_compare( $wp_version, '5.2', '<' ) ) {
120 wp_register_script( 'clipboard', WP_SMUSH_URL . 'app/assets/js/smush-clipboard.min.js', array(), WP_SMUSH_VERSION, true );
121 }
122
123 /**
124 * Share UI JS.
125 *
126 * @since 3.8.0 added 'clipboard' dependency.
127 */
128 wp_register_script( 'smush-sui', WP_SMUSH_URL . 'app/assets/js/smush-sui.min.js', array( 'jquery', 'clipboard' ), WP_SHARED_UI_VERSION, true );
129
130 // Main JS.
131 wp_register_script( 'smush-admin', WP_SMUSH_URL . 'app/assets/js/smush-admin.min.js', array( 'jquery', 'smush-sui', 'underscore', 'wp-color-picker' ), WP_SMUSH_VERSION, true );
132
133 // JS that can be used on all pages in the WP backend.
134 wp_register_script( 'smush-admin-common', WP_SMUSH_URL . 'app/assets/js/smush-admin-common.min.js', array( 'jquery' ), WP_SMUSH_VERSION, true );
135
136 // Main CSS.
137 wp_register_style( 'smush-admin', WP_SMUSH_URL . 'app/assets/css/smush-admin.min.css', array(), WP_SMUSH_VERSION );
138
139 // Styles that can be used on all pages in the WP backend.
140 wp_register_style( 'smush-admin-common', WP_SMUSH_URL . 'app/assets/css/smush-global.min.css', array(), WP_SMUSH_VERSION );
141
142 // Dismiss update info.
143 WP_Smush::get_instance()->core()->mod->smush->dismiss_update_info();
144 }
145
146 /**
147 * Enqueue scripts.
148 */
149 public function enqueue_scripts() {
150 wp_enqueue_script( 'smush-global', WP_SMUSH_URL . 'app/assets/js/smush-global.min.js', array(), WP_SMUSH_VERSION, true );
151 wp_localize_script( 'smush-global', 'smush_global', array(
152 'nonce' => wp_create_nonce( 'wp-smush-ajax' ),
153 ) );
154
155 $current_page = '';
156 $current_screen = '';
157
158 if ( function_exists( 'get_current_screen' ) ) {
159 $current_screen = get_current_screen();
160 $current_page = ! empty( $current_screen ) ? $current_screen->base : $current_page;
161 }
162
163 if ( ! in_array( $current_page, Core::$external_pages, true ) && false === strpos( $current_page, 'page_smush' ) ) {
164 return;
165 }
166
167 // Allows to disable enqueuing smush files on a particular page.
168 if ( ! apply_filters( 'wp_smush_enqueue', true ) ) {
169 return;
170 }
171
172 $this->register_scripts();
173
174 // Load on all Smush page only.
175 if ( isset( $current_screen->id ) && ( in_array( $current_screen->id, self::$plugin_pages, true ) || false !== strpos( $current_screen->id, 'page_smush' ) ) ) {
176 // Smush admin (smush-admin) includes the Shared UI.
177 wp_enqueue_style( 'smush-admin' );
178 wp_enqueue_script( 'smush-wpmudev-sui' );
179 }
180
181 if ( ! in_array( $current_page, array( 'post', 'post-new', 'page', 'edit-page' ), true ) ) {
182 // Skip these pages where the script isn't used.
183 wp_enqueue_script( 'smush-admin' );
184 } else {
185 // Otherwise, load only the common JS code.
186 wp_enqueue_script( 'smush-admin-common' );
187 }
188
189 // We need it on media pages and Smush pages.
190 wp_enqueue_style( 'smush-admin-common' );
191
192 // Localize translatable strings for js.
193 WP_Smush::get_instance()->core()->localize();
194 }
195
196 /**
197 * Adds a Smush pro settings link on plugin page.
198 *
199 * @param array $links Current links.
200 *
201 * @return array|string
202 */
203 public function settings_link( $links ) {
204 // Upgrade link.
205 if ( ! WP_Smush::is_pro() ) {
206 $upgrade_url = add_query_arg(
207 array(
208 'coupon' => 'SMUSH30OFF',
209 'checkout' => 0,
210 'utm_source' => 'smush',
211 'utm_medium' => 'plugin',
212 'utm_campaign' => 'wp-smush-pro/wp-smush.php' !== WP_SMUSH_BASENAME ? 'smush_pluginlist_upgrade' : 'smush_pluginlist_renew',
213 ),
214 esc_url( 'https://wpmudev.com/project/wp-smush-pro/' )
215 );
216
217 $using_free_version = 'wp-smush-pro/wp-smush.php' !== WP_SMUSH_BASENAME;
218 if ( $using_free_version ) {
219 $label = __( 'Upgrade to Smush Pro', 'wp-smushit' );
220 $text = __( 'Upgrade for 30% off', 'wp-smushit' );
221 } else {
222 $label = __( 'Renew Membership', 'wp-smushit' );
223 $text = __( 'Renew Membership', 'wp-smushit' );
224 }
225
226 if ( isset( $text ) ) {
227 $links['smush_upgrade'] = '<a href="' . esc_url( $upgrade_url ) . '" aria-label="' . esc_attr( $label ) . '" target="_blank" style="color: #8D00B1;">' . esc_html( $text ) . '</a>';
228 }
229 }
230
231 // Documentation link.
232 $links['smush_docs'] = '<a href="https://wpmudev.com/docs/wpmu-dev-plugins/smush/?utm_source=smush&utm_medium=plugin&utm_campaign=smush_pluginlist_docs" aria-label="' . esc_attr( __( 'View Smush Documentation', 'wp-smushit' ) ) . '" target="_blank">' . esc_html__( 'Docs', 'wp-smushit' ) . '</a>';
233
234 // Settings link.
235 $settings_page = is_multisite() && is_network_admin() ? network_admin_url( 'admin.php?page=smush-settings' ) : menu_page_url( 'smush-settings', false );
236 $links['smush_dashboard'] = '<a href="' . $settings_page . '" aria-label="' . esc_attr( __( 'Go to Smush settings', 'wp-smushit' ) ) . '">' . esc_html__( 'Settings', 'wp-smushit' ) . '</a>';
237
238 $access = get_site_option( 'wp-smush-networkwide' );
239 if ( ! is_network_admin() && is_plugin_active_for_network( WP_SMUSH_BASENAME ) && ! $access ) {
240 // Remove settings link for subsites if Subsite Controls is not set on network permissions tab.
241 unset( $links['smush_dashboard'] );
242 }
243
244 return array_reverse( $links );
245 }
246
247 /**
248 * Add additional links next to the plugin version.
249 *
250 * @since 3.5.0
251 *
252 * @param array $links Links array.
253 * @param string $file Plugin basename.
254 *
255 * @return array
256 */
257 public function add_plugin_meta_links( $links, $file ) {
258 if ( ! defined( 'WP_SMUSH_BASENAME' ) || WP_SMUSH_BASENAME !== $file ) {
259 return $links;
260 }
261
262 if ( 'wp-smush-pro/wp-smush.php' !== WP_SMUSH_BASENAME ) {
263 $links[] = '<a href="https://wordpress.org/support/plugin/wp-smushit/reviews/#new-post" target="_blank" title="' . esc_attr__( 'Rate Smush', 'wp-smushit' ) . '">' . esc_html__( 'Rate Smush', 'wp-smushit' ) . '</a>';
264 $links[] = '<a href="https://wordpress.org/support/plugin/wp-smushit/" target="_blank" title="' . esc_attr__( 'Support', 'wp-smushit' ) . '">' . esc_html__( 'Support', 'wp-smushit' ) . '</a>';
265 } else {
266 if ( isset( $links[2] ) && false !== strpos( $links[2], 'project/wp-smush-pro' ) ) {
267 $links[2] = sprintf(
268 '<a href="https://wpmudev.com/project/wp-smush-pro/" target="_blank">%s</a>',
269 __( 'View details', 'wp-smushit' )
270 );
271 }
272
273 $links[] = '<a href="https://wpmudev.com/get-support/" target="_blank" title="' . esc_attr__( 'Premium Support', 'wp-smushit' ) . '">' . esc_html__( 'Premium Support', 'wp-smushit' ) . '</a>';
274 }
275
276 $links[] = '<a href="https://wpmudev.com/roadmap/" target="_blank" title="' . esc_attr__( 'Roadmap', 'wp-smushit' ) . '">' . esc_html__( 'Roadmap', 'wp-smushit' ) . '</a>';
277
278 return $links;
279 }
280
281 /**
282 * Add menu pages.
283 */
284 public function add_menu_pages() {
285 $title = 'wp-smush-pro/wp-smush.php' === WP_SMUSH_BASENAME ? esc_html__( 'Smush Pro', 'wp-smushit' ) : esc_html__( 'Smush', 'wp-smushit' );
286
287 if ( Settings::can_access( false, true ) ) {
288 $this->pages['smush'] = new Pages\Dashboard( 'smush', $title );
289 $this->pages['dashboard'] = new Pages\Dashboard( 'smush', __( 'Dashboard', 'wp-smushit' ), 'smush' );
290
291 if ( Abstract_Page::should_render( 'bulk' ) ) {
292 $this->pages['bulk'] = new Pages\Bulk( 'smush-bulk', __( 'Bulk Smush', 'wp-smushit' ), 'smush' );
293 }
294
295 if ( Abstract_Page::should_render( 'directory' ) ) {
296 $this->pages['directory'] = new Pages\Directory( 'smush-directory', __( 'Directory Smush', 'wp-smushit' ), 'smush' );
297 }
298
299 if ( Abstract_Page::should_render( 'lazy_load' ) ) {
300 $this->pages['lazy-load'] = new Pages\Lazy( 'smush-lazy-load', __( 'Lazy Load', 'wp-smushit' ), 'smush' );
301 }
302
303 if ( Abstract_Page::should_render( 'cdn' ) ) {
304 $this->pages['cdn'] = new Pages\CDN( 'smush-cdn', __( 'CDN', 'wp-smushit' ), 'smush' );
305 }
306
307 if ( Abstract_Page::should_render( 'webp' ) ) {
308 $this->pages['webp'] = new Pages\WebP( 'smush-webp', __( 'Local WebP', 'wp-smushit' ), 'smush' );
309 }
310
311 if ( Abstract_Page::should_render( 'integrations' ) ) {
312 $this->pages['integrations'] = new Pages\Integrations( 'smush-integrations', __( 'Integrations', 'wp-smushit' ), 'smush' );
313 }
314
315 if ( ! is_multisite() || is_network_admin() ) {
316 $this->pages['settings'] = new Pages\Settings( 'smush-settings', __( 'Settings', 'wp-smushit' ), 'smush' );
317 }
318
319 if ( ! apply_filters( 'wpmudev_branding_hide_doc_link', false ) && Abstract_Page::should_render( 'tutorials' ) ) {
320 $this->pages['tutorials'] = new Pages\Tutorials( 'smush-tutorials', __( 'Tutorials', 'wp-smushit' ), 'smush' );
321 }
322
323 if ( ! WP_Smush::is_pro() ) {
324 $this->pages['smush-upgrade'] = new Pages\Upgrade( 'smush-upgrade', __( 'Smush Pro', 'wp-smushit' ), 'smush' );
325 }
326 }
327
328 // Add a bulk smush option for NextGen gallery.
329 if ( defined( 'NGGFOLDER' ) && WP_Smush::get_instance()->core()->nextgen->is_enabled() && WP_Smush::is_pro() && ! is_network_admin() ) {
330 $this->pages['nextgen'] = new Pages\Nextgen( 'wp-smush-nextgen-bulk', $title, NGGFOLDER, true );
331 }
332 }
333
334 /**
335 * Add Smush Policy to "Privacy Policy" page during creation.
336 *
337 * @since 2.3.0
338 */
339 public function add_policy() {
340 if ( ! function_exists( 'wp_add_privacy_policy_content' ) ) {
341 return;
342 }
343
344 $content = '<h3>' . __( 'Plugin: Smush', 'wp-smushit' ) . '</h3>';
345 $content .=
346 '<p>' . __( 'Note: Smush does not interact with end users on your website. The only input option Smush has is to a newsletter subscription for site admins only. If you would like to notify your users of this in your privacy policy, you can use the information below.', 'wp-smushit' ) . '</p>';
347 $content .=
348 '<p>' . __( 'Smush sends images to the WPMU DEV servers to optimize them for web use. This includes the transfer of EXIF data. The EXIF data will either be stripped or returned as it is. It is not stored on the WPMU DEV servers.', 'wp-smushit' ) . '</p>';
349 $content .=
350 '<p>' . sprintf( /* translators: %1$s - opening <a>, %2$s - closing </a> */
351 __( "Smush uses the Stackpath Content Delivery Network (CDN). Stackpath may store web log information of site visitors, including IPs, UA, referrer, Location and ISP info of site visitors for 7 days. Files and images served by the CDN may be stored and served from countries other than your own. Stackpath's privacy policy can be found %1\$shere%2\$s.", 'wp-smushit' ),
352 '<a href="https://www.stackpath.com/legal/privacy-statement/" target="_blank">',
353 '</a>'
354 ) . '</p>';
355
356 if ( strpos( WP_SMUSH_DIR, 'wp-smushit' ) !== false ) {
357 // Only for wordpress.org members.
358 $content .=
359 '<p>' . __( 'Smush uses a third-party email service (Drip) to send informational emails to the site administrator. The administrator\'s email address is sent to Drip and a cookie is set by the service. Only administrator information is collected by Drip.', 'wp-smushit' ) . '</p>';
360 }
361
362 wp_add_privacy_policy_content(
363 __( 'WP Smush', 'wp-smushit' ),
364 wp_kses_post( wpautop( $content, false ) )
365 );
366 }
367
368 /**
369 * Prints the Membership Validation issue notice
370 */
371 public function media_library_membership_notice() {
372 // No need to print it for free version.
373 if ( ! WP_Smush::is_pro() ) {
374 return;
375 }
376
377 // Show it on Media Library page only.
378 $screen = get_current_screen();
379 if ( ! empty( $screen ) && ( 'upload' === $screen->id || in_array( $screen->id, self::$plugin_pages, true ) || false !== strpos( $screen->id, 'page_smush' ) ) ) {
380 ?>
381 <div id="wp-smush-invalid-member" data-message="<?php esc_attr_e( 'Validating...', 'wp-smushit' ); ?>" class="hidden notice notice-warning is-dismissible">
382 <p>
383 <?php
384 printf(
385 /* translators: $1$s: recheck link, $2$s: closing a tag, %3$s; contact link, %4$s: closing a tag */
386 esc_html__(
387 'It looks like Smush couldn’t verify your WPMU DEV membership so Pro features have been disabled for now. If you think this is an error, run a %1$sre-check%2$s or get in touch with our %3$ssupport team%4$s.',
388 'wp-smushit'
389 ),
390 '<a href="#" id="wp-smush-revalidate-member" data-message="%s">',
391 '</a>',
392 '<a href="https://wpmudev.com/contact" target="_blank">',
393 '</a>'
394 );
395 ?>
396 </p>
397 </div>
398 <?php
399 }
400 }
401
402 /**
403 * Check for plugin conflicts cron.
404 *
405 * @since 3.6.0
406 *
407 * @param string $deactivated Holds the slug of activated/deactivated plugin.
408 */
409 public function check_for_conflicts_cron( $deactivated = '' ) {
410 $conflicting_plugins = array(
411 'autoptimize/autoptimize.php',
412 'ewww-image-optimizer/ewww-image-optimizer.php',
413 'imagify/imagify.php',
414 'resmushit-image-optimizer/resmushit.php',
415 'shortpixel-image-optimiser/wp-shortpixel.php',
416 'tiny-compress-images/tiny-compress-images.php',
417 'wp-rocket/wp-rocket.php',
418 'optimole-wp/optimole-wp.php',
419 // lazy load plugins.
420 'rocket-lazy-load/rocket-lazy-load.php',
421 'a3-lazy-load/a3-lazy-load.php',
422 'jetpack/jetpack.php',
423 'sg-cachepress/sg-cachepress.php',
424 'w3-total-cache/w3-total-cache.php',
425 'wp-fastest-cache/wpFastestCache.php',
426 'wp-optimize/wp-optimize.php',
427 'nitropack/main.php',
428 );
429
430 $plugins = get_plugins();
431
432 $active_plugins = array();
433 foreach ( $conflicting_plugins as $plugin ) {
434 if ( ! array_key_exists( $plugin, $plugins ) ) {
435 continue;
436 }
437
438 if ( ! is_plugin_active( $plugin ) ) {
439 continue;
440 }
441
442 // Deactivation of the plugin in process.
443 if ( doing_action( 'deactivated_plugin' ) && $deactivated === $plugin ) {
444 continue;
445 }
446
447 $active_plugins[] = $plugins[ $plugin ]['Name'];
448 }
449
450 set_transient( 'wp-smush-conflict_check', $active_plugins, 3600 );
451 }
452
453 /**
454 * Display plugin incompatibility notice.
455 *
456 * @since 3.6.0
457 */
458 public function show_plugin_conflict_notice() {
459 // Do not show on lazy load module, there we show an inline notice.
460 if ( false !== strpos( get_current_screen()->id, 'page_smush-lazy-load' ) ) {
461 return;
462 }
463
464 $dismissed = $this->is_notice_dismissed( 'plugin-conflict' );
465 if ( $dismissed ) {
466 return;
467 }
468
469 $conflict_check = get_transient( 'wp-smush-conflict_check' );
470
471 // Have never checked before.
472 if ( false === $conflict_check ) {
473 wp_schedule_single_event( time(), 'smush_check_for_conflicts' );
474 return;
475 }
476
477 // No conflicting plugins detected.
478 if ( isset( $conflict_check ) && is_array( $conflict_check ) && empty( $conflict_check ) ) {
479 return;
480 }
481
482 array_walk(
483 $conflict_check,
484 function( &$item ) {
485 $item = '<strong>' . $item . '</strong>';
486 }
487 );
488 ?>
489 <div class="notice notice-info is-dismissible smush-dismissible-notice"
490 id="smush-conflict-notice"
491 data-key="plugin-conflict">
492
493 <p><?php esc_html_e( 'You have multiple WordPress image optimization plugins installed. This may cause unpredictable behavior while optimizing your images, inaccurate reporting, or images to not display. For best results use only one image optimizer plugin at a time. These plugins may cause issues with Smush:', 'wp-smushit' ); ?></p>
494 <p>
495 <?php echo wp_kses_post( join( '<br>', $conflict_check ) ); ?>
496 </p>
497 <p>
498 <a href="<?php echo esc_url( admin_url( 'plugins.php' ) ); ?>" class="button button-primary">
499 <?php esc_html_e( 'Manage Plugins', 'wp-smushit' ); ?>
500 </a>
501 <a href="#"
502 style="margin-left: 15px"
503 id="smush-dismiss-conflict-notice" class="smush-dismiss-notice-button">
504
505 <?php esc_html_e( 'Dismiss', 'wp-smushit' ); ?>
506 </a>
507 </p>
508 </div>
509 <?php
510 }
511
512 /**
513 * Prints the content for pending images for the Bulk Smush section.
514 *
515 * @param int $remaining_count
516 * @param int $reoptimize_count
517 * @param int $optimize_count
518 *
519 * @since 3.7.2
520 */
521 public function print_pending_bulk_smush_content( $remaining_count, $reoptimize_count, $optimize_count ) {
522 $optimize_message = '';
523 if ( 0 < $optimize_count ) {
524 $optimize_message = sprintf(
525 /* translators: 1. opening strong tag, 2: unsmushed images count,3. closing strong tag. */
526 esc_html( _n( '%1$s%2$d attachment%3$s that needs smushing', '%1$s%2$d attachments%3$s that need smushing', $optimize_count, 'wp-smushit' ) ),
527 '<strong>',
528 absint( $optimize_count ),
529 '</strong>'
530 );
531 }
532
533 $reoptimize_message = '';
534 if ( 0 < $reoptimize_count ) {
535 $reoptimize_message = sprintf(
536 /* translators: 1. opening strong tag, 2: re-smush images count,3. closing strong tag. */
537 esc_html( _n( '%1$s%2$d attachment%3$s that needs re-smushing', '%1$s%2$d attachments%3$s that need re-smushing', $reoptimize_count, 'wp-smushit' ) ),
538 '<strong>',
539 esc_html( $reoptimize_count ),
540 '</strong>'
541 );
542 }
543
544 $bulk_limit_free_message = $this->generate_bulk_limit_message_for_free( $remaining_count );
545
546 $image_count_description = sprintf(
547 /* translators: 1. username, 2. unsmushed images message, 3. 'and' text for when having both unsmushed and re-smush images, 4. re-smush images message. */
548 __( '%1$s, you have %2$s%3$s%4$s! %5$s', 'wp-smushit' ),
549 esc_html( Helper::get_user_name() ),
550 $optimize_message,
551 ( $optimize_message && $reoptimize_message ? esc_html__( ' and ', 'wp-smushit' ) : '' ),
552 $reoptimize_message,
553 $bulk_limit_free_message
554 );
555 ?>
556 <span id="wp-smush-bulk-image-count"><?php echo esc_html( $remaining_count ); ?></span>
557 <p id="wp-smush-bulk-image-count-description">
558 <?php echo wp_kses_post( $image_count_description ); ?>
559 </p>
560 <?php
561 }
562
563 public function get_global_stats_with_bulk_smush_content() {
564 $core = WP_Smush::get_instance()->core();
565 $stats = $core->get_global_stats();
566 $global_stats = Global_Stats::get();
567 $remaining_count = $global_stats->get_remaining_count();
568 $optimize_count = $global_stats->get_optimize_list()->get_count();
569 $reoptimize_count = $global_stats->get_redo_count();
570
571 $stats['errors'] = Error_Handler::get_last_errors();
572
573 if ( $remaining_count > 0 ) {
574 ob_start();
575 WP_Smush::get_instance()->admin()->print_pending_bulk_smush_content(
576 $remaining_count,
577 $reoptimize_count,
578 $optimize_count
579 );
580 $content = ob_get_clean();
581 $stats['content'] = $content;
582 }
583
584 return $stats;
585 }
586
587 public function get_global_stats_with_bulk_smush_content_and_notice() {
588 $stats = $this->get_global_stats_with_bulk_smush_content();
589 $remaining_count = Global_Stats::get()->get_remaining_count();
590 if ( $remaining_count < 1 ) {
591 $stats['notice'] = esc_html__( 'Yay! All images are optimized as per your current settings.', 'wp-smushit' );
592 $stats['noticeType'] = 'success';
593 } else {
594 $stats['noticeType'] = 'warning';
595 $stats['notice'] = sprintf(
596 /* translators: %1$d - number of images, %2$s - opening a tag, %3$s - closing a tag */
597 esc_html__( 'Image check complete, you have %1$d images that need smushing. %2$sBulk smush now!%3$s', 'wp-smushit' ),
598 $remaining_count,
599 '<a href="#" class="wp-smush-trigger-bulk">',
600 '</a>'
601 );
602 }
603
604 return $stats;
605 }
606
607 private function generate_bulk_limit_message_for_free( $remaining_count ) {
608 $dont_limit = WP_Smush::get_instance()->core()->mod->bg_optimization->can_use_background();
609 if ( $dont_limit || $remaining_count < Core::MAX_FREE_BULK ) {
610 return '';
611 }
612
613 $upgrade_url = add_query_arg(
614 array(
615 'coupon' => 'SMUSH30OFF',
616 'checkout' => 0,
617 'utm_source' => 'smush',
618 'utm_medium' => 'plugin',
619 'utm_campaign' => 'smush_bulk_smush_pre_smush_50_limit',
620 ),
621 'https://wpmudev.com/project/wp-smush-pro/'
622 );
623 $batches = ceil( $remaining_count / Core::MAX_FREE_BULK );
624 $discount_text = '<strong>'. esc_html__( '30% off welcome discount available.', 'wp-smushit' ) .'</strong>';
625 return sprintf(
626 /* translators: 1: max free bulk limit, 2: Total batches to smush, 3: opening a tag, 4: closing a tag. */
627 esc_html__( 'Free users can only Bulk Smush %1$d images at one time. Smush in %2$d batches or %3$sBulk Smush unlimited images with Pro%4$s. %5$s', 'wp-smushit' ),
628 Core::MAX_FREE_BULK,
629 $batches,
630 '<a class="smush-upsell-link" target="_blank" href="' . $upgrade_url . '">',
631 '</a>',
632 $discount_text
633 );
634 }
635
636 /**
637 * Add more pages to builtin wpmudev branding.
638 *
639 * @since 3.0
640 *
641 * @param array $plugin_pages Nextgen pages is not introduced in built in wpmudev branding.
642 *
643 * @return array
644 */
645 public function builtin_wpmudev_branding( $plugin_pages ) {
646 $plugin_pages['gallery_page_wp-smush-nextgen-bulk'] = array(
647 'wpmudev_whitelabel_sui_plugins_branding',
648 'wpmudev_whitelabel_sui_plugins_footer',
649 'wpmudev_whitelabel_sui_plugins_doc_links',
650 );
651
652 // There's a different page ID since NextGen 3.3.6.
653 $plugin_pages['nextgen-gallery_page_wp-smush-nextgen-bulk'] = array(
654 'wpmudev_whitelabel_sui_plugins_branding',
655 'wpmudev_whitelabel_sui_plugins_footer',
656 'wpmudev_whitelabel_sui_plugins_doc_links',
657 );
658
659 foreach ( $this->pages as $key => $value ) {
660 $plugin_pages[ "smush-pro_page_smush-{$key}" ] = array(
661 'wpmudev_whitelabel_sui_plugins_branding',
662 'wpmudev_whitelabel_sui_plugins_footer',
663 'wpmudev_whitelabel_sui_plugins_doc_links',
664 );
665 }
666
667 return $plugin_pages;
668 }
669
670 public function is_notice_dismissed( $notice ) {
671 $dismissed_notices = get_option( 'wp-smush-dismissed-notices', array() );
672
673 return ! empty( $dismissed_notices[ $notice ] );
674 }
675
676 public function show_parallel_unavailability_notice() {
677 $smush = WP_Smush::get_instance()->core()->mod->smush;
678 $curl_multi_exec_available = $smush->curl_multi_exec_available();
679 $is_current_user_not_admin = ! current_user_can( 'manage_options' );
680 $is_not_bulk_smush_page = false === strpos( get_current_screen()->id, 'page_smush-bulk' );
681 $notice_hidden = $this->is_notice_dismissed( 'curl-multi-unavailable' );
682
683 if (
684 $curl_multi_exec_available ||
685 $is_current_user_not_admin ||
686 $is_not_bulk_smush_page ||
687 $notice_hidden
688 ) {
689 return;
690 }
691
692 $notice_text = sprintf(
693 /* translators: %s: <strong>curl_multi_exec()</strong> */
694 esc_html__( 'Smush was unable to activate parallel processing on your site as your web hosting provider has disabled the %s function on your server. We highly recommend contacting your hosting provider to enable that function to optimize images on your site faster.', 'wp-smushit' ),
695 '<strong>curl_multi_exec()</strong>'
696 );
697
698 ?>
699 <div class="notice notice-warning is-dismissible smush-dismissible-notice"
700 id="smush-parallel-unavailability-notice"
701 data-key="curl-multi-unavailable">
702
703 <strong style="font-size: 15px;line-height: 30px;margin: 8px 0 0 2px;display: inline-block;">
704 <?php esc_html_e( 'Smush images faster with parallel image optimization', 'wp-smushit' ); ?>
705 </strong>
706 <br/>
707 <p style="margin-bottom: 13px;margin-top: 0;">
708 <?php echo wp_kses_post( $notice_text ); ?><br/>
709
710 <a style="margin-top: 5px;display: inline-block;" href="#" class="smush-dismiss-notice-button">
711 <?php esc_html_e( 'Dismiss', 'wp-smushit' ); ?>
712 </a>
713 </p>
714 </div>
715 <?php
716 }
717
718 public function show_background_unavailability_notice() {
719 $bg_optimization = WP_Smush::get_instance()->core()->mod->bg_optimization;
720 $background_supported = $bg_optimization->is_background_supported();
721 $background_disabled = ! $bg_optimization->is_background_enabled();
722 $is_current_user_not_admin = ! current_user_can( 'manage_options' );
723 $is_not_bulk_smush_page = false === strpos( get_current_screen()->id, 'page_smush-bulk' );
724 $notice_hidden = $this->is_notice_dismissed( 'background-smush-unavailable' );
725
726 if (
727 $background_supported ||
728 $background_disabled ||
729 $is_current_user_not_admin ||
730 $is_not_bulk_smush_page ||
731 $notice_hidden
732 ) {
733 return;
734 }
735
736 $notice_text = sprintf(
737 /* translators: 1: Current MYSQL version, 2: Required MYSQL version */
738 esc_html__( 'Smush was unable to activate background processing on your site as your web hosting provider is using an old version of MySQL on your server (version %1$s). We highly recommend contacting your hosting provider to upgrade MySQL to version %2$s or higher to optimize images in the background.', 'wp-smushit' ),
739 $bg_optimization->get_actual_mysql_version(),
740 $bg_optimization->get_required_mysql_version()
741 );
742 ?>
743 <div class="notice notice-warning is-dismissible smush-dismissible-notice"
744 id="smush-background-unavailability-notice"
745 data-key="background-smush-unavailable">
746
747 <strong style="font-size: 15px;line-height: 30px;margin: 8px 0 0 2px;display: inline-block;">
748 <?php esc_html_e( 'Smush images in the background', 'wp-smushit' ); ?>
749 </strong>
750 <br/>
751 <p style="margin-bottom: 13px;margin-top: 0;">
752 <?php echo wp_kses_post( $notice_text ); ?><br/>
753
754 <a style="margin-top: 5px;display: inline-block;" href="#" class="smush-dismiss-notice-button">
755 <?php esc_html_e( 'Dismiss', 'wp-smushit' ); ?>
756 </a>
757 </p>
758 </div>
759 <?php
760 }
761
762 public function show_php_deprecated_notice() {
763 // Only show the deprecated notice for admin and only network side for MU site.
764 if ( ! current_user_can( 'manage_options' ) || ( is_multisite() && ! is_network_admin() ) ) {
765 return;
766 }
767
768 if ( $this->is_notice_dismissed( 'php_deprecated' ) ) {
769 return;
770 }
771
772 $php_version = PHP_VERSION;
773 $required_php_version = '7.0';
774 if ( version_compare( $php_version, $required_php_version, '>=' ) ) {
775 return;
776 }
777 /* translators: %1$s: Current PHP version */
778 $error_message = sprintf( esc_html__( 'We have noticed that you are using PHP %1$s, which has reached its end of life and is now highly insecure. Smush will stop supporting PHP %1$s soon, please contact your hosting provider to switch to a more recent version of PHP.', 'wp-smushit' ), $php_version );
779 $error_message = '<p>' . $error_message . '</p>';
780 ?>
781 <div role="alert" id="wp-smush-php-deprecated-notice" class="sui-notice wp-smush-dismissible-header-notice smush-dismissible-notice" data-dismiss-key="php_deprecated" data-message="<?php echo esc_attr( $error_message ); ?>" aria-live="assertive"></div>
782 <?php
783 }
784 }
785