summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnthony G. Basile <blueness@gentoo.org>2017-06-15 08:53:57 -0400
committerAnthony G. Basile <blueness@gentoo.org>2017-06-15 08:53:57 -0400
commit48822ba710570832bbc0ffb9b6c3470e25e7bf29 (patch)
tree70e349b7e03191c456033287e53593056249c962 /plugins/jetpack/class.photon.php
parentUpdate twentyfourteen 2.0 (diff)
downloadblogs-gentoo-48822ba710570832bbc0ffb9b6c3470e25e7bf29.tar.gz
blogs-gentoo-48822ba710570832bbc0ffb9b6c3470e25e7bf29.tar.bz2
blogs-gentoo-48822ba710570832bbc0ffb9b6c3470e25e7bf29.zip
Update jetpack 5.0
Signed-off-by: Anthony G. Basile <blueness@gentoo.org>
Diffstat (limited to 'plugins/jetpack/class.photon.php')
-rw-r--r--plugins/jetpack/class.photon.php64
1 files changed, 42 insertions, 22 deletions
diff --git a/plugins/jetpack/class.photon.php b/plugins/jetpack/class.photon.php
index 87a0f8c3..8f6f15e7 100644
--- a/plugins/jetpack/class.photon.php
+++ b/plugins/jetpack/class.photon.php
@@ -51,6 +51,7 @@ class Jetpack_Photon {
// Images in post content and galleries
add_filter( 'the_content', array( __CLASS__, 'filter_the_content' ), 999999 );
add_filter( 'get_post_galleries', array( __CLASS__, 'filter_the_galleries' ), 999999 );
+ add_filter( 'widget_media_image_instance', array( __CLASS__, 'filter_the_image_widget' ), 999999 );
// Core image retrieval
add_filter( 'image_downsize', array( $this, 'filter_image_downsize' ), 10, 3 );
@@ -197,27 +198,25 @@ class Jetpack_Photon {
// WP Attachment ID, if uploaded to this site
if (
preg_match( '#class=["|\']?[^"\']*wp-image-([\d]+)[^"\']*["|\']?#i', $images['img_tag'][ $index ], $attachment_id ) &&
- (
- 0 === strpos( $src, $upload_dir['baseurl'] ) ||
- /**
- * Filter whether an image using an attachment ID in its class has to be uploaded to the local site to go through Photon.
- *
- * @module photon
- *
- * @since 2.0.3
- *
- * @param bool false Was the image uploaded to the local site. Default to false.
- * @param array $args {
- * Array of image details.
- *
- * @type $src Image URL.
- * @type tag Image tag (Image HTML output).
- * @type $images Array of information about the image.
- * @type $index Image index.
- * }
- */
- apply_filters( 'jetpack_photon_image_is_local', false, compact( 'src', 'tag', 'images', 'index' ) )
- )
+ 0 === strpos( $src, $upload_dir['baseurl'] ) &&
+ /**
+ * Filter whether an image using an attachment ID in its class has to be uploaded to the local site to go through Photon.
+ *
+ * @module photon
+ *
+ * @since 2.0.3
+ *
+ * @param bool false Was the image uploaded to the local site. Default to false.
+ * @param array $args {
+ * Array of image details.
+ *
+ * @type $src Image URL.
+ * @type tag Image tag (Image HTML output).
+ * @type $images Array of information about the image.
+ * @type $index Image index.
+ * }
+ */
+ apply_filters( 'jetpack_photon_image_is_local', false, compact( 'src', 'tag', 'images', 'index' ) )
) {
$attachment_id = intval( array_pop( $attachment_id ) );
@@ -388,6 +387,24 @@ class Jetpack_Photon {
return $galleries;
}
+
+ /**
+ * Runs the image widget through photon.
+ *
+ * @param array $instance Image widget instance data.
+ * @return array
+ */
+ public static function filter_the_image_widget( $instance ) {
+ if ( Jetpack::is_module_active( 'photon' ) && ! $instance['attachment_id'] && $instance['url'] ) {
+ jetpack_photon_url( $instance['url'], array(
+ 'w' => $instance['width'],
+ 'h' => $instance['height'],
+ ) );
+ }
+
+ return $instance;
+ }
+
/**
** CORE IMAGE RETRIEVAL
**/
@@ -626,7 +643,10 @@ class Jetpack_Photon {
* @uses Jetpack_Photon::strip_image_dimensions_maybe, Jetpack::get_content_width
* @return array An array of Photon image urls and widths.
*/
- public function filter_srcset_array( $sources, $size_array, $image_src, $image_meta ) {
+ public function filter_srcset_array( $sources = array(), $size_array = array(), $image_src = array(), $image_meta = array() ) {
+ if ( ! is_array( $sources ) ) {
+ return $sources;
+ }
$upload_dir = wp_get_upload_dir();
foreach ( $sources as $i => $source ) {