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: [https://github.com/php/php-src/blob/PHP-7.0.0/UPGRADING#L626 PHP 7.0 Upgrade Notes: array_column()].

Props uofaberdeendarren, antonvlasenko, ironprogrammer, jonmackintosh, costdev, hellofromTonya, swissspidy, rudlinkon.
Fixes #56271.
Built from https://develop.svn.wordpress.org/trunk@53927


git-svn-id: http://core.svn.wordpress.org/trunk@53486 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Sergey Biryukov 2022-08-23 14:52:12 +00:00
parent cf54dd1b24
commit 08f5675e1c
2 changed files with 2 additions and 2 deletions

View File

@ -696,7 +696,7 @@ function get_block_templates( $query = array(), $template_type = 'wp_template' )
$is_not_custom = false === array_search(
wp_get_theme()->get_stylesheet() . '//' . $template_file['slug'],
array_column( $query_result, 'id' ),
wp_list_pluck( $query_result, 'id' ),
true
);
$fits_slug_query =

View File

@ -16,7 +16,7 @@
*
* @global string $wp_version
*/
$wp_version = '6.1-alpha-53924';
$wp_version = '6.1-alpha-53927';
/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.