@since 3.0.0: * * @see is_valid_url() * @see get_size_from_file_name() * @see get_url_without_dimensions() * @see set_additional_srcset() * @see generate_srcset() * @see maybe_generate_srcset() * @see is_supported_path() */ /** * Check if we can use the image URL in CDN. * * @param string $url Image URL. * * @return bool * @since 3.0 * */ private function is_valid_url( $url ) { $parsed_url = wp_parse_url( $url ); if ( ! $parsed_url ) { return false; } // No host or path found. if ( ! isset( $parsed_url['host'] ) || ! isset( $parsed_url['path'] ) ) { return false; } // If not supported extension - return false. if ( ! in_array( strtolower( pathinfo( $parsed_url['path'], PATHINFO_EXTENSION ) ), $this->supported_extensions, true ) ) { return false; } return true; } /** * Try to determine height and width from strings WP appends to resized image filenames. * * @param string $src The image URL. * * @return array An array consisting of width and height. * @since 3.0 * */ private function get_size_from_file_name( $src ) { $size = array(); if ( preg_match( '/-(\d+)x(\d+)\.(?:' . implode( '|', $this->supported_extensions ) . ')$/i', $src, $size ) ) { // Get size and width. $width = (int) $size[1]; $height = (int) $size[2]; // Handle retina images. if ( strpos( $src, '@2x' ) ) { $width = 2 * $width; $height = 2 * $height; } // Return width and height as array. if ( $width && $height ) { return array( $width, $height ); } } return array( false, false ); } /** * Filters an array of image srcset values, and add additional values. * * @param array $sources An array of image urls and widths. * @param array $size_array Array of width and height values in pixels. * @param string $url Image URL. * @param array $image_meta The image metadata. * @param string $image_src The src of the image. * * @return array $sources * @since 3.0 * */ private function set_additional_srcset( $sources, $size_array, $url, $image_meta, $image_src = '' ) { $content_width = $this->settings->max_content_width(); // If url is empty, try to get from src. if ( empty( $url ) ) { $url = $this->urls_utils->get_url_without_dimensions( $image_src ); } // We need to add additional dimensions. $full_width = $image_meta['width']; $full_height = $image_meta['height']; $current_width = $size_array[0]; $current_height = $size_array[1]; // Get width and height calculated by WP. list( $constrained_width, $constrained_height ) = wp_constrain_dimensions( $full_width, $full_height, $current_width, $current_height ); // Calculate base width. // If $constrained_width sizes are smaller than current size, set maximum content width. if ( abs( $constrained_width - $current_width ) <= 1 && abs( $constrained_height - $current_height ) <= 1 ) { $base_width = $content_width; } else { $base_width = $current_width; } $current_widths = array_keys( $sources ); $new_sources = array(); /** * Filter to add/update/bypass additional srcsets. * * If empty value or false is retured, additional srcset * will not be generated. * * @param array|bool $additional_multipliers Additional multipliers. */ $additional_multipliers = apply_filters( 'smush_srcset_additional_multipliers', array( 0.2, 0.4, 0.6, 0.8, 1, 1.5, 2, 3, ) ); // Continue only if additional multipliers found or not skipped. // Filter already documented in class-cdn.php. if ( $this->cdn_helper->skip_image_url( $url, false ) || empty( $additional_multipliers ) ) { return $sources; } // Loop through each multipliers and generate image. foreach ( $additional_multipliers as $multiplier ) { // New width by multiplying with original size. $new_width = (int) ( $base_width * $multiplier ); // In most cases - going over the current width is not recommended and probably not what the user is expecting. if ( $new_width > $current_width ) { continue; } // If a nearly sized image already exist, skip. foreach ( $current_widths as $_width ) { // If +- 50 pixel difference - skip. if ( abs( $_width - $new_width ) < 50 || ( $new_width > $full_width ) ) { continue 2; } } // We need the width as well... $dimensions = wp_constrain_dimensions( $current_width, $current_height, $new_width ); // Arguments for cdn url. $args = array( 'size' => "{$new_width}x{$dimensions[1]}", ); // Add new srcset item. $new_sources[ $new_width ] = array( 'url' => $this->cdn_helper->generate_cdn_url( $url, $args ), 'descriptor' => 'w', 'value' => $new_width, ); } // Assign new srcset items to existing ones. if ( ! empty( $new_sources ) ) { // Loop through each items and replace/add. foreach ( $new_sources as $_width_key => $_width_values ) { $sources[ $_width_key ] = $_width_values; } } return $sources; } /** * Try to generate the srcset for the image. * * @param string $src Image source. * * @return array|bool * @since 3.0 * */ public function generate_srcset( $src, $attachment_id = 0, $width = 0, $height = 0 ) { $priority = $this->get_cdn_srcset_priority(); add_filter( 'wp_calculate_image_srcset', array( $this, 'update_image_srcset' ), $priority, 5 ); list( $srcset, $sizes ) = $this->srcset_helper->generate_srcset_and_sizes( $src, $attachment_id, $width, $height ); remove_filter( 'wp_calculate_image_srcset', array( $this, 'update_image_srcset' ), $priority ); return array( $srcset, $sizes ); } /** * @return int */ private function get_cdn_srcset_priority(): int { return defined( 'WP_SMUSH_CDN_DELAY_SRCSET' ) && WP_SMUSH_CDN_DELAY_SRCSET ? 1000 : 99; } }
Fatal error: Uncaught Error: Class "Smush\Core\CDN\CDN_Srcset_Controller" not found in /home/cpaherna/public_html/wp-content/plugins/wp-smushit/core/modules/class-cdn.php:32 Stack trace: #0 /home/cpaherna/public_html/wp-content/plugins/wp-smushit/core/class-modules.php(151): Smush\Core\Modules\CDN->__construct() #1 /home/cpaherna/public_html/wp-content/plugins/wp-smushit/core/class-core.php(158): Smush\Core\Modules->__construct() #2 /home/cpaherna/public_html/wp-content/plugins/wp-smushit/core/class-stats.php(104): Smush\Core\Core->init() #3 /home/cpaherna/public_html/wp-content/plugins/wp-smushit/wp-smush.php(387): Smush\Core\Stats->__construct() #4 /home/cpaherna/public_html/wp-content/plugins/wp-smushit/wp-smush.php(307): WP_Smush->init() #5 /home/cpaherna/public_html/wp-content/plugins/wp-smushit/wp-smush.php(258): WP_Smush->__construct() #6 /home/cpaherna/public_html/wp-includes/class-wp-hook.php(324): WP_Smush::get_instance('') #7 /home/cpaherna/public_html/wp-includes/class-wp-hook.php(348): WP_Hook->apply_filters(NULL, Array) #8 /home/cpaherna/public_html/wp-includes/plugin.php(517): WP_Hook->do_action(Array) #9 /home/cpaherna/public_html/wp-settings.php(555): do_action('plugins_loaded') #10 /home/cpaherna/public_html/wp-config.php(96): require_once('/home/cpaherna/...') #11 /home/cpaherna/public_html/wp-load.php(50): require_once('/home/cpaherna/...') #12 /home/cpaherna/public_html/wp-blog-header.php(13): require_once('/home/cpaherna/...') #13 /home/cpaherna/public_html/index.php(17): require('/home/cpaherna/...') #14 {main} thrown in /home/cpaherna/public_html/wp-content/plugins/wp-smushit/core/modules/class-cdn.php on line 32