Skip to content
2 changes: 1 addition & 1 deletion js/inline-loader.asset.php
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<?php return array('dependencies' => array(), 'version' => '25ccbb8ce37353267420');
<?php return array('dependencies' => array(), 'version' => '4e42165f1fda84e18ed5');
2 changes: 1 addition & 1 deletion js/inline-loader.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

34 changes: 31 additions & 3 deletions php/class-delivery.php
Original file line number Diff line number Diff line change
Expand Up @@ -1032,6 +1032,10 @@ public function convert_tags( $content, $context = 'view' ) {
$replacements = array_merge( $replacements, $aliases );
}

// Sort by length, so we replace the longest first and prevent early replacements.
$keys = array_map( 'strlen', array_keys( $replacements ) );
array_multisort( $keys, SORT_DESC, $replacements );

// Update the post meta cache.
if ( is_singular() ) {
$has_cache = array();
Expand Down Expand Up @@ -1140,7 +1144,7 @@ protected function standardize_tag( $tag_element ) {
$local_size = filesize( get_attached_file( $tag_element['id'] ) );
}
$remote_size = get_post_meta( $tag_element['id'], Sync::META_KEYS['remote_size'], true );
$tag_element['atts']['data-filesize'] = size_format( $local_size );
$tag_element['atts']['data-filesize'] = size_format( $local_size );
$tag_element['atts']['data-optsize'] = size_format( $remote_size );
$tag_element['atts']['data-optformat'] = get_post_meta( $tag_element['id'], Sync::META_KEYS['remote_format'], true );
if ( ! empty( $local_size ) && ! empty( $remote_size ) ) {
Expand All @@ -1154,6 +1158,29 @@ protected function standardize_tag( $tag_element ) {

$tag_element['atts']['data-version'] = $this->media->get_cloudinary_version( $tag_element['id'] );

/**
* Bypass Cloudinary's SEO URLs.
*
* @hook cloudinary_bypass_seo_url
* @since 3.1.5
*
* @param $bypass_seo_url {bool} Whether to bypass SEO URLs.
*
* @return {bool}
*/
$bypass_seo_url = apply_filters( 'cloudinary_bypass_seo_url', false );

$tag_element['atts']['data-seo'] = ! $bypass_seo_url;

$resource_type = in_array( $tag_element['type'], array( 'image', 'video' ), true ) ? $tag_element['type'] : 'raw';

$args = array(
'delivery' => $this->media->get_media_delivery( $tag_element['id'] ),
'resource_type' => $resource_type,
);

$tag_element['atts']['data-public-id'] = $this->plugin->get_component( 'connect' )->api->get_public_id( $tag_element['id'], '', $args );

return $tag_element;
}

Expand Down Expand Up @@ -1182,9 +1209,10 @@ public function rebuild_tag( $tag_element ) {
if ( apply_filters( 'cloudinary_apply_breakpoints', true ) ) {
$meta = wp_get_attachment_metadata( $tag_element['id'] );
if ( ! empty( $meta['width'] ) && ! empty( $meta['height'] ) ) {
$relationship = Relationship::get_relationship( $tag_element['id'] );
// Check overwrite.
$meta['overwrite_transformations'] = $tag_element['overwrite_transformations'];
$meta['cloudinary_id'] = $tag_element['atts']['data-public-id'];
$meta['cloudinary_id'] = $relationship->public_id;
$meta['transformations'] = $tag_element['transformations'];
// Add new srcset.
$element = wp_image_add_srcset_and_sizes( $tag_element['original'], $meta, $tag_element['id'] );
Expand Down Expand Up @@ -1318,7 +1346,7 @@ public function parse_element( $element ) {
$tag_element['height'] = ! empty( $attributes['height'] ) ? $attributes['height'] : $item['height'];
$attributes['data-public-id'] = $public_id;
$tag_element['format'] = $item['format'];

if ( 'img' === $tag_element['tag'] ) {
// Check if this is a crop or a scale.
$has_size = $this->media->get_size_from_url( $this->sanitize_url( $raw_url ) );
Expand Down
4 changes: 2 additions & 2 deletions php/class-media.php
Original file line number Diff line number Diff line change
Expand Up @@ -1383,7 +1383,7 @@ public function cloudinary_url( $attachment_id, $size = array(), $transformation
'secure' => is_ssl(),
'version' => $this->get_cloudinary_version( $attachment_id ),
'resource_type' => $resource_type,
'delivery_type' => $delivery,
'delivery' => $delivery,
);
$set_size = array();
if ( 'upload' === $delivery ) {
Expand All @@ -1397,7 +1397,7 @@ public function cloudinary_url( $attachment_id, $size = array(), $transformation

// Make a copy as not to destroy the options in \Cloudinary::cloudinary_url().
$args = $pre_args;
$url = $this->plugin->components['connect']->api->cloudinary_url( $cloudinary_id, $args, $set_size );
$url = $this->plugin->components['connect']->api->cloudinary_url( $cloudinary_id, $args, $set_size, $attachment_id );

// Check if this type is a preview only type. i.e PDF.
if ( ! empty( $set_size ) && $this->is_preview_only( $attachment_id ) ) {
Expand Down
Loading