Plugin Directory

Changeset 3410763


Ignore:
Timestamp:
12/04/2025 11:06:44 AM (10 days ago)
Author:
ignatggeorgiev
Message:

Bump to 7.7.5

Location:
sg-cachepress/trunk
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • sg-cachepress/trunk/core/Combinator/Abstract_Combinator.php

    r3090872 r3410763  
    204204        return $file_content;
    205205    }
     206
     207    /**
     208     * Removes the host and query stings from an URL to get the source.
     209     *
     210     * @param $url The URL to prepare.
     211     *
     212     * @return string The URL src.
     213     */
     214    public function prepare_url_src( $url ) {
     215        // Strips the URL from its host and query strings.
     216        return trim( str_replace( Helper_Service::get_site_url(), '', strtok( $url, '?' ) ), "/\\" );
     217    }
    206218}
  • sg-cachepress/trunk/core/Combinator/Css_Combinator.php

    r3174268 r3410763  
    182182            }
    183183
    184             // Replace the site URL and get the src.
    185             $excluded[] = trim( str_replace( Helper_Service::get_site_url(), '', strtok( $wp_styles->registered[ $handle ]->src, '?' ) ), '/\\' );
     184            // Remove the query stings and the host to get the source.
     185            $excluded[] = $this->prepare_url_src( $wp_styles->registered[ $handle ]->src );
    186186        }
    187187
     
    208208        }
    209209
    210         // Get the host from src..
     210        // Get the host from src.
    211211        $host = wp_parse_url( $style[2], PHP_URL_HOST );
    212212
     
    219219        }
    220220
    221         // Remove query strings from the URL.
    222         $src  = Front_End_Optimization::remove_query_strings( $style[2] );
    223 
    224         // Bail if the url is excluded.
    225         if ( in_array( str_replace( trailingslashit( Helper_Service::get_site_url() ), '', $src ), $this->excluded_urls ) ) {
     221        // Remove the query stings and the host to get the source.
     222        $src = $this->prepare_url_src( $style[2] );
     223
     224        // Bail if the URL is excluded.
     225        if ( in_array( $src, $this->excluded_urls ) ) {
    226226            return true;
    227227        }
  • sg-cachepress/trunk/core/Combinator/Js_Combinator.php

    r3204886 r3410763  
    519519    public $excluded_ids = array(
    520520        '@wordpress/block-library/navigation-js-module',
     521        '@wordpress/block-library/navigation/view-js-module',
    521522    );
    522523
  • sg-cachepress/trunk/core/Images_Optimizer/Images_Optimizer_Webp.php

    r2698959 r3410763  
    119119
    120120    /**
    121      * Check if image exists and perform optimiation.
     121     * Check if image exists and perform optimization.
    122122     *
    123123     * @since  5.0.0
     
    128128     */
    129129    public static function generate_webp_file( $filepath ) {
    130         // Bail if the file doens't exists or if the webp copy already exists.
     130        // Bail if the file doesn't exists or if the webp copy already exists.
    131131        if ( ! file_exists( $filepath ) ) {
    132132            return true;
     
    189189
    190190    /**
    191      * Delete all Webp files.
     191     * Delete the webp images generated by us, and reset the optimization status.
    192192     *
    193193     * @since  5.4.0
     
    196196     */
    197197    public function delete_webp_files() {
    198         $basedir = Helper_Service::get_uploads_dir();
    199         exec( "find $basedir -name '*.webp' -type f -print0 | xargs -L 500 -0 rm", $output, $result );
     198
     199        $this->delete_generated_webp_copies();
    200200
    201201        $this->reset_image_optimization_status();
     
    220220
    221221        if ( ! empty( $metadata['sizes'] ) ) {
    222             // Loop through all image sizes and optimize them as well.
     222            // Loop through all image sizes and delete them as well.
    223223            foreach ( $metadata['sizes'] as $size ) {
    224224                $wp_filesystem->delete( str_replace( $basename, $size['file'], $main_image ) . '.webp' );
    225225            }
    226226        }
    227 
    228227    }
    229228
     
    241240        $this->optimize( $id, $metadata );
    242241    }
     242
     243
     244    /**
     245     * Deletes only the webp images generated by us.
     246     */
     247    public function delete_generated_webp_copies() {
     248
     249        $images_ids = $this->get_all_image_attachments_with_webp_meta();
     250
     251        $batch_size = 200;
     252
     253        $batches = array_chunk( $images_ids, $batch_size );
     254
     255        foreach ( $batches as $chunk ) {
     256            foreach ( $chunk as $image_id ) {
     257                $this->delete_webp_copy( $image_id );
     258            }
     259        }
     260    }
     261
     262    /**
     263     * Gets all attachments with webp meta key.
     264     *
     265     * @return Array with IDs of images.
     266     */
     267    public function get_all_image_attachments_with_webp_meta() {
     268        // Query for attachments with the meta key and MIME type 'image'.
     269        $image_ids = get_posts(
     270            array(
     271                'post_type'      => 'attachment',
     272                'post_mime_type' => 'image',
     273                'meta_query'     => array(
     274                    array(
     275                        'key'     => 'siteground_optimizer_is_converted_to_webp',
     276                        'compare' => 'EXISTS',
     277                    ),
     278                ),
     279                'fields'         => 'ids',
     280                'posts_per_page' => -1,
     281            )
     282        );
     283
     284        return $image_ids;
     285    }
    243286}
  • sg-cachepress/trunk/core/Loader/Loader.php

    r3150542 r3410763  
    510510            // Minify the js files.
    511511            add_action( 'wp_print_scripts', array( $this->minifier, 'minify_scripts' ), 20 );
    512             add_action( 'wp_print_footer_scripts', array( $this->minifier, 'minify_scripts' ) );
     512
     513            if ( ! function_exists( 'is_plugin_active' ) ) {
     514                require_once ABSPATH . 'wp-admin/includes/plugin.php';
     515            }
     516
     517            if ( is_plugin_active( 'akismet/akismet.php' ) ) {
     518                add_action( 'wp_print_footer_scripts', array( $this->minifier, 'minify_scripts' ), 9 );
     519            } else {
     520                add_action( 'wp_print_footer_scripts', array( $this->minifier, 'minify_scripts' ) );
     521            }
    513522        }
    514523
  • sg-cachepress/trunk/core/Supercacher/Supercacher_Helper.php

    r2944007 r3410763  
    2828        if (
    2929            0 === $is_cache_enabled ||
    30             self::is_url_excluded( trailingslashit( $url ) )
     30            self::is_url_excluded( trailingslashit( $url ) ) ||
     31            self::is_query_param_excluded( $url )
    3132        ) {
    3233            $result->header( 'X-Cache-Enabled', 'False' );
     
    6061            ( 0 === $is_cache_enabled && 0 === $file_cache_enabled ) ||
    6162            self::is_url_excluded( $url ) ||
    62             self::is_post_type_excluded( $url )
     63            self::is_post_type_excluded( $url ) ||
     64            self::is_query_param_excluded( $url )
    6365        ) {
    6466            $headers['X-Cache-Enabled'] = 'False';
     
    163165    }
    164166
     167    /**
     168     * Checks if the URL contains excluded query parameters.
     169     *
     170     * @param $url The URL to check.
     171     *
     172     * @return boolean True if the URL contains excluded parameters, false otherwise.
     173     */
     174    public static function is_query_param_excluded( $url ) {
     175        // Get the excluded parameters, if there are such.
     176        $excluded_params = apply_filters( 'sgo_bypass_query_params', array() );
     177
     178        if ( empty( $excluded_params ) ) {
     179            return false;
     180        }
     181
     182        // Get the query parameters.
     183        $parsed_params = wp_parse_url( $url, PHP_URL_QUERY );
     184
     185        if ( empty( $parsed_params ) ) {
     186            return false;
     187        }
     188
     189        // Convert the parameters into array.
     190        $query_params = array();
     191        parse_str( $parsed_params, $query_params );
     192
     193        // Check if excluded parameters, exist in the query string.
     194        foreach ( $excluded_params as $param ) {
     195            if ( array_key_exists( $param, $query_params ) ) {
     196                return true;
     197            }
     198        }
     199
     200        return false;
     201    }
     202
    165203}
  • sg-cachepress/trunk/core/Supercacher/Supercacher_Posts.php

    r3393532 r3410763  
    137137    public function purge_all_post_cache( $post_id ) {
    138138
     139        // Get the post.
     140        $post = get_post( $post_id );
     141
     142        // Bail if the current hook is save_post and the post is scheduled.
     143        if ( 'save_post' === current_action() && 'future' === get_post_status( $post_id ) ) {
     144            return;
     145        }
     146
     147        // Bail if the current hook is publish_post and the post isn't scheduled.
     148        if ( 'publish_post' === current_action() && 'future' !== get_post_status( $post_id ) ) {
     149            return;
     150        }
     151
     152        // Bail if post type is excluded from cache purge.
     153        if ( true === $this->is_post_excluded_from_cache_purge( $post ) ) {
     154            return;
     155        }
     156
    139157        // Check if the cache for that $post_id is already flushed.
    140158        if ( true === $this->is_post_cache_already_flushed( $post_id ) ) {
    141             return;
    142         }
    143 
    144         // Get the post.
    145         $post = get_post( $post_id );
    146 
    147         // Bail if the current hook is save_post and the post is scheduled.
    148         if ( 'save_post' === current_action() && 'future' === get_post_status( $post_id ) ) {
    149             return;
    150         }
    151 
    152         // Bail if the current hook is publish_post and the post isn't scheduled.
    153         if ( 'publish_post' === current_action() && 'future' !== get_post_status( $post_id ) ) {
    154             return;
    155         }
    156 
    157         // Bail if post type is excluded from cache purge.
    158         if ( true === $this->is_post_excluded_from_cache_purge( $post ) ) {
    159159            return;
    160160        }
  • sg-cachepress/trunk/readme.txt

    r3393532 r3410763  
    44Requires at least: 4.7
    55Requires PHP: 7.0
    6 Tested up to: 6.8
    7 Stable tag: 7.7.4
     6Tested up to: 6.9
     7Stable tag: 7.7.5
    88License: GPLv3
    99License URI: http://www.gnu.org/licenses/gpl-3.0.html
     
    119119== Changelog ==
    120120
     121= Version 7.7.5 =
     122Release Date: Dec 4th, 2025
     123
     124* JS Combinator improvements
     125* Dynamic cache purge improvements
     126* CSS combination improvements
     127* WebP deletion improvements
     128* Query string exclude support for Dynamic Cache
     129
     130
    121131= Version 7.7.4 =
    122132Release Date: Nov 11th, 2025
  • sg-cachepress/trunk/sg-cachepress.php

    r3393532 r3410763  
    1111 * Plugin URI:        https://siteground.com
    1212 * Description:       This plugin will link your WordPress application with all the performance optimizations provided by SiteGround
    13  * Version:           7.7.4
     13 * Version:           7.7.5
    1414 * Author:            SiteGround
    1515 * Author URI:        https://www.siteground.com
     
    3434// Define version constant.
    3535if ( ! defined( __NAMESPACE__ . '\VERSION' ) ) {
    36     define( __NAMESPACE__ . '\VERSION', '7.7.4' );
     36    define( __NAMESPACE__ . '\VERSION', '7.7.5' );
    3737}
    3838
Note: See TracChangeset for help on using the changeset viewer.