diff --git a/wp-admin/edit-form-blocks.php b/wp-admin/edit-form-blocks.php index 8fdea59a18..a842facd49 100644 --- a/wp-admin/edit-form-blocks.php +++ b/wp-admin/edit-form-blocks.php @@ -209,6 +209,10 @@ $editor_settings = array( 'enableCustomFields' => (bool) get_user_meta( get_current_user_id(), 'enable_custom_fields', true ), ); +// Add additional back-compat patterns registered by `current_screen` et al. +$editor_settings['__experimentalAdditionalBlockPatterns'] = WP_Block_Patterns_Registry::get_instance()->get_all_registered( true ); +$editor_settings['__experimentalAdditionalBlockPatternCategories'] = WP_Block_Pattern_Categories_Registry::get_instance()->get_all_registered( true ); + $autosave = wp_get_post_autosave( $post->ID ); if ( $autosave ) { if ( mysql2date( 'U', $autosave->post_modified_gmt, false ) > mysql2date( 'U', $post->post_modified_gmt, false ) ) { diff --git a/wp-admin/site-editor.php b/wp-admin/site-editor.php index 317660909c..9fac7e62c7 100644 --- a/wp-admin/site-editor.php +++ b/wp-admin/site-editor.php @@ -68,6 +68,11 @@ $custom_settings = array( 'defaultTemplatePartAreas' => get_allowed_block_template_part_areas(), '__unstableHomeTemplate' => $home_template, ); + +// Add additional back-compat patterns registered by `current_screen` et al. +$custom_settings['__experimentalAdditionalBlockPatterns'] = WP_Block_Patterns_Registry::get_instance()->get_all_registered( true ); +$custom_settings['__experimentalAdditionalBlockPatternCategories'] = WP_Block_Pattern_Categories_Registry::get_instance()->get_all_registered( true ); + $editor_settings = get_block_editor_settings( $custom_settings, $block_editor_context ); if ( isset( $_GET['postType'] ) && ! isset( $_GET['postId'] ) ) { diff --git a/wp-includes/class-wp-block-pattern-categories-registry.php b/wp-includes/class-wp-block-pattern-categories-registry.php index b223dbf4a2..f4d881c4e2 100644 --- a/wp-includes/class-wp-block-pattern-categories-registry.php +++ b/wp-includes/class-wp-block-pattern-categories-registry.php @@ -19,6 +19,14 @@ final class WP_Block_Pattern_Categories_Registry { */ private $registered_categories = array(); + /** + * Pattern categories registered outside the `init` action. + * + * @since 6.0.0 + * @var array[] + */ + private $registered_categories_outside_init = array(); + /** * Container for the main instance of the class. * @@ -50,11 +58,20 @@ final class WP_Block_Pattern_Categories_Registry { return false; } - $this->registered_categories[ $category_name ] = array_merge( + $category = array_merge( array( 'name' => $category_name ), $category_properties ); + $this->registered_categories[ $category_name ] = $category; + + // If the category is registered inside an action other than `init`, store it + // also to a dedicated array. Used to detect deprecated registrations inside + // `admin_init` or `current_screen`. + if ( current_action() && 'init' !== current_action() ) { + $this->registered_categories_outside_init[ $category_name ] = $category; + } + return true; } @@ -78,6 +95,7 @@ final class WP_Block_Pattern_Categories_Registry { } unset( $this->registered_categories[ $category_name ] ); + unset( $this->registered_categories_outside_init[ $category_name ] ); return true; } @@ -103,10 +121,15 @@ final class WP_Block_Pattern_Categories_Registry { * * @since 5.5.0 * + * @param bool $outside_init_only Return only categories registered outside the `init` action. * @return array[] Array of arrays containing the registered pattern categories properties. */ - public function get_all_registered() { - return array_values( $this->registered_categories ); + public function get_all_registered( $outside_init_only = false ) { + return array_values( + $outside_init_only + ? $this->registered_categories_outside_init + : $this->registered_categories + ); } /** diff --git a/wp-includes/class-wp-block-patterns-registry.php b/wp-includes/class-wp-block-patterns-registry.php index e08d10bc28..81ee2e261c 100644 --- a/wp-includes/class-wp-block-patterns-registry.php +++ b/wp-includes/class-wp-block-patterns-registry.php @@ -21,6 +21,14 @@ final class WP_Block_Patterns_Registry { */ private $registered_patterns = array(); + /** + * Patterns registered outside the `init` action. + * + * @since 6.0.0 + * @var array[] + */ + private $registered_patterns_outside_init = array(); + /** * Container for the main instance of the class. * @@ -92,10 +100,18 @@ final class WP_Block_Patterns_Registry { return false; } - $this->registered_patterns[ $pattern_name ] = array_merge( + $pattern = array_merge( $pattern_properties, array( 'name' => $pattern_name ) ); + $this->registered_patterns[ $pattern_name ] = $pattern; + + // If the pattern is registered inside an action other than `init`, store it + // also to a dedicated array. Used to detect deprecated registrations inside + // `admin_init` or `current_screen`. + if ( current_action() && 'init' !== current_action() ) { + $this->registered_patterns_outside_init[ $pattern_name ] = $pattern; + } return true; } @@ -120,6 +136,7 @@ final class WP_Block_Patterns_Registry { } unset( $this->registered_patterns[ $pattern_name ] ); + unset( $this->registered_patterns_outside_init[ $pattern_name ] ); return true; } @@ -145,11 +162,16 @@ final class WP_Block_Patterns_Registry { * * @since 5.5.0 * + * @param bool $outside_init_only Return only patterns registered outside the `init` action. * @return array[] Array of arrays containing the registered block patterns properties, * and per style. */ - public function get_all_registered() { - return array_values( $this->registered_patterns ); + public function get_all_registered( $outside_init_only = false ) { + return array_values( + $outside_init_only + ? $this->registered_patterns_outside_init + : $this->registered_patterns + ); } /** diff --git a/wp-includes/version.php b/wp-includes/version.php index ef91d91b62..5f01ab0704 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -16,7 +16,7 @@ * * @global string $wp_version */ -$wp_version = '6.1-alpha-53403'; +$wp_version = '6.1-alpha-53404'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.