Make WordPress Core


Ignore:
Timestamp:
08/02/2023 05:56:16 PM (10 months ago)
Author:
flixos90
Message:

Media: Simplify logic in wp_get_loading_optimization_attributes().

While the wp_get_loading_optimization_attributes() function was only recently introduced in 6.3, its code was mostly ported over from the now deprecated wp_get_loading_attr_default() function introduced in 5.5.

That function started out in a simple way, but over time was expanded with more and more conditionals on when to avoid lazy-loading, which ended up making the logic extremely complex and hard to follow.

This changeset refactors the logic to simplify it, in a way that allows to follow it more sequentially, and without making any functional changes, ensuring that the extensive existing unit test coverage still passes. This will facilitate future enhancements to the function to be less error-prone and make it more accessible to new contributors.

Props flixos90, joemcgill.
Fixes #58891.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/media.php

    r56214 r56347  
    49574957        $attr['fetchpriority'] = 'high';
    49584958
    4959         $this->assertSame(
     4959        $this->assertEqualSetsWithIndex(
    49604960            array(
    49614961                'loading'       => 'lazy',
Note: See TracChangeset for help on using the changeset viewer.