Plugin Directory

Changeset 3441908


Ignore:
Timestamp:
01/18/2026 12:49:51 PM (4 weeks ago)
Author:
barb0ss
Message:

updated to 1.7.6

Location:
squeeze
Files:
90 added
4 edited

Legend:

Unmodified
Added
Removed
  • squeeze/trunk/inc/handlers.php

    r3436111 r3441908  
    231231        }
    232232        $attach_id = (int) $_POST["attachmentID"];
    233         $sizes = wp_get_attachment_metadata( $attach_id );
    234         $sizes = $sizes['sizes'];
     233        // Load excluded images once per request (Premium only) - cached in get_excluded_images()
     234        $excluded_images = array();
     235        // Get attachment metadata once (contains sizes data)
     236        $metadata = wp_get_attachment_metadata( $attach_id );
     237        $sizes = ( isset( $metadata['sizes'] ) ? $metadata['sizes'] : array() );
    235238        $full_image = wp_get_attachment_image_src( $attach_id, 'full' );
     239        // Check exclusion early (Premium only) - before expensive operations if possible
     240        if ( squeeze_freemius()->is__premium_only() && !empty( $excluded_images ) && !empty( $full_image[0] ) ) {
     241            if ( $is_excluded = self::$SqueezePremium->is_excluded_image( $full_image[0], $excluded_images ) ) {
     242                wp_send_json_error( '❌ ' . esc_html__( 'Attachment is excluded from compression', 'squeeze' ) . ' (' . esc_html__( 'found substring: ', 'squeeze' ) . $is_excluded['exclude_reason'] . ')' );
     243            }
     244        }
     245        // Cache file paths to avoid repeated function calls
     246        $attached_file = get_attached_file( $attach_id );
     247        $original_image_path = wp_get_original_image_path( $attach_id );
    236248        $is_squeezed = get_post_meta( $attach_id, 'squeeze_is_compressed', true );
    237249        // -scaled image
     
    240252            'width'    => $full_image[1],
    241253            'height'   => $full_image[2],
    242             'filesize' => wp_filesize( get_attached_file( $attach_id ) ),
     254            'filesize' => wp_filesize( $attached_file ),
    243255        );
     256        // Build size URLs (WordPress caches these internally)
    244257        foreach ( $sizes as $size_name => $size_data ) {
    245258            $sizes[$size_name]['url'] = wp_get_attachment_image_url( $attach_id, $size_name );
     
    250263            'mime'        => get_post_mime_type( $attach_id ),
    251264            'name'        => get_the_title( $attach_id ),
    252             'filename'    => basename( wp_get_original_image_path( $attach_id ) ),
     265            'filename'    => basename( $original_image_path ),
    253266            'sizes'       => $sizes,
    254267            'is_squeezed' => $is_squeezed,
     
    271284        $image_formats = self::$SqueezeHelpers->get_image_formats();
    272285        $image_formats = implode( ',', $image_formats );
     286        // MIME type mapping based on file extension (much faster than exif_imagetype)
     287        $mime_type_map = array(
     288            'jpg'  => 'image/jpeg',
     289            'jpeg' => 'image/jpeg',
     290            'png'  => 'image/png',
     291            'webp' => 'image/webp',
     292            'avif' => 'image/avif',
     293            'gif'  => 'image/gif',
     294        );
     295        // Load excluded images once per request (Premium only) - cached in get_excluded_images()
     296        $excluded_images = array();
     297        // Cache home URL and normalize ABSPATH to avoid repeated function calls and string operations
     298        $home_url = trailingslashit( home_url() );
     299        $abspath_normalized = str_replace( '\\', '/', ABSPATH );
    273300        foreach ( $pathes as $path ) {
    274301            // Remove dangerous patterns related to directory traversal
     
    293320            }
    294321            foreach ( $images as $image ) {
    295                 $attach_id = attachment_url_to_postid( $image );
    296                 $attach_mime = image_type_to_mime_type( exif_imagetype( $image ) );
    297                 $attach_url = str_replace( ABSPATH, home_url(), $image );
     322                // Get file extension for MIME type detection (much faster than exif_imagetype)
     323                $extension = strtolower( pathinfo( $image, PATHINFO_EXTENSION ) );
     324                // Skip if extension not in our map (safety check)
     325                if ( !isset( $mime_type_map[$extension] ) ) {
     326                    continue;
     327                }
     328                $attach_mime = $mime_type_map[$extension];
     329                $filename = basename( $image );
     330                // Convert file path to URL efficiently
     331                // Normalize path separators and replace ABSPATH with home URL
     332                $image_normalized = str_replace( '\\', '/', $image );
     333                $attach_url = str_replace( $abspath_normalized, $home_url, $image_normalized );
     334                // Check exclusion early (Premium only) - before any expensive operations
     335                if ( squeeze_freemius()->is__premium_only() && !empty( $excluded_images ) ) {
     336                    if ( $is_excluded = self::$SqueezePremium->is_excluded_image( $attach_url, $excluded_images ) ) {
     337                        $attachment_data[] = array(
     338                            'excluded'       => true,
     339                            'exclude_reason' => $is_excluded['exclude_reason'],
     340                            'filename'       => $filename,
     341                        );
     342                        continue;
     343                    }
     344                }
     345                // Skip attachment_url_to_postid() to avoid expensive database queries
     346                // Path-based compression works with ID = 0 (files not in media library)
     347                $attach_id = 0;
    298348                $attach_name = pathinfo( $image, PATHINFO_FILENAME );
    299349                $attachment_data[] = array(
     
    302352                    'mime'     => $attach_mime,
    303353                    'name'     => $attach_name,
    304                     'filename' => basename( $image ),
     354                    'filename' => $filename,
    305355                );
    306356            }
  • squeeze/trunk/inc/helpers.php

    r3436111 r3441908  
    88
    99class SqueezeHelpers extends SqueezeInit {
     10    // Cache squeeze_options array per request to avoid repeated database queries
     11    private static $cached_squeeze_options = null;
     12
    1013    public function __construct() {
    1114        //parent::__construct(); // will cause infinite loop in SquuezeInit
     
    327330
    328331    public function get_option($option) {
    329         $options = get_option('squeeze_options');
     332        // Cache squeeze_options array per request to avoid repeated database queries
     333        // This prevents hundreds of get_option('squeeze_options') calls during bulk operations
     334        if (self::$cached_squeeze_options === null) {
     335            self::$cached_squeeze_options = get_option('squeeze_options');
     336        }
     337       
     338        $options = self::$cached_squeeze_options;
    330339        $option_value = isset($options[$option]) ? $options[$option] : $this->get_default_value($option);
    331340
     
    336345        $default_options = $this->get_default_value('all', true);
    337346        $options = wp_parse_args($options, $default_options);
    338         return update_option('squeeze_options', $options);
     347        $result = update_option('squeeze_options', $options);
     348       
     349        // Clear the cache when options are updated
     350        if ($result) {
     351            self::$cached_squeeze_options = $options;
     352        }
     353       
     354        return $result;
    339355    }
    340356
  • squeeze/trunk/readme.txt

    r3436111 r3441908  
    55Tested up to: 6.9
    66Requires PHP: 7.3
    7 Stable tag: 1.7.5
     7Stable tag: 1.7.6
    88License: GPLv3
    99License URI: https://www.gnu.org/licenses/gpl-3.0.html
     
    185185
    186186== Changelog ==
     187= 1.7.6 =
     188* Cached heavy PHP and SQL requests
    187189= 1.7.5 =
    188190* Updated notifications texts and icons
  • squeeze/trunk/squeeze.php

    r3436111 r3441908  
    66 * Author URI:  https://pluginarium.com
    77 * Author:      Bogdan Bendziukov
    8  * Version:     1.7.5
     8 * Version:     1.7.6
    99 *
    1010 * Text Domain: squeeze
     
    2626     * Plugin version
    2727     */
    28     const VERSION = '1.7.5';
     28    const VERSION = '1.7.6';
    2929
    3030    const CHECKOUT_URL = 'https://checkout.freemius.com/plugin/17217/plan/28703/';
Note: See TracChangeset for help on using the changeset viewer.