Make WordPress Core


Ignore:
Timestamp:
08/23/2022 02:54:57 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.
Merges [53927] to the 6.0 branch.
Fixes #56271.

Location:
branches/6.0
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/6.0

  • branches/6.0/src/wp-includes/block-template-utils.php

    r53405 r53928  
    706706            $is_not_custom   = false === array_search(
    707707                wp_get_theme()->get_stylesheet() . '//' . $template_file['slug'],
    708                 array_column( $query_result, 'id' ),
     708                wp_list_pluck( $query_result, 'id' ),
    709709                true
    710710            );
Note: See TracChangeset for help on using the changeset viewer.