Make WordPress Core


Ignore:
Timestamp:
05/17/2022 02:36:22 PM (2 years ago)
Author:
gziolo
Message:

Editor: Return additional block patterns to server-generated settings

Reverts changes from [53155] to ensure backward compatibility.

Companion to Gutenberg changes https://github.com/WordPress/gutenberg/pull/40818. That makes sure that patterns registered with admin_init or current_screen hooks are not lost.

Props jsnajdr, zieladam, peterwilsoncc, johnstonphilip.
See #55567.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/class-wp-block-pattern-categories-registry.php

    r53299 r53404  
    1919     */
    2020    private $registered_categories = array();
     21
     22    /**
     23     * Pattern categories registered outside the `init` action.
     24     *
     25     * @since 6.0.0
     26     * @var array[]
     27     */
     28    private $registered_categories_outside_init = array();
    2129
    2230    /**
     
    5159        }
    5260
    53         $this->registered_categories[ $category_name ] = array_merge(
     61        $category = array_merge(
    5462            array( 'name' => $category_name ),
    5563            $category_properties
    5664        );
     65
     66        $this->registered_categories[ $category_name ] = $category;
     67
     68        // If the category is registered inside an action other than `init`, store it
     69        // also to a dedicated array. Used to detect deprecated registrations inside
     70        // `admin_init` or `current_screen`.
     71        if ( current_action() && 'init' !== current_action() ) {
     72            $this->registered_categories_outside_init[ $category_name ] = $category;
     73        }
    5774
    5875        return true;
     
    7996
    8097        unset( $this->registered_categories[ $category_name ] );
     98        unset( $this->registered_categories_outside_init[ $category_name ] );
    8199
    82100        return true;
     
    104122     * @since 5.5.0
    105123     *
     124     * @param bool $outside_init_only Return only categories registered outside the `init` action.
    106125     * @return array[] Array of arrays containing the registered pattern categories properties.
    107126     */
    108     public function get_all_registered() {
    109         return array_values( $this->registered_categories );
     127    public function get_all_registered( $outside_init_only = false ) {
     128        return array_values(
     129            $outside_init_only
     130                ? $this->registered_categories_outside_init
     131                : $this->registered_categories
     132        );
    110133    }
    111134
Note: See TracChangeset for help on using the changeset viewer.