Feature Request: Filter for image src (can then use Jetpack’s Photon CDN & more)

Not one for queueing up? Get faster support with AdRotate Pro!
The forum is checked a few times per week. With AdRotate Pro you can get answers faster using email support.
More private, more direct and usually a solution within a day! Learn more »

Home Forums AdRotate for WordPress General Support Feature Request: Filter for image src (can then use Jetpack’s Photon CDN & more)

This topic contains 5 replies, has 2 voices, and was last updated by  KZeni 9 months, 3 weeks ago.

  • #39647

    KZeni
    Badges:

    I want seamless integration of Jetpack’s Photon CDN service with the images served by AdRotate, but it appears there currently isn’t any filters which make it possible to update the image URL used by an ad. I’ve come up with a patch to add in this functionality, and I would love to see it adopted in the next official version for others to make use of.

    There’s only one line needing to be added to the plugin to accommodate this, but I’ll show more code for context. Open adrotate-output.php and update it so there’s a new line with the apply_filters function as seen here:

    
    $image = apply_filters('adrotate_image_src',$image);
    
    $banner_output = str_replace('%title%', $name, $banner_output);
    $banner_output = str_replace('%random%', rand(100000,999999), $banner_output);
    $banner_output = str_replace('%asset%', $image, $banner_output); // Replaces %image%
    $banner_output = str_replace('%image%', $image, $banner_output); // Depreciated, remove in AdRotate 5.0
    $banner_output = str_replace('%id%', $id, $banner_output);
    $banner_output = do_shortcode($banner_output);
    

    Again, it’s just that one line that needs to be added, but I included the rest for context to see what it’s affecting.

    Feel free to include this in the next version of AdRotate. I would greatly appreciate it and I’m guessing others will as well.

    Thanks for the great plugin!

    Also, I’ve crossposted this to WP.org support forum for others to potentially find it, if needed: https://wordpress.org/support/topic/feature-request-filter-for-image-src-can-then-use-jetpacks-photon-cdn-more/

    #39649

    KZeni
    Badges:

    Oh, and here’s the code I added to my theme’s functions.php file to make use of that new filter so all images used by AdRotate are automatically passed through the WP.com CDN via Jetpack’s Photon feature (when available).

    
    // Send images in AdRotate through Jetpack's Photon CDN service
    function adrotate_apply_jetpack_photon($image){
    	if(function_exists('jetpack_photon_url')){
    		return jetpack_photon_url($image);
    	}else{
    		return $image;
    	}
    }
    add_filter('adrotate_image_src','adrotate_apply_jetpack_photon');
    

    This would otherwise not be possible without this filter being added. Keep in mind that this will stop working if AdRotate is updated without including this new feature (as it will overwrite the patch adding the new filter).

    #39935

    Arnan
    Badges:

    So it’s 9 lines 😉

    I’ll look into it and consider it for a future update.
    Thanks!

    #39938

    KZeni
    Badges:

    Thanks! It’d be very appreciated!

    #40129

    Arnan
    Badges:
    #40170

    KZeni
    Badges:

    Great! Thanks a bunch!

Viewing 6 posts - 1 through 6 (of 6 total)

The topic ‘Feature Request: Filter for image src (can then use Jetpack’s Photon CDN & more)’ is closed to new replies.