Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wpmudev-sls/98d84a323ec2a5eac4d61532bfd1a2ba to your computer and use it in GitHub Desktop.
Save wpmudev-sls/98d84a323ec2a5eac4d61532bfd1a2ba to your computer and use it in GitHub Desktop.
[Smush Pro] - Fix external images source (ex: amazon) converted to not found cdn link
<?php
/**
* Plugin Name: [Smush Pro] - Fix external images source (ex: amazon) converted to not found cdn link
* Description: [Smush Pro] - Fix external images source (ex: amazon) converted to not found cdn link - 1153814839375518
* Author: Thobk @ WPMUDEV
* Author URI: https://premium.wpmudev.org
* License: GPLv2 or later
*/
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
add_action( 'after_setup_theme', 'wpmudev_smpro_external_image_source_converted_to_not_found_cdn_link_func', 100 );
function wpmudev_smpro_external_image_source_converted_to_not_found_cdn_link_func() {
if( defined('WP_SMUSH_VERSION') && class_exists( 'Smush\WP_Smush' ) ){
// return if disabled cdn
if( ! Smush\Core\Settings::get_instance()->get('cdn') ) return;
class WPMUDEV_SMPro_External_Images_Converted_2_404_CDN{
private $cdn_core;
public function __construct(){
add_filter( 'smush_cdn_skip_image', array( $this, 'smush_cdn_skip_image'), 10, 2 );
}
public function cdn_core(){
if( is_null( $this->cdn_core ) ){
$this->cdn_core = Smush\WP_Smush::get_instance()->core()->mod->cdn;
}
return $this->cdn_core;
}
public function smush_cdn_skip_image( $skip, $src ){
if( ! $this->cdn_core()->is_supported_path( $src ) ){
$skip = true;
}
return $skip;
}
}
$run = new WPMUDEV_SMPro_External_Images_Converted_2_404_CDN;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment