Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

61436 wp get loading optimization attributes with src #6830

Closed
Show file tree
Hide file tree
Changes from 18 commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
efc4882
Fix Uncaught exception Error with message 'Call to undefined function…
deepakrohillas May 15, 2024
8332cbf
Merge pull request #1 from deepakrohillas/deepakrohillas-patch-hello_…
deepakrohillas May 15, 2024
9c32016
Fix Hello Dolly : Uncaught exception 'Error' with message ' suggested…
deepakrohillas May 16, 2024
e0bf93f
Merge branch 'WordPress:trunk' into trunk
deepakrohillas May 23, 2024
b542011
PHP message: PHP Fatal error: Uncaught Error: Undefined constant "ABS…
deepakrohillas May 23, 2024
e9bfe06
remove changes
deepakrohillas May 23, 2024
ca3bcf4
Merge branch 'WordPress:trunk' into trunk
deepakrohillas May 24, 2024
0bb77bc
Update hello.php
deepakrohillas May 27, 2024
e66ea99
Merge branch 'WordPress:trunk' into trunk
deepakrohillas May 29, 2024
f296585
Merge branch 'WordPress:trunk' into trunk
deepakrohillas Jun 4, 2024
1cf6ece
Merge branch 'WordPress:trunk' into trunk
deepakrohillas Jun 4, 2024
d5e2ba2
'src' not in for wp_get_loading_optimization_attributes
deepakrohillas Jun 15, 2024
e4244fb
'src' not in for wp_get_loading_optimization_attributes
deepakrohillas Jun 15, 2024
1b78c26
Merge branch 'WordPress:trunk' into 61436_wp_get_loading_optimization…
deepakrohillas Jun 15, 2024
e9da81d
Update media.php
deepakrohillas Jul 4, 2024
8d07549
Update media.php
deepakrohillas Jul 4, 2024
0a60f55
PHP cs fixed extra white space
deepakrohillas Jul 5, 2024
d6bc0d2
Use closure in unit test instead of separate method.
felixarntz Sep 3, 2024
46ab7ba
Enhance test to cover modified code fix.
felixarntz Sep 3, 2024
171f805
Merge branch 'trunk' into 61436_wp_get_loading_optimization_attribute…
felixarntz Sep 3, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/wp-includes/media.php
Original file line number Diff line number Diff line change
Expand Up @@ -1969,6 +1969,7 @@ function wp_filter_content_tags( $content, $context = null ) {
* @return string Converted `img` tag with optimization attributes added.
*/
function wp_img_tag_add_loading_optimization_attrs( $image, $context ) {
$src = preg_match( '/ src=["\']?([^"\']*)/i', $image, $matche_src ) ? $matche_src[1] : null;
$width = preg_match( '/ width=["\']([0-9]+)["\']/', $image, $match_width ) ? (int) $match_width[1] : null;
$height = preg_match( '/ height=["\']([0-9]+)["\']/', $image, $match_height ) ? (int) $match_height[1] : null;
$loading_val = preg_match( '/ loading=["\']([A-Za-z]+)["\']/', $image, $match_loading ) ? $match_loading[1] : null;
Expand All @@ -1983,6 +1984,7 @@ function wp_img_tag_add_loading_optimization_attrs( $image, $context ) {
$optimization_attrs = wp_get_loading_optimization_attributes(
'img',
array(
'src' => $src,
'width' => $width,
'height' => $height,
'loading' => $loading_val,
Expand Down
36 changes: 36 additions & 0 deletions tests/phpunit/tests/media.php
Original file line number Diff line number Diff line change
Expand Up @@ -5553,6 +5553,42 @@ public function test_wp_get_loading_optimization_attributes_if_loading_attr_pres
);
}

/**
* @ticket 61436
felixarntz marked this conversation as resolved.
Show resolved Hide resolved
*
* @covers ::wp_get_loading_optimization_attributes
*/
public function test_wp_get_loading_optimization_attributes_image_src_matched() {
add_filter(
'wp_get_loading_optimization_attributes',
static function ( $loading_attrs, $tag_name, $attr ) {
if (
'img' === $tag_name &&
isset( $attr['src'] ) &&
'https://example.org/a-specific-image.jpg' === $attr['src']
) {
$loading_attrs['fetchpriority'] = 'high';
felixarntz marked this conversation as resolved.
Show resolved Hide resolved
}
return $loading_attrs;
},
10,
3
);
$attr = array(
'src' => 'https://example.org/a-specific-image.jpg',
);

// fetchpriority is high when image src is matched.
$this->assertSameSetsWithIndex(
array(
'decoding' => 'async',
'fetchpriority' => 'high',
felixarntz marked this conversation as resolved.
Show resolved Hide resolved
),
wp_get_loading_optimization_attributes( 'img', $attr, 'the_content' ),
felixarntz marked this conversation as resolved.
Show resolved Hide resolved
'fetchpriority should be high when src is matched.'
felixarntz marked this conversation as resolved.
Show resolved Hide resolved
);
}

/**
* @ticket 58235
*
Expand Down
Loading