| 1 |
<?php |
| 2 |
/** |
| 3 |
* Plugin Name: Image Optimizer by Elementor – Compress, Resize and Optimize Images |
| 4 |
* Description: Automatically compress and enhance your images, boosting your website speed, appearance, and SEO. Get Image Optimizer and optimize your images in seconds. |
| 5 |
* Plugin URI: https://go.elementor.com/wp-repo-description-tab-io-product-page/ |
| 6 |
* Version: 1.1.0 |
| 7 |
* Author: Elementor.com |
| 8 |
* Author URI: https://go.elementor.com/wp-repo-description-tab-io-author-url/ |
| 9 |
* Text Domain: image-optimization |
| 10 |
* License: GPL-3 |
| 11 |
* License URI: https://www.gnu.org/licenses/gpl-3.0.en.html |
| 12 |
*/ |
| 13 |
|
| 14 |
if ( ! defined( 'ABSPATH' ) ) { |
| 15 |
exit; // Exit if accessed directly. |
| 16 |
} |
| 17 |
|
| 18 |
define( 'IMAGE_OPTIMIZATION_VERSION', '1.1.0' ); |
| 19 |
define( 'IMAGE_OPTIMIZATION_PATH', plugin_dir_path( __FILE__ ) ); |
| 20 |
define( 'IMAGE_OPTIMIZATION_URL', plugins_url( '/', __FILE__ ) ); |
| 21 |
define( 'IMAGE_OPTIMIZATION_ASSETS_PATH', IMAGE_OPTIMIZATION_PATH . 'assets/' ); |
| 22 |
define( 'IMAGE_OPTIMIZATION_ASSETS_URL', IMAGE_OPTIMIZATION_URL . 'assets/' ); |
| 23 |
define( 'IMAGE_OPTIMIZATION_PLUGIN_FILE', basename( __FILE__ ) ); |
| 24 |
|
| 25 |
/** |
| 26 |
* ImageOptimization Class |
| 27 |
*/ |
| 28 |
final class ImageOptimization { |
| 29 |
private const REQUIRED_EXTENSIONS = [ |
| 30 |
'exif', |
| 31 |
'fileinfo', |
| 32 |
'gd', |
| 33 |
]; |
| 34 |
|
| 35 |
/** |
| 36 |
* Constructor |
| 37 |
* |
| 38 |
* @access public |
| 39 |
*/ |
| 40 |
public function __construct() { |
| 41 |
// Load translation |
| 42 |
add_action( 'init', [ $this, 'i18n' ] ); |
| 43 |
|
| 44 |
// Init Plugin |
| 45 |
add_action( 'plugins_loaded', [ $this, 'init' ], -11 ); |
| 46 |
} |
| 47 |
|
| 48 |
/** |
| 49 |
* Load Textdomain |
| 50 |
* |
| 51 |
* Load plugin localization files. |
| 52 |
* Fired by `init` action hook. |
| 53 |
* |
| 54 |
* @access public |
| 55 |
*/ |
| 56 |
public function i18n() { |
| 57 |
load_plugin_textdomain( 'image-optimization' ); |
| 58 |
} |
| 59 |
|
| 60 |
public function insufficient_php_version() { |
| 61 |
$message = sprintf( |
| 62 |
/* translators: 1: `<h3>` opening tag, 2: `</h3>` closing tag, 3: PHP version. 4: Link opening tag, 5: Link closing tag. */ |
| 63 |
esc_html__( '%1$sImage Optimizer isn’t running because PHP is outdated.%2$s Update to PHP version %3$s and get back to optimizing! %4$sShow me how%5$s', 'image-optimization' ), |
| 64 |
'<h3>', |
| 65 |
'</h3>', |
| 66 |
'7.4', |
| 67 |
'<a href="https://go.elementor.com/wp-dash-update-php/" target="_blank">', |
| 68 |
'</a>' |
| 69 |
); |
| 70 |
$html_message = sprintf( '<div class="error">%s</div>', wpautop( $message ) ); |
| 71 |
echo wp_kses_post( $html_message ); |
| 72 |
} |
| 73 |
|
| 74 |
private function get_missed_extensions_list(): array { |
| 75 |
$output = []; |
| 76 |
|
| 77 |
foreach ( self::REQUIRED_EXTENSIONS as $extension ) { |
| 78 |
if ( ! extension_loaded( $extension ) ) { |
| 79 |
$output[] = $extension; |
| 80 |
} |
| 81 |
} |
| 82 |
|
| 83 |
return $output; |
| 84 |
} |
| 85 |
|
| 86 |
public function add_missed_extensions_notice() { |
| 87 |
$missed_extensions = $this->get_missed_extensions_list(); |
| 88 |
|
| 89 |
$message = sprintf( |
| 90 |
/* translators: 1: `<h3>` opening tag, 2: Missed extension names, 3: `</h3>` closing tag. */ |
| 91 |
esc_html__( '%1$sImage Optimizer isn’t running because the next required PHP extensions are missed: %2$s.%3$s', 'image-optimization' ), |
| 92 |
'<h3>', |
| 93 |
implode( ', ', $missed_extensions ), |
| 94 |
'</h3>', |
| 95 |
); |
| 96 |
|
| 97 |
$html_message = sprintf( '<div class="error">%s</div>', wpautop( $message ) ); |
| 98 |
|
| 99 |
echo wp_kses_post( $html_message ); |
| 100 |
} |
| 101 |
|
| 102 |
/** |
| 103 |
* Initialize the plugin |
| 104 |
* |
| 105 |
* Validates that PHP version is sufficient. |
| 106 |
* Checks for basic plugin requirements, if one check fail don't continue, |
| 107 |
* if all check have passed include the plugin class. |
| 108 |
* |
| 109 |
* Fired by `plugins_loaded` action hook. |
| 110 |
* |
| 111 |
* @since 1.2.0 |
| 112 |
* @access public |
| 113 |
*/ |
| 114 |
public function init() { |
| 115 |
if ( ! version_compare( PHP_VERSION, '7.4', '>=' ) ) { |
| 116 |
add_action( 'admin_notices', [ $this, 'insufficient_php_version' ] ); |
| 117 |
} else if ( count( $this->get_missed_extensions_list() ) ) { |
| 118 |
add_action( 'admin_notices', [ $this, 'add_missed_extensions_notice' ] ); |
| 119 |
} else { |
| 120 |
// Once we get here, We have passed all validation checks, so we can safely include our plugin |
| 121 |
require_once 'plugin.php'; |
| 122 |
} |
| 123 |
} |
| 124 |
} |
| 125 |
|
| 126 |
// Instantiate ImageOptimization.. |
| 127 |
new ImageOptimization(); |
| 128 |
|