ajax = new Ajax(); } // Init media library UI. $media_lib->init_ui(); add_filter( 'plugin_action_links_' . WP_SMUSH_BASENAME, array( $this, 'settings_link' ) ); add_filter( 'network_admin_plugin_action_links_' . WP_SMUSH_BASENAME, array( $this, 'settings_link' ) ); add_filter( 'plugin_row_meta', array( $this, 'add_plugin_meta_links' ), 10, 2 ); // Prints a membership validation issue notice in Media Library. add_action( 'admin_notices', array( $this, 'media_library_membership_notice' ) ); // Plugin conflict notice. add_action( 'admin_notices', array( $this, 'show_plugin_conflict_notice' ) ); add_action( 'admin_notices', array( $this, 'show_parallel_unavailability_notice' ) ); add_action( 'admin_notices', array( $this, 'show_background_unavailability_notice' ) ); add_action( 'smush_check_for_conflicts', array( $this, 'check_for_conflicts_cron' ) ); add_action( 'activated_plugin', array( $this, 'check_for_conflicts_cron' ) ); add_action( 'deactivated_plugin', array( $this, 'check_for_conflicts_cron' ) ); // Filter built-in wpmudev branding script. add_filter( 'wpmudev_whitelabel_plugin_pages', array( $this, 'builtin_wpmudev_branding' ) ); add_action( 'wp_smush_header_notices', array( $this, 'show_php_deprecated_notice' ) ); } /** * Load translation files. */ public function smush_i18n() { load_plugin_textdomain( 'wp-smushit', false, dirname( WP_SMUSH_BASENAME ) . '/languages' ); } /** * Register JS and CSS. */ private function register_scripts() { global $wp_version; /** * Queue clipboard.js from your plugin if WP's version is below 5.2.0 * since it's only included from 5.2.0 on. * * Use 'clipboard' as the handle so it matches WordPress' handle for the script. * * @since 3.8.0 */ if ( version_compare( $wp_version, '5.2', '<' ) ) { wp_register_script( 'clipboard', WP_SMUSH_URL . 'app/assets/js/smush-clipboard.min.js', array(), WP_SMUSH_VERSION, true ); } /** * Share UI JS. * * @since 3.8.0 added 'clipboard' dependency. */ wp_register_script( 'smush-sui', WP_SMUSH_URL . 'app/assets/js/smush-sui.min.js', array( 'jquery', 'clipboard' ), WP_SHARED_UI_VERSION, true ); // Main JS. 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 ); // JS that can be used on all pages in the WP backend. wp_register_script( 'smush-admin-common', WP_SMUSH_URL . 'app/assets/js/smush-admin-common.min.js', array( 'jquery' ), WP_SMUSH_VERSION, true ); // Main CSS. wp_register_style( 'smush-admin', WP_SMUSH_URL . 'app/assets/css/smush-admin.min.css', array(), WP_SMUSH_VERSION ); // Styles that can be used on all pages in the WP backend. wp_register_style( 'smush-admin-common', WP_SMUSH_URL . 'app/assets/css/smush-global.min.css', array(), WP_SMUSH_VERSION ); // Dismiss update info. WP_Smush::get_instance()->core()->mod->smush->dismiss_update_info(); } /** * Enqueue scripts. */ public function enqueue_scripts() { wp_enqueue_script( 'smush-global', WP_SMUSH_URL . 'app/assets/js/smush-global.min.js', array(), WP_SMUSH_VERSION, true ); wp_localize_script( 'smush-global', 'smush_global', array( 'nonce' => wp_create_nonce( 'wp-smush-ajax' ), ) ); $current_page = ''; $current_screen = ''; if ( function_exists( 'get_current_screen' ) ) { $current_screen = get_current_screen(); $current_page = ! empty( $current_screen ) ? $current_screen->base : $current_page; } if ( ! in_array( $current_page, Core::$external_pages, true ) && false === strpos( $current_page, 'page_smush' ) ) { return; } // Allows to disable enqueuing smush files on a particular page. if ( ! apply_filters( 'wp_smush_enqueue', true ) ) { return; } $this->register_scripts(); // Load on all Smush page only. if ( isset( $current_screen->id ) && ( in_array( $current_screen->id, self::$plugin_pages, true ) || false !== strpos( $current_screen->id, 'page_smush' ) ) ) { // Smush admin (smush-admin) includes the Shared UI. wp_enqueue_style( 'smush-admin' ); wp_enqueue_script( 'smush-wpmudev-sui' ); } if ( ! in_array( $current_page, array( 'post', 'post-new', 'page', 'edit-page' ), true ) ) { // Skip these pages where the script isn't used. wp_enqueue_script( 'smush-admin' ); } else { // Otherwise, load only the common JS code. wp_enqueue_script( 'smush-admin-common' ); } // We need it on media pages and Smush pages. wp_enqueue_style( 'smush-admin-common' ); // Localize translatable strings for js. WP_Smush::get_instance()->core()->localize(); } /** * Adds a Smush pro settings link on plugin page. * * @param array $links Current links. * * @return array|string */ public function settings_link( $links ) { // Upgrade link. if ( ! WP_Smush::is_pro() ) { $upgrade_url = add_query_arg( array( 'utm_source' => 'smush', 'utm_medium' => 'plugin', 'utm_campaign' => 'wp-smush-pro/wp-smush.php' !== WP_SMUSH_BASENAME ? 'smush_pluginlist_upgrade' : 'smush_pluginlist_renew', ), esc_url( 'https://wpmudev.com/project/wp-smush-pro/' ) ); $using_free_version = 'wp-smush-pro/wp-smush.php' !== WP_SMUSH_BASENAME; if ( $using_free_version ) { $label = __( 'Upgrade to Smush Pro', 'wp-smushit' ); $text = __( 'Upgrade for 60% off', 'wp-smushit' ); } else { $label = __( 'Renew Membership', 'wp-smushit' ); $text = __( 'Renew Membership', 'wp-smushit' ); } if ( isset( $text ) ) { $links['smush_upgrade'] = '' . esc_html( $text ) . ''; } } // Documentation link. $links['smush_docs'] = '' . esc_html__( 'Docs', 'wp-smushit' ) . ''; // Settings link. $settings_page = is_multisite() && is_network_admin() ? network_admin_url( 'admin.php?page=smush-settings' ) : menu_page_url( 'smush-settings', false ); $links['smush_dashboard'] = '' . esc_html__( 'Settings', 'wp-smushit' ) . ''; $access = get_site_option( 'wp-smush-networkwide' ); if ( ! is_network_admin() && is_plugin_active_for_network( WP_SMUSH_BASENAME ) && ! $access ) { // Remove settings link for subsites if Subsite Controls is not set on network permissions tab. unset( $links['smush_dashboard'] ); } return array_reverse( $links ); } /** * Add additional links next to the plugin version. * * @since 3.5.0 * * @param array $links Links array. * @param string $file Plugin basename. * * @return array */ public function add_plugin_meta_links( $links, $file ) { if ( ! defined( 'WP_SMUSH_BASENAME' ) || WP_SMUSH_BASENAME !== $file ) { return $links; } if ( 'wp-smush-pro/wp-smush.php' !== WP_SMUSH_BASENAME ) { $links[] = '' . esc_html__( 'Rate Smush', 'wp-smushit' ) . ''; $links[] = '' . esc_html__( 'Support', 'wp-smushit' ) . ''; } else { if ( isset( $links[2] ) && false !== strpos( $links[2], 'project/wp-smush-pro' ) ) { $links[2] = sprintf( '%s', __( 'View details', 'wp-smushit' ) ); } $links[] = '' . esc_html__( 'Premium Support', 'wp-smushit' ) . ''; } $links[] = '' . esc_html__( 'Roadmap', 'wp-smushit' ) . ''; return $links; } /** * Add menu pages. */ public function add_menu_pages() { $title = 'wp-smush-pro/wp-smush.php' === WP_SMUSH_BASENAME ? esc_html__( 'Smush Pro', 'wp-smushit' ) : esc_html__( 'Smush', 'wp-smushit' ); if ( Settings::can_access( false, true ) ) { $this->pages['smush'] = new Pages\Dashboard( 'smush', $title ); $this->pages['dashboard'] = new Pages\Dashboard( 'smush', __( 'Dashboard', 'wp-smushit' ), 'smush' ); if ( Abstract_Page::should_render( 'bulk' ) ) { $this->pages['bulk'] = new Pages\Bulk( 'smush-bulk', __( 'Bulk Smush', 'wp-smushit' ), 'smush' ); } if ( Abstract_Page::should_render( 'directory' ) ) { $this->pages['directory'] = new Pages\Directory( 'smush-directory', __( 'Directory Smush', 'wp-smushit' ), 'smush' ); } if ( Abstract_Page::should_render( 'lazy_load' ) ) { $this->pages['lazy-load'] = new Pages\Lazy( 'smush-lazy-load', __( 'Lazy Load', 'wp-smushit' ), 'smush' ); } if ( Abstract_Page::should_render( 'cdn' ) ) { $this->pages['cdn'] = new Pages\CDN( 'smush-cdn', __( 'CDN', 'wp-smushit' ), 'smush' ); } if ( Abstract_Page::should_render( 'webp' ) ) { $this->pages['webp'] = new Pages\WebP( 'smush-webp', __( 'Local WebP', 'wp-smushit' ), 'smush' ); } if ( Abstract_Page::should_render( 'integrations' ) ) { $this->pages['integrations'] = new Pages\Integrations( 'smush-integrations', __( 'Integrations', 'wp-smushit' ), 'smush' ); } if ( ! is_multisite() || is_network_admin() ) { $this->pages['settings'] = new Pages\Settings( 'smush-settings', __( 'Settings', 'wp-smushit' ), 'smush' ); } if ( ! apply_filters( 'wpmudev_branding_hide_doc_link', false ) && Abstract_Page::should_render( 'tutorials' ) ) { $this->pages['tutorials'] = new Pages\Tutorials( 'smush-tutorials', __( 'Tutorials', 'wp-smushit' ), 'smush' ); } if ( ! WP_Smush::is_pro() ) { $this->pages['smush-upgrade'] = new Pages\Upgrade( 'smush-upgrade', __( 'Smush Pro', 'wp-smushit' ), 'smush' ); } } // Add a bulk smush option for NextGen gallery. if ( defined( 'NGGFOLDER' ) && WP_Smush::get_instance()->core()->nextgen->is_enabled() && WP_Smush::is_pro() && ! is_network_admin() ) { $this->pages['nextgen'] = new Pages\Nextgen( 'wp-smush-nextgen-bulk', $title, NGGFOLDER, true ); } } /** * Add Smush Policy to "Privacy Policy" page during creation. * * @since 2.3.0 */ public function add_policy() { if ( ! function_exists( 'wp_add_privacy_policy_content' ) ) { return; } $content = '

' . __( 'Plugin: Smush', 'wp-smushit' ) . '

'; $content .= '

' . __( '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' ) . '

'; $content .= '

' . __( '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' ) . '

'; $content .= '

' . sprintf( /* translators: %1$s - opening , %2$s - closing */ __( "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' ), '', '' ) . '

'; if ( strpos( WP_SMUSH_DIR, 'wp-smushit' ) !== false ) { // Only for wordpress.org members. $content .= '

' . __( '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' ) . '

'; } wp_add_privacy_policy_content( __( 'WP Smush', 'wp-smushit' ), wp_kses_post( wpautop( $content, false ) ) ); } /** * Prints the Membership Validation issue notice */ public function media_library_membership_notice() { // No need to print it for free version. if ( ! WP_Smush::is_pro() ) { return; } // Show it on Media Library page only. $screen = get_current_screen(); if ( ! empty( $screen ) && ( 'upload' === $screen->id || in_array( $screen->id, self::$plugin_pages, true ) || false !== strpos( $screen->id, 'page_smush' ) ) ) { ?> id, 'page_smush-lazy-load' ) ) { return; } $dismissed = $this->is_notice_dismissed( 'plugin-conflict' ); if ( $dismissed ) { return; } $conflict_check = get_transient( 'wp-smush-conflict_check' ); // Have never checked before. if ( false === $conflict_check ) { wp_schedule_single_event( time(), 'smush_check_for_conflicts' ); return; } // No conflicting plugins detected. if ( isset( $conflict_check ) && is_array( $conflict_check ) && empty( $conflict_check ) ) { return; } array_walk( $conflict_check, function( &$item ) { $item = '' . $item . ''; } ); ?>

', $conflict_check ) ); ?>

', absint( $optimize_count ), '' ); } $reoptimize_message = ''; if ( 0 < $reoptimize_count ) { $reoptimize_message = sprintf( /* translators: 1. opening strong tag, 2: re-smush images count,3. closing strong tag. */ 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' ) ), '', esc_html( $reoptimize_count ), '' ); } $bulk_limit_free_message = $this->generate_bulk_limit_message_for_free( $remaining_count ); $image_count_description = sprintf( /* translators: 1. username, 2. unsmushed images message, 3. 'and' text for when having both unsmushed and re-smush images, 4. re-smush images message. */ __( '%1$s, you have %2$s%3$s%4$s! %5$s', 'wp-smushit' ), esc_html( Helper::get_user_name() ), $optimize_message, ( $optimize_message && $reoptimize_message ? esc_html__( ' and ', 'wp-smushit' ) : '' ), $reoptimize_message, $bulk_limit_free_message ); ?>

core(); $stats = $core->get_global_stats(); $global_stats = Global_Stats::get(); $remaining_count = $global_stats->get_remaining_count(); $optimize_count = $global_stats->get_optimize_list()->get_count(); $reoptimize_count = $global_stats->get_redo_count(); $stats['errors'] = Error_Handler::get_last_errors(); if ( $remaining_count > 0 ) { ob_start(); WP_Smush::get_instance()->admin()->print_pending_bulk_smush_content( $remaining_count, $reoptimize_count, $optimize_count ); $content = ob_get_clean(); $stats['content'] = $content; } return $stats; } public function get_global_stats_with_bulk_smush_content_and_notice() { $stats = $this->get_global_stats_with_bulk_smush_content(); $remaining_count = Global_Stats::get()->get_remaining_count(); if ( $remaining_count < 1 ) { $stats['notice'] = esc_html__( 'Yay! All images are optimized as per your current settings.', 'wp-smushit' ); $stats['noticeType'] = 'success'; } else { $stats['noticeType'] = 'warning'; $stats['notice'] = sprintf( /* translators: %1$d - number of images, %2$s - opening a tag, %3$s - closing a tag */ esc_html__( 'Image check complete, you have %1$d images that need smushing. %2$sBulk smush now!%3$s', 'wp-smushit' ), $remaining_count, '', '' ); } return $stats; } private function generate_bulk_limit_message_for_free( $remaining_count ) { $dont_limit = WP_Smush::get_instance()->core()->mod->bg_optimization->can_use_background(); if ( $dont_limit || $remaining_count < Core::MAX_FREE_BULK ) { return ''; } $upgrade_url = add_query_arg( array( 'utm_source' => 'smush', 'utm_medium' => 'plugin', 'utm_campaign' => 'smush_bulk_smush_pre_smush_50_limit', ), 'https://wpmudev.com/project/wp-smush-pro/' ); $batches = ceil( $remaining_count / Core::MAX_FREE_BULK ); $discount_text = ''. esc_html__( '60% off welcome discount available.', 'wp-smushit' ) .''; return sprintf( /* translators: 1: max free bulk limit, 2: Total batches to smush, 3: opening a tag, 4: closing a tag. */ 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' ), Core::MAX_FREE_BULK, $batches, '', '', $discount_text ); } /** * Add more pages to builtin wpmudev branding. * * @since 3.0 * * @param array $plugin_pages Nextgen pages is not introduced in built in wpmudev branding. * * @return array */ public function builtin_wpmudev_branding( $plugin_pages ) { $plugin_pages['gallery_page_wp-smush-nextgen-bulk'] = array( 'wpmudev_whitelabel_sui_plugins_branding', 'wpmudev_whitelabel_sui_plugins_footer', 'wpmudev_whitelabel_sui_plugins_doc_links', ); // There's a different page ID since NextGen 3.3.6. $plugin_pages['nextgen-gallery_page_wp-smush-nextgen-bulk'] = array( 'wpmudev_whitelabel_sui_plugins_branding', 'wpmudev_whitelabel_sui_plugins_footer', 'wpmudev_whitelabel_sui_plugins_doc_links', ); foreach ( $this->pages as $key => $value ) { $plugin_pages[ "smush-pro_page_smush-{$key}" ] = array( 'wpmudev_whitelabel_sui_plugins_branding', 'wpmudev_whitelabel_sui_plugins_footer', 'wpmudev_whitelabel_sui_plugins_doc_links', ); } return $plugin_pages; } public function is_notice_dismissed( $notice ) { $dismissed_notices = get_option( 'wp-smush-dismissed-notices', array() ); return ! empty( $dismissed_notices[ $notice ] ); } public function show_parallel_unavailability_notice() { $smush = WP_Smush::get_instance()->core()->mod->smush; $curl_multi_exec_available = $smush->curl_multi_exec_available(); $is_current_user_not_admin = ! current_user_can( 'manage_options' ); $is_not_bulk_smush_page = false === strpos( get_current_screen()->id, 'page_smush-bulk' ); $notice_hidden = $this->is_notice_dismissed( 'curl-multi-unavailable' ); if ( $curl_multi_exec_available || $is_current_user_not_admin || $is_not_bulk_smush_page || $notice_hidden ) { return; } $notice_text = sprintf( /* translators: %s: curl_multi_exec() */ 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' ), 'curl_multi_exec()' ); ?>


core()->mod->bg_optimization; $background_supported = $bg_optimization->is_background_supported(); $background_disabled = ! $bg_optimization->is_background_enabled(); $is_current_user_not_admin = ! current_user_can( 'manage_options' ); $is_not_bulk_smush_page = false === strpos( get_current_screen()->id, 'page_smush-bulk' ); $notice_hidden = $this->is_notice_dismissed( 'background-smush-unavailable' ); if ( $background_supported || $background_disabled || $is_current_user_not_admin || $is_not_bulk_smush_page || $notice_hidden ) { return; } $notice_text = sprintf( /* translators: 1: Current MYSQL version, 2: Required MYSQL version */ 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' ), $bg_optimization->get_actual_mysql_version(), $bg_optimization->get_required_mysql_version() ); ?>


is_notice_dismissed( 'php_deprecated' ) ) { return; } $php_version = PHP_VERSION; $required_php_version = '7.0'; if ( version_compare( $php_version, $required_php_version, '>=' ) ) { return; } /* translators: %1$s: Current PHP version */ $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 ); $error_message = '

' . $error_message . '

'; ?>