Skip to content

Commit

Permalink
Add support for dc_cloudinary_exclude filter and data-cloudinary-excl…
Browse files Browse the repository at this point in the history
…ude attribute
  • Loading branch information
tlovett1 committed May 31, 2023
1 parent 791bf05 commit 01b90d4
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 6 deletions.
4 changes: 2 additions & 2 deletions dynamic-cloudinary.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Plugin Name: Dynamic Cloudinary
* Plugin URI: https://github.com/tlovett1/dynamic-cloudinary
* Description: Automatically serve all your images optimized from the cloud.
* Version: 1.2.3
* Version: 1.3.0
* Requires PHP: 7.4
* Author: Taylor Lovett
* Author URI: https://taylorlovett.com
Expand All @@ -19,7 +19,7 @@

namespace DynamicCloudinary;

define( 'DYNAMIC_CLOUDINARY_VERSION', '1.2.3' );
define( 'DYNAMIC_CLOUDINARY_VERSION', '1.3.0' );
define( 'DYNAMIC_CLOUDINARY_URL', plugin_dir_url( __FILE__ ) );
define( 'DYNAMIC_CLOUDINARY_PATH', plugin_dir_path( __FILE__ ) );

Expand Down
18 changes: 14 additions & 4 deletions includes/classes/Parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,13 @@ public function parse_assets( $html ) {
foreach ( $imgs as $img ) {
$original_html = $img->outerHTML;

$src = $img->getAttribute( 'src' );
$srcset = $img->getAttribute( 'srcset' );
$exclude = $img->getAttribute( 'data-cloudinary-exclude' );
$src = $img->getAttribute( 'src' );
$srcset = $img->getAttribute( 'srcset' );

if ( ! empty( $exclude ) || apply_filters( 'dc_exclude_asset', false, $src, $srcset, $img ) ) {
continue;
}

$args = $this->get_transformations_from_node( $img );

Expand Down Expand Up @@ -200,8 +205,13 @@ public function parse_assets( $html ) {
// We have to do some weird regex because of unexpected HTML5Document results
$original_html = preg_replace( '#^(<source .*?>).*$#is', '$1', $source->outerHTML );

$srcset = $source->getAttribute( 'srcset' );
$src = $source->getAttribute( 'src' );
$exclude = $source->getAttribute( 'data-cloudinary-exclude' );
$srcset = $source->getAttribute( 'srcset' );
$src = $source->getAttribute( 'src' );

if ( ! empty( $exclude ) || apply_filters( 'dc_exclude_asset', false, $src, $srcset, $source ) ) {
continue;
}

$args = $this->get_transformations_from_node( $source );

Expand Down
3 changes: 3 additions & 0 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ For full documentation, questions, feature requests, and support concerning the

== Changelog ==

= 1.3.0 =
* Add `dc_cloudinary_exclude` filter and support for `data-cloudinary-exclude` attribute. If either is provided, the asset will be excluded from Cloudinary parsing.

= 1.2.3 =
* Better process transformation arguments

Expand Down

0 comments on commit 01b90d4

Please sign in to comment.