diff --git a/README.txt b/README.txt index 3a4e3cb..daf95a7 100644 --- a/README.txt +++ b/README.txt @@ -3,8 +3,8 @@ Plugin Name: Convert WebP & AVIF | Quicq | Best image optimizer and compression Contributors: kyanoapp Tags: convert webp, convert AVIF, image optimization, optimize images, resize images, compress images, webp, AVIF, image optimizer, image compress, image optimize, webp format, AVIF format Requires at least: 5.3 -Tested up to: 5.9.0 -Stable tag: 1.5.0 +Tested up to: 6.0.1 +Stable tag: 1.6.0 Requires PHP: 5.6.20 License: GPLv2 or later License URI: https://www.gnu.org/licenses/gpl-2.0.html @@ -264,6 +264,13 @@ The Free forever plan provides 25gb and 100.000 optimizations per month. Thus, a == Changelog == += 1.6.0 (2022-07-26) = + +- Fix: Fixed a regression bug that occurred when a previous version lower then 1.4.0 was installed +- Enhance: improved the parsing of images +- Enhance: improved the update process of a quicq proxy + + = 1.5.0 (2022-07-13) = - Enhance: updated the path Quicq proxy uses to /wp-content instead of /wp-content/uploads diff --git a/quicq.php b/quicq.php index 8adbc9f..098a969 100644 --- a/quicq.php +++ b/quicq.php @@ -3,7 +3,7 @@ * Plugin Name: Quicq for WebP images * Plugin URI: https://afosto.com/apps/quicq/ * Description: Quicq integration for Wordpress. - * Version: 1.5.0 + * Version: 1.6.0 * Author: Afosto * Author URI: https://afosto.com * Domain Path: /languages @@ -31,9 +31,17 @@ /** * hook that defines if quicq is active - * @since 1.4 + * @since 1.6 */ -add_action( 'init', 'quicq_active', 1 ); +if ( ! is_admin() && get_option( 'quicq_enabled' ) == 1 ) { + add_filter( 'the_content', 'quicq_activated' ); +} + +/** + * hook that defines if quicq is active + * @since 1.6 + */ +add_action( 'init', 'quicq_version_check', 2 ); /** * added hooks when deactivating and removing * @since 1.2 @@ -43,66 +51,55 @@ register_activation_hook( __FILE__, 'quicq_activate' ); /** - * hook that handles updates - * @since 1.4.3 + * hook that checks if there plugin has been updated + * @since 1.6.0 */ -add_action( 'upgrader_process_complete', 'quicq_upgrader_process_complete', 10, 2 ); - - - - -if ( ! function_exists( ' quicq_upgrader_process_complete' ) ) { - function quicq_upgrader_process_complete( $upgrader_object, $options ) { - $current_plugin_path_name = plugin_basename( __FILE__ ); - - if ( $options['action'] == 'update' && $options['type'] == 'plugin' ) { - foreach ( $options['plugins'] as $each_plugin ) { - if ( $each_plugin == $current_plugin_path_name ) { - // Set a transient to record that our plugin has just been updated - set_transient( 'wp_quicq_updated', 1 ); - } +if ( ! function_exists( 'quicq_version_check' ) ) { + function quicq_version_check() { + if ( get_option( 'quicq_enabled' ) == 1 ) { + $currentVersion = null; + if ( preg_match( '/\*[\s\t]+?version:[\s\t]+?([0-9.]+)/i', file_get_contents( __FILE__ ), $v ) ) { + $currentVersion = $v[1]; + } + if ( $currentVersion != null && strcasecmp( $currentVersion, get_option( "quicq_version" ) ) != 0 ) { + quicq_trigger_update( $currentVersion ); } } } } - /** * notifies Quicq about the version update so it can match the plugin version + * @since 1.6.0 */ -if ( ! function_exists( ' quicq_trigger_update' ) ) { - function quicq_trigger_update() { +if ( ! function_exists( 'quicq_trigger_update' ) ) { + function quicq_trigger_update( $plugin_version ) { // Check the transient to see if we've just updated the plugin - if ( get_transient( 'wp_quicq_updated' ) ) { - global $wp_version; - $plugin_version = null; - if ( preg_match( '/\*[\s\t]+?version:[\s\t]+?([0-9.]+)/i', file_get_contents( __FILE__ ), $v ) ) { - $plugin_version = $v[1]; - } + global $wp_version; + $siteKey = str_replace( "https://cdn.quicq.io/", "", get_option( 'quicq_key' ) ); + + wp_remote_request( sprintf( "https://afosto.app/api/storage/quicq/proxies/%s/wordpress/upgrade", $siteKey ), [ + "method" => "PUT", + "headers" => [ + "content-type" => "application/vnd.afosto.api.v1+json" + ], + "body" => json_encode( [ + "data" => [ + "site_key" => $siteKey, + "version" => $plugin_version, + "site_url" => site_url(), + "wordpress_version" => $wp_version, + ] + ] ) + ] + ); - $siteKey = str_replace( "https://cdn.quicq.io/", "", get_option( 'quicq_key' ) ); - wp_remote_request( sprintf( "https://afosto.app/api/storage/quicq/proxies/%s/wordpress/upgrade", $siteKey ), [ - "method" => "PUT", - "headers" => [ - "content-type" => "application/vnd.afosto.api.v1+json" - ], - "body" => json_encode( [ - "data" => [ - "site_key" => $siteKey, - "version" => $plugin_version, - "site_url" => site_url(), - "wordpress_version" => $wp_version, - ] - ] ) - ] - ); - delete_transient( 'wp_quicq_updated' ); - } + update_option("quicq_version",$plugin_version); } - quicq_trigger_update(); } + if ( isset( $_GET['page'] ) ) { if ( $_GET['page'] == 'quicq_adminpage' ) { add_action( 'admin_enqueue_scripts', 'quicq_add_styles', 0 ); @@ -112,7 +109,7 @@ function quicq_trigger_update() { * Multilanguage function * @since 1.0.0 */ -if ( ! function_exists( ' quicq_load_textdomain' ) ) { +if ( ! function_exists( 'quicq_load_textdomain' ) ) { function quicq_load_textdomain() { if ( is_textdomain_loaded( 'quicq' ) ) { return; @@ -126,7 +123,7 @@ function quicq_load_textdomain() { * function that starts the content rewrite if quicq is enabled * @since 1.0.0 */ -if ( ! function_exists( ' quicq_active' ) ) { +if ( ! function_exists( 'quicq_active' ) ) { function quicq_active() { if ( get_option( 'quicq_enabled' ) == 1 && ! is_admin() ) { ob_start( "quicq_activated" ); @@ -138,7 +135,7 @@ function quicq_active() { * function that rewrites the the urls within the html content * @since 1.4.0 */ -if ( ! function_exists( ' quicq_activated' ) ) { +if ( ! function_exists( 'quicq_activated' ) ) { function quicq_activated( $content ) { $content = preg_replace_callback( '/(https?:\/\/(www\.)?[-a-zA-Z0-9@:%._+~#=]{1,256}(\.[a-zA-Z0-9()]{1,6}|:\d+)\b([-a-zA-Z0-9()@:%_+.~#?&\/\/=]*))(.png|.jpe?g|webp|.svg)/', 'quicq_rewrite_url', $content ); @@ -150,7 +147,7 @@ function quicq_activated( $content ) { * function thar replaces an wp-content url to the quicq cdn url * @since 1.4.0 */ -if ( ! function_exists( ' quicq_rewrite_url' ) ) { +if ( ! function_exists( 'quicq_rewrite_url' ) ) { function quicq_rewrite_url( $images ) { $quicq_url = get_option( 'quicq_key' ); foreach ( $images as &$imageUrl ) { @@ -166,7 +163,7 @@ function quicq_rewrite_url( $images ) { * function for when the plugin is being deactivated * @since 1.2.0 */ -if ( ! function_exists( ' quicq_deactivate' ) ) { +if ( ! function_exists( 'quicq_deactivate' ) ) { function quicq_deactivate() { update_option( 'quicq_enabled', 0 ); } @@ -176,7 +173,7 @@ function quicq_deactivate() { * function for when the plugin is being deactivated * @since 1.2.0 */ -if ( ! function_exists( ' quicq_activate' ) ) { +if ( ! function_exists( 'quicq_activate' ) ) { function quicq_activate() { if ( get_option( 'quicq_key' ) != "" ) { update_option( 'quicq_enabled', 1 ); @@ -189,7 +186,7 @@ function quicq_activate() { * function which uninstalls the plugin, removes traces for settings * @since 1.2.0 */ -if ( ! function_exists( ' quicq_uninstall' ) ) { +if ( ! function_exists( 'quicq_uninstall' ) ) { function quicq_uninstall() { delete_option( 'quicq_enabled' ); delete_option( 'quicq_key' ); @@ -203,7 +200,7 @@ function quicq_uninstall() { * @since 1.0.0 */ -if ( ! function_exists( ' quicq_add_styles' ) ) { +if ( ! function_exists( 'quicq_add_styles' ) ) { function quicq_add_styles() { $plugin_url = plugin_dir_url( __FILE__ ); @@ -219,7 +216,7 @@ function quicq_add_styles() { * Adds quicq settings page * @since 1.0 */ -if ( ! function_exists( ' quicq_init_page' ) ) { +if ( ! function_exists( 'quicq_init_page' ) ) { function quicq_init_page() { $plugin_url = plugin_dir_url( __FILE__ ); $imageurl = $plugin_url . 'images/quicqicon.png'; @@ -239,7 +236,7 @@ function quicq_init_page() { * Adds quicq settings * @since 1.0 */ -if ( ! function_exists( ' quicq_add_settings' ) ) { +if ( ! function_exists( 'quicq_add_settings' ) ) { function quicq_add_settings() { register_setting( 'quicq-page', 'quicq_enabled' ); register_setting( 'quicq-page', 'quicq_key' ); @@ -251,19 +248,19 @@ function quicq_add_settings() { * Quicq SVG logo * @since 1.0 */ -if ( ! function_exists( ' quicq_logo' ) ) { +if ( ! function_exists( 'quicq_logo' ) ) { function quicq_logo() { echo ''; } } -if ( ! function_exists( ' quicq_doc_icon' ) ) { +if ( ! function_exists( 'quicq_doc_icon' ) ) { function quicq_doc_icon() { echo ''; } } -if ( ! function_exists( ' quicq_arrow_icon' ) ) { +if ( ! function_exists( 'quicq_arrow_icon' ) ) { function quicq_arrow_icon() { echo ''; } @@ -273,7 +270,7 @@ function quicq_arrow_icon() { * Adds quicq menu style * @since 1.0 */ -if ( ! function_exists( ' quicq_plugin_style' ) ) { +if ( ! function_exists( 'quicq_plugin_style' ) ) { function quicq_plugin_style() { ?>