| @@ -1,28 +1,50 @@ | ||
| 1 | 1 | <?php |
| 2 | 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. | |
| 3 | + * Plugin Name: Image Optimization - Optimize Images and Convert to WebP or AVIF | |
| 4 | + * Description: Automatically resize, optimize, and convert images to WebP and AVIF. Compress images in bulk or on upload to boost your WordPress site performance. | |
| 5 | 5 | * Plugin URI: https://go.elementor.com/wp-repo-description-tab-io-product-page/ |
| 6 | - * Version: 1.5.0 | |
| 6 | + * Version: 1.7.7 | |
| 7 | 7 | * Author: Elementor.com |
| 8 | - * Author URI: https://go.elementor.com/wp-repo-description-tab-io-author-url/ | |
| 8 | + * Author URI: https://go.elementor.com/author-uri-io/ | |
| 9 | 9 | * Text Domain: image-optimization |
| 10 | 10 | * License: GPL-3 |
| 11 | 11 | * License URI: https://www.gnu.org/licenses/gpl-3.0.en.html |
| 12 | + * | |
| 13 | + * Image Optimization is free software: you can redistribute it and/or modify | |
| 14 | + * it under the terms of the GNU General Public License as published by | |
| 15 | + * the Free Software Foundation, either version 3 of the License, or | |
| 16 | + * any later version. | |
| 17 | + * | |
| 18 | + * Image Optimization is distributed in the hope that it will be useful, | |
| 19 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 20 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 21 | + * GNU General Public License for more details. | |
| 12 | 22 | */ |
| 13 | 23 | |
| 24 | +use ImageOptimization\Modules\Core\Module as CoreModule; | |
| 25 | + | |
| 14 | 26 | if ( ! defined( 'ABSPATH' ) ) { |
| 15 | 27 | exit; // Exit if accessed directly. |
| 16 | 28 | } |
| 17 | 29 | |
| 18 | -define( 'IMAGE_OPTIMIZATION_VERSION', '1.5.0' ); | |
| 19 | -define( 'IMAGE_OPTIMIZATION_PATH', plugin_dir_path( __FILE__ ) ); | |
| 20 | -define( 'IMAGE_OPTIMIZATION_URL', plugins_url( '/', __FILE__ ) ); | |
| 30 | +define( 'IMAGE_OPTIMIZATION_VERSION', '1.7.7' ); | |
| 31 | +define( 'IMAGE_OPTIMIZATION_FILE', __FILE__ ); | |
| 32 | +define( 'IMAGE_OPTIMIZATION_PATH', plugin_dir_path( IMAGE_OPTIMIZATION_FILE ) ); | |
| 33 | +define( 'IMAGE_OPTIMIZATION_URL', plugins_url( '/', IMAGE_OPTIMIZATION_FILE ) ); | |
| 21 | 34 | define( 'IMAGE_OPTIMIZATION_ASSETS_PATH', IMAGE_OPTIMIZATION_PATH . 'assets/' ); |
| 22 | 35 | define( 'IMAGE_OPTIMIZATION_ASSETS_URL', IMAGE_OPTIMIZATION_URL . 'assets/' ); |
| 23 | -define( 'IMAGE_OPTIMIZATION_PLUGIN_FILE', basename( __FILE__ ) ); | |
| 36 | +define( 'IMAGE_OPTIMIZATION_PLUGIN_FILE', plugin_basename( IMAGE_OPTIMIZATION_FILE ) ); | |
| 24 | 37 | |
| 38 | +if ( ! defined( 'IMAGE_OPTIMIZATION_MINIMUM_LOG_LEVEL' ) ) { | |
| 39 | + define( 'IMAGE_OPTIMIZATION_MINIMUM_LOG_LEVEL', 3 ); | |
| 40 | +} | |
| 41 | + | |
| 42 | +register_deactivation_hook( | |
| 43 | + __FILE__, | |
| 44 | + [ CoreModule::class, 'on_deactivation' ] | |
| 45 | +); | |
| 46 | + | |
| 25 | 47 | /** |
| 26 | 48 | * ImageOptimization Class |
| 27 | 49 | */ |
| 28 | 50 | final class ImageOptimization { |
| @@ -38,10 +60,9 @@ | ||
| 38 | 60 | * |
| 39 | 61 | * @access public |
| 40 | 62 | */ |
| 41 | 63 | public function __construct() { |
| 42 | - // Load translation | |
| 43 | - add_action( 'plugins_loaded', [ $this, 'i18n' ] ); | |
| 64 | + require_once IMAGE_OPTIMIZATION_PATH . 'vendor/autoload.php'; | |
| 44 | 65 | |
| 45 | 66 | // Init Plugin |
| 46 | 67 | add_action( 'plugins_loaded', [ $this, 'init' ], -11 ); |
| 47 | 68 | } |
| @@ -46,19 +67,8 @@ | ||
| 46 | 67 | add_action( 'plugins_loaded', [ $this, 'init' ], -11 ); |
| 47 | 68 | } |
| 48 | 69 | |
| 49 | 70 | /** |
| 50 | - * Load plugin localization files. | |
| 51 | - * | |
| 52 | - * Fired by `plugins_loaded` action hook. | |
| 53 | - * | |
| 54 | - * @access public | |
| 55 | - */ | |
| 56 | - public function i18n() { | |
| 57 | - load_plugin_textdomain( 'image-optimization' ); | |
| 58 | - } | |
| 59 | - | |
| 60 | - /** | |
| 61 | 71 | * Checks if all requirements met to safely start the plugin and renders admin notices |
| 62 | 72 | * if something is not right. |
| 63 | 73 | * |
| 64 | 74 | * @access public |
| @@ -137,16 +147,30 @@ | ||
| 137 | 147 | |
| 138 | 148 | return $output; |
| 139 | 149 | } |
| 140 | 150 | |
| 151 | + /** | |
| 152 | + * The check is strictly based on the action scheduler requirements that needs JSON partial matching to work | |
| 153 | + * with action queries. | |
| 154 | + * | |
| 155 | + * @return bool | |
| 156 | + */ | |
| 141 | 157 | public function is_db_json_supported(): bool { |
| 142 | 158 | global $wpdb; |
| 143 | 159 | |
| 144 | - $result = $wpdb->query(" | |
| 145 | - SELECT JSON_EXTRACT('[1, 2]', '$[1]'); | |
| 146 | - "); | |
| 160 | + $db_server_info = is_callable( array( $wpdb, 'db_server_info' ) ) ? $wpdb->db_server_info() : $wpdb->db_version(); | |
| 147 | 161 | |
| 148 | - return false !== $result; | |
| 162 | + if ( false !== strpos( $db_server_info, 'MariaDB' ) ) { | |
| 163 | + $supports_json = version_compare( | |
| 164 | + PHP_VERSION_ID >= 80016 ? $wpdb->db_version() : preg_replace( '/[^0-9.].*/', '', str_replace( '5.5.5-', '', $db_server_info ) ), | |
| 165 | + '10.2', | |
| 166 | + '>=' | |
| 167 | + ); | |
| 168 | + } else { | |
| 169 | + $supports_json = version_compare( $wpdb->db_version(), '5.7', '>=' ); | |
| 170 | + } | |
| 171 | + | |
| 172 | + return (bool) $supports_json; | |
| 149 | 173 | } |
| 150 | 174 | |
| 151 | 175 | /** |
| 152 | 176 | * Renders an admin notice if the setup did not meet requirements. |
| @@ -158,9 +182,9 @@ | ||
| 158 | 182 | */ |
| 159 | 183 | public function add_requirements_error() { |
| 160 | 184 | $message = sprintf( |
| 161 | 185 | '<h3>%s</h3>', |
| 162 | - esc_html__( 'Image Optimizer isn’t running because:', 'image-optimization' ) | |
| 186 | + esc_html__( 'Image Optimization isn’t running because:', 'image-optimization' ) | |
| 163 | 187 | ); |
| 164 | 188 | |
| 165 | 189 | $message .= '<ul>'; |
| 166 | 190 | |