Make WordPress Core

Changeset 53927


Ignore:
Timestamp:
08/23/2022 02:50:56 PM (2 years ago)
Author:
SergeyBiryukov
Message:

Editor: Ensure get_block_templates() returns unique templates or template parts.

The function was using the array_column() PHP function on an array of objects, which works as expected on PHP 7 or later, but not on PHP 5.6.

This resulted in customized templates being listed multiple times on the Templates and Template Parts screens, and being repeatedly added between lists when switching between the screens.

The issue is now resolved by replacing array_column() with the wp_list_pluck() WordPress core function, which provides consistent behavior beetween PHP versions.

Reference: PHP 7.0 Upgrade Notes: array_column().

Props uofaberdeendarren, antonvlasenko, ironprogrammer, jonmackintosh, costdev, hellofromTonya, swissspidy, rudlinkon.
Fixes #56271.

Location:
trunk
Files:
1 added
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/block-template-utils.php

    r53757 r53927  
    697697            $is_not_custom   = false === array_search(
    698698                wp_get_theme()->get_stylesheet() . '//' . $template_file['slug'],
    699                 array_column( $query_result, 'id' ),
     699                wp_list_pluck( $query_result, 'id' ),
    700700                true
    701701            );
Note: See TracChangeset for help on using the changeset viewer.