Skip to:
Content

BuddyPress.org

Ticket #8340: 8340.noiframe-fixunittest.patch

File 8340.noiframe-fixunittest.patch, 2.4 KB (added by imath, 4 years ago)
  • src/bp-core/bp-core-filters.php

    diff --git src/bp-core/bp-core-filters.php src/bp-core/bp-core-filters.php
    index ec84a6990..789145f95 100644
    add_filter( 'bp_email_set_content_html', 'stripslashes', 8 ); 
    5959add_filter( 'bp_email_set_content_plaintext', 'wp_strip_all_tags', 6 );
    6060add_filter( 'bp_email_set_subject', 'sanitize_text_field', 6 );
    6161
     62// Avatars.
     63add_filter( 'bp_core_fetch_avatar', 'bp_core_add_loading_lazy_attribute' );
     64
    6265/**
    6366 * Template Compatibility.
    6467 *
    function bp_core_filter_edit_post_link( $edit_link = '', $post_id = 0 ) { 
    899902        return $edit_link;
    900903}
    901904
     905/**
     906 * Add 'loading="lazy"' attribute into images.
     907 *
     908 * @since 7.0.0
     909 *
     910 * @string $content Content to inject attribute into.
     911 * @return string
     912 */
     913function bp_core_add_loading_lazy_attribute( $content = '' ) {
     914        if ( false === strpos( $content, '<img ' ) ) {
     915                return $content;
     916        }
     917
     918        $content = str_replace( '<img ', '<img loading="lazy" ', $content );
     919        return $content;
     920}
     921
    902922/**
    903923 * Should BuddyPress load the mentions scripts and related assets, including results to prime the
    904924 * mentions suggestions?
  • tests/phpunit/testcases/core/avatars.php

    diff --git tests/phpunit/testcases/core/avatars.php tests/phpunit/testcases/core/avatars.php
    index b56bf73b6..10ce03d6b 100644
    class BP_Tests_Avatars extends BP_UnitTestCase { 
    166166
    167167                }
    168168
    169                 $expected_html = '<img src="' . $avatar_url . '" id="' . $this->params['css_id'] . '" class="' . $this->params['class'] . ' ' . $this->params['object'] . '-' . $this->params['item_id'] . '-avatar avatar-' . $this->params['width'] . ' photo" width="' . $this->params['width'] . '" height="' . $this->params['height'] . '" alt="' . $this->params['alt'] . '" title="' . $this->params['title'] . '" ' . $this->params['extra_attr'] . ' />';
     169                $expected_html = '<img loading="lazy" src="' . $avatar_url . '" id="' . $this->params['css_id'] . '" class="' . $this->params['class'] . ' ' . $this->params['object'] . '-' . $this->params['item_id'] . '-avatar avatar-' . $this->params['width'] . ' photo" width="' . $this->params['width'] . '" height="' . $this->params['height'] . '" alt="' . $this->params['alt'] . '" title="' . $this->params['title'] . '" ' . $this->params['extra_attr'] . ' />';
    170170
    171171                $this->assertEquals( $html, $expected_html );
    172172        }