PHP Class Jetpack_Photon, jetpack

Show file Open project: automattic/jetpack Class Usage Examples

Protected Properties

Property Type Description
$extensions Allowed extensions must match http://code.trac.wordpress.org/browser/photon/index.php#L31
$image_sizes Don't access this directly. Instead, use self::image_sizes() so it's actually populated with something.

Public Methods

Method Description
action_wp_enqueue_scripts ( ) : null Enqueue Photon helper script
filter_image_downsize ( string | boolean $image, integer $attachment_id, string | array $size ) : string | boolean Filter post thumbnail image retrieval, passing images through Photon
filter_open_graph_tags ( array $tags, array $parameters ) : array Pass og:image URLs through Photon
filter_sizes ( array $sizes, array $size ) : array Filters an array of image sizes values, using $content_width instead of image's full size.
filter_srcset_array ( array $sources, $size_array, $image_src, $image_meta ) : array Filters an array of image srcset values, replacing each URL with its Photon equivalent.
filter_the_content ( string $content ) : string Identify images in post content, and if images are local (uploaded to the current site), pass through Photon.
filter_the_galleries ( $galleries )
instance ( ) : object Singleton implementation
parse_dimensions_from_filename ( string $src ) : array Try to determine height and width from strings WP appends to resized image filenames.
parse_images_from_html ( string $content ) : array Match all images and any relevant tags in a block of HTML.

Protected Methods

Method Description
image_sizes ( ) : array Provide an array of available image sizes and corresponding dimensions.
strip_image_dimensions_maybe ( string $src ) : string Checks if the file exists before it passes the file to photon
validate_image_url ( string $url ) : boolean Ensure image URL is valid for Photon.

Private Methods

Method Description
__construct ( ) Silence is golden.
setup ( ) : null Register actions and filters, but only if basic Photon functions are available.

Method Details

action_wp_enqueue_scripts() public method

Enqueue Photon helper script
public action_wp_enqueue_scripts ( ) : null
return null

filter_image_downsize() public method

Filter post thumbnail image retrieval, passing images through Photon
public filter_image_downsize ( string | boolean $image, integer $attachment_id, string | array $size ) : string | boolean
$image string | boolean
$attachment_id integer
$size string | array
return string | boolean

filter_open_graph_tags() public method

Pass og:image URLs through Photon
public filter_open_graph_tags ( array $tags, array $parameters ) : array
$tags array
$parameters array
return array

filter_sizes() public method

Filters an array of image sizes values, using $content_width instead of image's full size.
Since: 4.0.4
Since: 4.1.0 Returns early for images not within the_content.
public filter_sizes ( array $sizes, array $size ) : array
$sizes array An array of media query breakpoints.
$size array Width and height of the image
return array An array of media query breakpoints.

filter_srcset_array() public method

Filters an array of image srcset values, replacing each URL with its Photon equivalent.
Since: 3.8.0
Since: 4.0.4 Added automatically additional sizes beyond declared image sizes.
public filter_srcset_array ( array $sources, $size_array, $image_src, $image_meta ) : array
$sources array An array of image urls and widths.
return array An array of Photon image urls and widths.

filter_the_content() public static method

Identify images in post content, and if images are local (uploaded to the current site), pass through Photon.
public static filter_the_content ( string $content ) : string
$content string
return string

filter_the_galleries() public static method

public static filter_the_galleries ( $galleries )

image_sizes() protected static method

Similar to get_intermediate_image_sizes() except that it includes image sizes' dimensions, not just their names.
protected static image_sizes ( ) : array
return array

instance() public static method

Singleton implementation
public static instance ( ) : object
return object

parse_dimensions_from_filename() public static method

Try to determine height and width from strings WP appends to resized image filenames.
public static parse_dimensions_from_filename ( string $src ) : array
$src string The image URL.
return array An array consisting of width and height.
Checks if the file exists before it passes the file to photon
protected static strip_image_dimensions_maybe ( string $src ) : string
$src string The image URL
return string

validate_image_url() protected static method

Though Photon functions address some of the URL issues, we should avoid unnecessary processing if we know early on that the image isn't supported.
protected static validate_image_url ( string $url ) : boolean
$url string
return boolean

Property Details

$extensions protected static property

Allowed extensions must match http://code.trac.wordpress.org/browser/photon/index.php#L31
protected static $extensions

$image_sizes protected static property

Don't access this directly. Instead, use self::image_sizes() so it's actually populated with something.
protected static $image_sizes