apply_filters ( 'jetpack_photon_skip_for_url', bool false, string $image_url, array $args, string $scheme )

Allow specific image URls to avoid going through Photon.

Source file: functions.photon.php

View in GitHub

Parameters

false

(bool) false Should the image be returned as is, without going through Photon. Default to false.

$image_url

(string) Image URL.

$args

(array) Array of Photon arguments.

$scheme

(string) Image scheme. Default to null.


Changelog

Since: Jetpack 3.2.0


Notes

You can use this filter to make sure some of the images on your site do not use Photon. In the example below, we’ll only use Photon for images belonging to our site, and make sure none of the images that are not hosted on our site get processed by Photon.

/**
 * Only use Photon for images belonging to our site.
 *
 * @see https://wordpress.org/support/?p=8513006
 *
 * @param bool         $skip      Should Photon ignore that image.
 * @param string       $image_url Image URL.
 * @param array|string $args      Array of Photon arguments.
 * @param string|null  $scheme    Image scheme. Default to null.
 */
function jeherve_photon_only_allow_local( $skip, $image_url, $args, $scheme ) {
	// Get the site URL, without any protocol.
	$site_url = preg_replace( '~^(?:f|ht)tps?://~i', '', get_site_url() );

	/**
	 * If the image URL is from our site,
	 * return default value (false, unless another function overwrites).
	 * Otherwise, do not use Photon with it.
	 */
	if ( strpos( $image_url, $site_url ) ) {
		return $skip;
	} else {
		return true;
	}
}
add_filter( 'jetpack_photon_skip_for_url', 'jeherve_photon_only_allow_local', 9, 4 );

Have a note to contribute?

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s