Skip to content
This repository was archived by the owner on Dec 23, 2020. It is now read-only.

Commit b64c890

Browse files
committed
Rename wp_add_lazy_loading_to to wp_lazy_loading_enabled.
1 parent 07eb7e9 commit b64c890

File tree

2 files changed

+12
-12
lines changed

2 files changed

+12
-12
lines changed

tests/phpunit/tests/media.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,10 @@ function test_wp_lazy_load_content_media_opted_in() {
7676
$content_filtered = sprintf( $content, $lazy_img, $lazy_iframe );
7777

7878
// Enable globally for all tags.
79-
add_filter( 'wp_add_lazy_loading_to', '__return_true' );
79+
add_filter( 'wp_lazy_loading_enabled', '__return_true' );
8080

8181
$this->assertSame( $content_filtered, wp_add_lazy_load_attributes( $content_unfiltered ) );
82-
remove_filter( 'wp_add_lazy_loading_to', '__return_true' );
82+
remove_filter( 'wp_lazy_loading_enabled', '__return_true' );
8383
}
8484

8585
/**
@@ -94,9 +94,9 @@ function test_wp_lazy_load_content_media_opted_out() {
9494
$content = sprintf( $content, $img );
9595

9696
// Disable globally for all tags.
97-
add_filter( 'wp_add_lazy_loading_to', '__return_false' );
97+
add_filter( 'wp_lazy_loading_enabled', '__return_false' );
9898

9999
$this->assertSame( $content, wp_add_lazy_load_attributes( $content ) );
100-
remove_filter( 'wp_add_lazy_loading_to', '__return_false' );
100+
remove_filter( 'wp_lazy_loading_enabled', '__return_false' );
101101
}
102102
}

wp-lazy-loading.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ function _wp_lazy_loading_initialize_filters() {
6262
* @return string Modified tag.
6363
*/
6464
function _wp_lazy_loading_add_attribute_to_avatar( $avatar ) {
65-
if ( wp_add_lazy_loading_to( 'img', 'get_avatar' ) && false === strpos( $avatar, ' loading=' ) ) {
65+
if ( wp_lazy_loading_enabled( 'img', 'get_avatar' ) && false === strpos( $avatar, ' loading=' ) ) {
6666
$avatar = str_replace( '<img ', '<img loading="lazy" ', $avatar );
6767
}
6868

@@ -83,7 +83,7 @@ function _wp_lazy_loading_add_attribute_to_avatar( $avatar ) {
8383
* @return array Modified attributes.
8484
*/
8585
function _wp_lazy_loading_add_attribute_to_attachment_image( $attr ) {
86-
if ( wp_add_lazy_loading_to( 'img', 'wp_get_attachment_image' ) && ! isset( $attr['loading'] ) ) {
86+
if ( wp_lazy_loading_enabled( 'img', 'wp_get_attachment_image' ) && ! isset( $attr['loading'] ) ) {
8787
$attr['loading'] = 'lazy';
8888
}
8989

@@ -102,21 +102,21 @@ function _wp_lazy_loading_add_attribute_to_attachment_image( $attr ) {
102102
* @param string $context Additional context, like the current filter name or the function name from where this was called.
103103
* @return boolean Whether to add the attribute.
104104
*/
105-
function wp_add_lazy_loading_to( $tag_name, $context ) {
105+
function wp_lazy_loading_enabled( $tag_name, $context ) {
106106
// By default add to all 'img' tags.
107107
// See https://github.com/whatwg/html/issues/2806
108-
$add = ( 'img' === $tag_name );
108+
$default = ( 'img' === $tag_name );
109109

110110
/**
111111
* Filters whether to add the `loading` attribute to the specified tag in the specified context.
112112
*
113113
* @since (TBD)
114114
*
115-
* @param boolean $add Defatls value.
115+
* @param boolean $default Defatls value.
116116
* @param string $tag_name The tag name.
117117
* @param string $context Additional context, like the current filter name or the function name from where this was called.
118118
*/
119-
return (bool) apply_filters( 'wp_add_lazy_loading_to', $add, $tag_name, $context );
119+
return (bool) apply_filters( 'wp_lazy_loading_enabled', $default, $tag_name, $context );
120120
}
121121

122122

@@ -140,12 +140,12 @@ function wp_add_lazy_load_attributes( $content, $context = null ) {
140140
$context = current_filter();
141141
}
142142

143-
if ( wp_add_lazy_loading_to( 'img', $context ) ) {
143+
if ( wp_lazy_loading_enabled( 'img', $context ) ) {
144144
$tags[] = 'img';
145145
}
146146

147147
// Experimental. Will be removed when merging unless the HTML specs are updated by that time.
148-
if ( wp_add_lazy_loading_to( 'iframe', $context ) ) {
148+
if ( wp_lazy_loading_enabled( 'iframe', $context ) ) {
149149
$tags[] = 'iframe';
150150
}
151151

0 commit comments

Comments
 (0)