Skip to content

Commit

Permalink
Built release for 0.5.8. For a full change log look at the notes with…
Browse files Browse the repository at this point in the history
…in the original/0.5.8 release.
  • Loading branch information
github-actions[bot] committed Feb 7, 2025
1 parent a3a5ecf commit 645780c
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 60 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
Changelog
=========

## v0.5.8

- Bug: Fix adding image optimization attributes to images

## v0.5.7

- Bug: Add image optimization attributes to images

## v0.4.3

- Bug: Check model has mime type before checking value
Expand Down
2 changes: 1 addition & 1 deletion build.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"owner":"humanmade","repo":"smart-media","sha":"de46d43a95739a481b9d320b9c6d3e92d9a324f7","ref":"refs/tags/0.5.7","tagName":"0.5.7","branch":"gh-actions","tags":["0.5.7"],"updated_at":"2024-11-27T16:56:50.515Z"}
{"owner":"humanmade","repo":"smart-media","sha":"c3b1e20bc6e99794fd5882a1d6c146c5728c8371","ref":"refs/tags/0.5.8","tagName":"0.5.8","branch":"gh-actions","tags":["0.5.8"],"updated_at":"2025-02-07T15:49:20.976Z"}
64 changes: 6 additions & 58 deletions inc/cropper/namespace.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,6 @@ function setup() {
*/
add_filter( 'wp_content_img_tag', __NAMESPACE__ . '\\content_img_tag', 10, 3 );

// Ensure loading and fetchpriority attributes are added to images.
add_filter( 'wp_get_loading_optimization_attributes', __NAMESPACE__ . '\\maybe_add_loading_optimization_attributes', 10, 4 );

// Ensure the get dimensions function understands Tachyon.
add_filter( 'wp_image_src_get_dimensions', __NAMESPACE__ . '\\src_get_dimensions', 10, 4 );

Expand Down Expand Up @@ -956,62 +953,13 @@ function content_img_tag( string $filtered_image, string $context, int $attachme
$filtered_image = add_srcset_and_sizes_attr( $filtered_image, $image_meta, $attachment_id );
}

return $filtered_image;
}

/**
* Maybe add Loading optimization attributes to the img tag.
*
* @param array|false $loading_attrs False by default, or array of loading optimization attributes to short-circuit.
* @param string $tag_name The tag name.
* @param array $attr Array of the attributes for the tag.
* @param string $context Context for the element for which the loading optimization attribute is requested.
*
* @return string
*/
function maybe_add_loading_optimization_attributes( $loading_attrs, $tag_name, $attr, $context ) {
$allowed_context = [ 'the_content', 'template' ];
if ( ! in_array( $context, $allowed_context , true ) ) {
return $loading_attrs;
}

// Only apply to img tags.
if ( $tag_name !== 'img' ) {
return $loading_attrs;
}

// Check if lazy loading is enabled.
if ( ! wp_lazy_loading_enabled( $tag_name, $context ) ) {
return $loading_attrs;
}

// Count images to determine when we should fetchpriority and loading attribute.
static $count_images = 1;

/**
* Filters the threshold for how many of the first content media elements to not lazy-load.
*
* For these first content media elements, the `loading` attribute will be omitted. By default, this is the case
* for only the very first content media element.
*
* @since 5.9.0
* @since 6.3.0 The default threshold was changed from 1 to 3.
*
* @param int $omit_threshold The number of media elements where the `loading` attribute will not be added. Default 3.
*/
$omit_threshold = apply_filters( 'wp_omit_loading_attr_threshold', 3 );

// Only apply fetchpriority to the first image.
if ( $count_images === 1 ) {
$loading_attrs['fetchpriority'] = 'high';
} elseif( $count_images > $omit_threshold ) {
$loading_attrs['loading'] = 'lazy';
}

// Increment image count.
$count_images++;
// Call core function to add loading optimization attributes again.
// These rely on width/heights being set correctly which is not set at the point core calls them.
// See wp_img_tag_add_auto_sizes
$filtered_image = wp_img_tag_add_loading_optimization_attrs( $filtered_image, $context );
$filtered_image = wp_img_tag_add_auto_sizes( $filtered_image );

return $loading_attrs;
return $filtered_image;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* Description: Advanced media tools that take advantage of Rekognition and Tachyon.
* Author: Human Made Limited
* License: GPL-3.0
* Version: 0.5.7
* Version: 0.5.8
*/

namespace HM\Media;
Expand Down

0 comments on commit 645780c

Please sign in to comment.