Skip to content

Instantly share code, notes, and snippets.

@robincornett
Last active February 21, 2022 17:12
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save robincornett/eb39947d13aa86501e49 to your computer and use it in GitHub Desktop.
Disable the Jetpack Photon module so that you can work with WordPress' image functions
<?php
// do not include the opening php tag
// turn Photon off so we can get the correct image
$photon_removed = '';
if ( class_exists( 'Jetpack' ) && Jetpack::is_module_active( 'photon' ) ) { // check that we are, in fact, using Photon in the first place
$photon_removed = remove_filter( 'image_downsize', array( Jetpack_Photon::instance(), 'filter_image_downsize' ) );
}
// do things with image functions
// turn Photon back on
if ( $photon_removed ) {
add_filter( 'image_downsize', array( Jetpack_Photon::instance(), 'filter_image_downsize' ), 10, 3 );
}
@asyrawih
Copy link

where i put this code

@UTCGilligan
Copy link

@hananloser You can see how this is used in an RSS media attachment plugin I created:

@robincornett THANKS for the Jetpack check, that's important!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment