: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
* Reduce image file sizes, improve performance and boost your SEO using the free
* <a href="https://wpmudev.com/">WPMU DEV</a> WordPress Smush API.
* @link http://wpmudev.com/project/wp-smush-pro/
* Plugin URI: http://wordpress.org/plugins/wp-smushit/
* Description: Reduce image file sizes, improve performance and boost your SEO using the free <a href="https://wpmudev.com/">WPMU DEV</a> WordPress Smush API.
* Author URI: https://profiles.wordpress.org/wpmudev/
* License URI: https://www.gnu.org/licenses/gpl-2.0.html
* Text Domain: wp-smushit
* Domain Path: /languages/
This plugin was originally developed by Alex Dunae (http://dialect.ca/).
Copyright 2007-2022 Incsub (http://incsub.com)
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License (Version 2 - GPLv2) as published by
the Free Software Foundation.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
// If this file is called directly, abort.
if ( ! defined( 'WPINC' ) ) {
if ( ! defined( 'WP_SMUSH_VERSION' ) ) {
define( 'WP_SMUSH_VERSION', '3.16.6' );
// Used to define body class.
if ( ! defined( 'WP_SHARED_UI_VERSION' ) ) {
define( 'WP_SHARED_UI_VERSION', 'sui-2-12-23' );
if ( ! defined( 'WP_SMUSH_BASENAME' ) ) {
define( 'WP_SMUSH_BASENAME', plugin_basename( __FILE__ ) );
if ( ! defined( 'WP_SMUSH_API' ) ) {
define( 'WP_SMUSH_API', 'https://smushpro.wpmudev.com/1.0/' );
if ( ! defined( 'WP_SMUSH_UA' ) ) {
define( 'WP_SMUSH_UA', 'WP Smush/' . WP_SMUSH_VERSION . '; ' . network_home_url() );
if ( ! defined( 'WP_SMUSH_DIR' ) ) {
define( 'WP_SMUSH_DIR', plugin_dir_path( __FILE__ ) );
if ( ! defined( 'WP_SMUSH_URL' ) ) {
define( 'WP_SMUSH_URL', plugin_dir_url( __FILE__ ) );
if ( ! defined( 'WP_SMUSH_MAX_BYTES' ) ) {
define( 'WP_SMUSH_MAX_BYTES', 5242880 ); // 5MB
if ( ! defined( 'WP_SMUSH_PREMIUM_MAX_BYTES' ) ) {
define( 'WP_SMUSH_PREMIUM_MAX_BYTES', 268435456 );
if ( ! defined( 'WP_SMUSH_TIMEOUT' ) ) {
define( 'WP_SMUSH_TIMEOUT', 420 ); // 7 minutes
if ( ! defined( 'WP_SMUSH_RETRY_ATTEMPTS' ) ) {
define( 'WP_SMUSH_RETRY_ATTEMPTS', 3 );
if ( ! defined( 'WP_SMUSH_RETRY_WAIT' ) ) {
define( 'WP_SMUSH_RETRY_WAIT', 1 );
if ( ! defined( 'WP_SMUSH_PARALLEL' ) ) {
define( 'WP_SMUSH_PARALLEL', true );
if ( ! defined( 'WP_SMUSH_BACKGROUND' ) ) {
define( 'WP_SMUSH_BACKGROUND', true );
if ( ! defined( 'WP_SMUSH_MIN_PHP_VERSION' ) ) {
define( 'WP_SMUSH_MIN_PHP_VERSION', '7.4' );
if ( version_compare( PHP_VERSION, WP_SMUSH_MIN_PHP_VERSION, '<' ) ) {
if ( ! function_exists( 'wp_smush_php_deprecated_notice' ) ) {
function wp_smush_php_deprecated_notice() {
// Only show the deprecated notice for admin and only network side for MU site.
if ( ! current_user_can( 'manage_options' ) || ( is_multisite() && ! is_network_admin() ) ) {
<div class="notice notice-error is-dismissible">
wp_kses( /* translators: %1$s - Requires PHP version - %2$s URL to an article about our hosting benefits. */
__( 'Your site is running an outdated version of PHP that is no longer supported or receiving security updates. Please update PHP to at least version %1$s at your hosting provider in order to activate Smush, or consider switching to <a href="%2$s" target="_blank" rel="noopener noreferrer">WPMU DEV Hosting</a>.', 'wp-smushit' ),
esc_html( WP_SMUSH_MIN_PHP_VERSION ),
'https://wpmudev.com/hosting/'
deactivate_plugins( WP_SMUSH_BASENAME, false, is_network_admin() );
add_action( 'admin_notices', 'wp_smush_php_deprecated_notice' );
add_action( 'network_admin_notices', 'wp_smush_php_deprecated_notice' );
* To support Smushing on staging sites like SiteGround staging where staging site urls are different
* but redirects to main site url. Remove the protocols and www, and get the domain name.*
* If Set to false, WP Smush switch backs to the Old Sync Optimisation.
$site_url = str_replace( array( 'http://', 'https://', 'www.' ), '', site_url() );
// Compat with WPMU DEV staging.
$wpmu_host = isset( $_SERVER['WPMUDEV_HOSTING_ENV'] ) && 'staging' === sanitize_text_field( wp_unslash( $_SERVER['WPMUDEV_HOSTING_ENV'] ) );
if ( ! defined( 'WP_SMUSH_ASYNC' ) ) {
if ( ( ! empty( $_SERVER['SERVER_NAME'] ) && 0 !== strpos( $site_url, sanitize_text_field( wp_unslash( $_SERVER['SERVER_NAME'] ) ) ) ) || $wpmu_host ) {
define( 'WP_SMUSH_ASYNC', false );
define( 'WP_SMUSH_ASYNC', true );
* If we are activating a version, while having another present and activated.
* Leave in the Pro version, if it is available.
if ( WP_SMUSH_BASENAME !== plugin_basename( __FILE__ ) ) {
if ( file_exists( WP_PLUGIN_DIR . '/wp-smush-pro/wp-smush.php' ) ) {
if ( ! function_exists( 'is_plugin_active' ) ) {
include_once ABSPATH . 'wp-admin/includes/plugin.php';
if ( is_plugin_active( 'wp-smush-pro/wp-smush.php' ) ) {
deactivate_plugins( plugin_basename( __FILE__ ) );
update_site_option( 'smush_deactivated', 1 );
return; // Return to avoid errors with free-dashboard module.
} elseif ( $pro_installed && is_plugin_active( WP_SMUSH_BASENAME ) ) {
deactivate_plugins( WP_SMUSH_BASENAME );
// If WordPress is already in the process of activating - return.
if ( defined( 'WP_SANDBOX_SCRAPING' ) && WP_SANDBOX_SCRAPING ) {
activate_plugin( plugin_basename( __FILE__ ) );
/* @noinspection PhpIncludeInspection */
require_once WP_SMUSH_DIR . 'core/class-installer.php';
register_activation_hook( __FILE__, array( 'Smush\\Core\\Installer', 'smush_activated' ) );
register_deactivation_hook( __FILE__, array( 'Smush\\Core\\Installer', 'smush_deactivated' ) );
register_activation_hook( __FILE__, function () {
update_option( 'wp-smush-plugin-activated', true );
// Init the plugin and load the plugin instance for the first time.
add_action( 'plugins_loaded', array( 'WP_Smush', 'get_instance' ) );
if ( ! class_exists( 'WP_Smush' ) ) {
private static $instance = null;
* @var Smush\Core\Api\Smush_API
* @var Smush\App\Media_Library
* Stores the value of validate_install function.
* Return the plugin instance.
public static function get_instance() {
if ( ! self::$instance ) {
self::$instance = new self();
private function __construct() {
spl_autoload_register( array( $this, 'autoload' ) );
add_action( 'admin_init', array( '\\Smush\\Core\\Installer', 'upgrade_settings' ) );
add_action( 'current_screen', array( '\\Smush\\Core\\Installer', 'maybe_create_table' ) );
// We use priority 9 to avoid conflict with old free-dashboard module <= 2.0.4.
add_action( 'admin_init', array( $this, 'register_free_modules' ), 9 );
// The dash-notification actions are hooked into "init" with a priority of 10.
add_action( 'init', array( $this, 'register_pro_modules' ), 5 );
add_action( 'init', array( $this, 'do_plugin_activated_action' ) );
public function do_plugin_activated_action() {
$transient_key = 'wp-smush-plugin-activated';
if ( ! get_option( $transient_key ) ) {
( new \Smush\Core\Modules\Background\Mutex( $transient_key ) )
->set_break_on_timeout( true )
->execute( function () use ( $transient_key ) {
// The get_option call we made above has added the "true" value to the cache,
// get_option is always going to return true even if the option was deleted in another thread,
// now we need use a thread safe method instead
$background_utils = new \Smush\Core\Modules\Background\Background_Utils();
if ( $background_utils->get_option( $transient_key, false ) ) {
do_action( 'wp_smush_plugin_activated' );
delete_option( $transient_key );
* @param string $class Class name to autoload.
public function autoload( $class ) {
// Project-specific namespace prefix.
// Does the class use the namespace prefix?
$len = strlen( $prefix );
if ( 0 !== strncmp( $prefix, $class, $len ) ) {
// Maybe require some external classes.
$external_libs = array( 'WDEV_Logger' );
if ( in_array( $class, $external_libs, true ) ) {
$lib = str_replace( '_', '-', strtolower( $class ) );
$file = WP_SMUSH_DIR . "core/external/{$lib}/{$lib}.php";
if ( file_exists( $file ) ) {
// No, move to the next registered autoloader.
// Get the relative class name.
$relative_class = substr( $class, $len );
$path = explode( '\\', strtolower( str_replace( '_', '-', $relative_class ) ) );
$file = array_pop( $path );
$file = WP_SMUSH_DIR . implode( '/', $path ) . '/class-' . $file . '.php';
// If the file exists, require it.
if ( file_exists( $file ) ) {
/* @noinspection PhpIncludeInspection */
private function init() {
$this->api = new Smush\Core\Api\Smush_API( Smush\Core\Helper::get_wpmudev_apikey() );
} catch ( Exception $e ) {
// Handle failed items, load it before validate the install.
new Smush\Core\Error_Handler();
$this->validate_install();
$this->core = new Smush\Core\Core();
$this->library = new Smush\App\Media_Library( $this->core() );
$this->admin = new Smush\App\Admin( $this->library() );
if ( defined( 'WP_CLI' ) && WP_CLI ) {
WP_CLI::add_command( 'smush', '\\Smush\\Core\\CLI' );
* Getter method for core.
* @return Smush\Core\Core
* Getter method for core.
* @return Smush\App\Admin
public function admin() {
* Getter method for core.
* @return Smush\Core\Api\Smush_API
* Getter method for library.
* @return Smush\App\Media_Library
public function library() {
public static function is_pro() {
public static function is_expired() {
return ! self::is_pro() && Smush\Core\Helper::get_wpmudev_apikey();
public static function is_new_user() {
return ! self::is_pro() && ! self::is_expired();
* Verify the site is connected to TFH.
public static function is_site_connected_to_tfh() {
return isset( $_SERVER['WPMUDEV_HOSTED'] )
&& class_exists( '\WPMUDEV_Dashboard' ) && is_object( \WPMUDEV_Dashboard::$api )
&& method_exists( \WPMUDEV_Dashboard::$api, 'get_membership_status' )
&& 'free' === \WPMUDEV_Dashboard::$api->get_membership_status();
public static function is_member() {
return self::is_pro() || self::is_site_connected_to_tfh();
* Only for wordpress.org members.
public function register_free_modules() {
if ( false === strpos( WP_SMUSH_DIR, 'wp-smushit' ) || class_exists( 'WPMUDEV_Dashboard' ) || file_exists( WP_PLUGIN_DIR . '/wpmudev-updates/update-notifications.php' ) ) {
/* @noinspection PhpIncludeInspection */
require_once WP_SMUSH_DIR . 'core/external/free-dashboard/module.php';
/* @noinspection PhpIncludeInspection */
require_once WP_SMUSH_DIR . 'core/external/plugin-notice/notice.php';
// Add the Mailchimp group value.
'frash_subscribe_form_fields',
function ( $mc_list_id ) {
if ( '4b14b58816' === $mc_list_id ) {
echo '<input type="hidden" id="mce-group[53]-53-1" name="group[53][2]" value="2" />';
// Register the current plugin.
'wpmudev_register_notices',
'basename' => WP_SMUSH_BASENAME, // Required: Plugin basename (for backward compat).
'title' => 'Smush', // Required: Plugin title.
'wp_slug' => 'wp-smushit', // Required: wp.org slug of the plugin.
'cta_email' => __( 'Get Fast!', 'wp-smushit' ), // Email button CTA.
'installed_on' => time(), // Optional: Plugin activated time.
'screens' => array( // Required: Plugin screen ids.
add_filter( 'wpmudev_notices_is_disabled', array( $this, 'enable_free_tips_opt_in' ), 10, 3 );
// The email message contains 1 variable: plugin-name.
'wdev_email_message_' . WP_SMUSH_BASENAME,
return "You're awesome for installing %s! Make sure you get the most out of it, boost your Google PageSpeed score with these tips and tricks - just for users of Smush!";
// Recommended plugin notice.