* * add_filter( * 'smush_cdn_custom_uploads_dir', * function( $uploads ) { * $uploads['baseurl'] = 'https://example.com/media'; * return $uploads; * } * ); */ $uploads = apply_filters( 'smush_cdn_custom_uploads_dir', wp_get_upload_dir() ); // Check if the src is within custom uploads directory. $uploads = isset( $uploads['baseurl'] ) ? false !== strpos( $src, $uploads['baseurl'] ) : true; if ( ( false === strpos( $src, content_url() ) && ! $uploads ) || ( is_multisite() && $mapped_domain && false === strpos( $src, $mapped_domain ) ) ) { return false; } return $src; } /** * Support for domain mapping plugin. * * @since 3.1.1 */ private function check_mapped_domain() { if ( ! is_multisite() ) { return false; } if ( ! defined( 'DOMAINMAP_BASEFILE' ) ) { return false; } $domain = wp_cache_get( 'smush_mapped_site_domain', 'smush' ); if ( ! $domain ) { global $wpdb; $domain = $wpdb->get_var( $wpdb->prepare( "SELECT domain FROM {$wpdb->base_prefix}domain_mapping WHERE blog_id = %d ORDER BY id LIMIT 1", get_current_blog_id() ) ); // Db call ok. if ( null !== $domain ) { wp_cache_add( 'smush_mapped_site_domain', $domain, 'smush' ); } } return $domain; } /** * Init the page parser. */ private function init_parser() { $background_images = $this->settings->get( 'background_images' ); if ( $background_images ) { $this->parser->enable( 'background_images' ); } $this->parser->enable( 'cdn' ); } /** * Try to get the image dimensions from a local file. * * @since 3.4.0 * @param string $url Image URL. * * @return array|false */ private function get_image_size( $url ) { if ( $this->site_url !== $this->home_url ) { $url = str_replace( $this->site_url, $this->home_url, $url ); } $path = wp_make_link_relative( $url ); $path = wp_normalize_path( ABSPATH . $path ); if ( ! file_exists( $path ) ) { return false; } return getimagesize( $path ); } }