Editor: Fix block type and block metadata collection registration issues on Windows due to lack of path normalization.
Props flixos90, gziolo, joemcgill. Fixes #63027. Built from https://develop.svn.wordpress.org/trunk@59938 git-svn-id: http://core.svn.wordpress.org/trunk@59280 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
@@ -445,11 +445,13 @@ function register_block_type_from_metadata( $file_or_folder, $args = array() ) {
|
|||||||
* Using a static variable ensures that the metadata is only read once per request.
|
* Using a static variable ensures that the metadata is only read once per request.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
$file_or_folder = wp_normalize_path( $file_or_folder );
|
||||||
|
|
||||||
$metadata_file = ( ! str_ends_with( $file_or_folder, 'block.json' ) ) ?
|
$metadata_file = ( ! str_ends_with( $file_or_folder, 'block.json' ) ) ?
|
||||||
trailingslashit( $file_or_folder ) . 'block.json' :
|
trailingslashit( $file_or_folder ) . 'block.json' :
|
||||||
$file_or_folder;
|
$file_or_folder;
|
||||||
|
|
||||||
$is_core_block = str_starts_with( $file_or_folder, ABSPATH . WPINC );
|
$is_core_block = str_starts_with( $file_or_folder, wp_normalize_path( ABSPATH . WPINC ) );
|
||||||
$metadata_file_exists = $is_core_block || file_exists( $metadata_file );
|
$metadata_file_exists = $is_core_block || file_exists( $metadata_file );
|
||||||
$registry_metadata = WP_Block_Metadata_Registry::get_metadata( $file_or_folder );
|
$registry_metadata = WP_Block_Metadata_Registry::get_metadata( $file_or_folder );
|
||||||
|
|
||||||
|
|||||||
@@ -82,7 +82,7 @@ class WP_Block_Metadata_Registry {
|
|||||||
* @return bool True if the collection was registered successfully, false otherwise.
|
* @return bool True if the collection was registered successfully, false otherwise.
|
||||||
*/
|
*/
|
||||||
public static function register_collection( $path, $manifest ) {
|
public static function register_collection( $path, $manifest ) {
|
||||||
$path = wp_normalize_path( rtrim( $path, '/' ) );
|
$path = rtrim( wp_normalize_path( $path ), '/' );
|
||||||
|
|
||||||
$collection_roots = self::get_default_collection_roots();
|
$collection_roots = self::get_default_collection_roots();
|
||||||
|
|
||||||
@@ -112,7 +112,7 @@ class WP_Block_Metadata_Registry {
|
|||||||
$collection_roots = array_unique(
|
$collection_roots = array_unique(
|
||||||
array_map(
|
array_map(
|
||||||
static function ( $allowed_root ) {
|
static function ( $allowed_root ) {
|
||||||
return rtrim( $allowed_root, '/' );
|
return rtrim( wp_normalize_path( $allowed_root ), '/' );
|
||||||
},
|
},
|
||||||
$collection_roots
|
$collection_roots
|
||||||
)
|
)
|
||||||
@@ -161,6 +161,8 @@ class WP_Block_Metadata_Registry {
|
|||||||
* @return array|null The block metadata for the block, or null if not found.
|
* @return array|null The block metadata for the block, or null if not found.
|
||||||
*/
|
*/
|
||||||
public static function get_metadata( $file_or_folder ) {
|
public static function get_metadata( $file_or_folder ) {
|
||||||
|
$file_or_folder = wp_normalize_path( $file_or_folder );
|
||||||
|
|
||||||
$path = self::find_collection_path( $file_or_folder );
|
$path = self::find_collection_path( $file_or_folder );
|
||||||
if ( ! $path ) {
|
if ( ! $path ) {
|
||||||
return null;
|
return null;
|
||||||
@@ -194,7 +196,7 @@ class WP_Block_Metadata_Registry {
|
|||||||
* @return string[] List of block metadata file paths, or an empty array if the given `$path` is invalid.
|
* @return string[] List of block metadata file paths, or an empty array if the given `$path` is invalid.
|
||||||
*/
|
*/
|
||||||
public static function get_collection_block_metadata_files( $path ) {
|
public static function get_collection_block_metadata_files( $path ) {
|
||||||
$path = wp_normalize_path( rtrim( $path, '/' ) );
|
$path = rtrim( wp_normalize_path( $path ), '/' );
|
||||||
|
|
||||||
if ( ! isset( self::$collections[ $path ] ) ) {
|
if ( ! isset( self::$collections[ $path ] ) ) {
|
||||||
_doing_it_wrong(
|
_doing_it_wrong(
|
||||||
@@ -213,6 +215,7 @@ class WP_Block_Metadata_Registry {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return array_map(
|
return array_map(
|
||||||
|
// No normalization necessary since `$path` is already normalized and `$block_name` is just a folder name.
|
||||||
static function ( $block_name ) use ( $path ) {
|
static function ( $block_name ) use ( $path ) {
|
||||||
return "{$path}/{$block_name}/block.json";
|
return "{$path}/{$block_name}/block.json";
|
||||||
},
|
},
|
||||||
@@ -225,8 +228,8 @@ class WP_Block_Metadata_Registry {
|
|||||||
*
|
*
|
||||||
* @since 6.7.0
|
* @since 6.7.0
|
||||||
*
|
*
|
||||||
* @param string $file_or_folder The path to the file or folder.
|
* @param string $file_or_folder The normalized path to the file or folder.
|
||||||
* @return string|null The collection path if found, or null if not found.
|
* @return string|null The normalized collection path if found, or null if not found.
|
||||||
*/
|
*/
|
||||||
private static function find_collection_path( $file_or_folder ) {
|
private static function find_collection_path( $file_or_folder ) {
|
||||||
if ( empty( $file_or_folder ) ) {
|
if ( empty( $file_or_folder ) ) {
|
||||||
@@ -234,7 +237,7 @@ class WP_Block_Metadata_Registry {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Check the last matched collection first, since block registration usually happens in batches per plugin or theme.
|
// Check the last matched collection first, since block registration usually happens in batches per plugin or theme.
|
||||||
$path = wp_normalize_path( rtrim( $file_or_folder, '/' ) );
|
$path = rtrim( $file_or_folder, '/' );
|
||||||
if ( self::$last_matched_collection && str_starts_with( $path, self::$last_matched_collection ) ) {
|
if ( self::$last_matched_collection && str_starts_with( $path, self::$last_matched_collection ) ) {
|
||||||
return self::$last_matched_collection;
|
return self::$last_matched_collection;
|
||||||
}
|
}
|
||||||
@@ -279,7 +282,7 @@ class WP_Block_Metadata_Registry {
|
|||||||
*
|
*
|
||||||
* @since 6.7.0
|
* @since 6.7.0
|
||||||
*
|
*
|
||||||
* @param string $path The file or folder path to determine the block identifier from.
|
* @param string $path The normalized file or folder path to determine the block identifier from.
|
||||||
* @return string The block identifier, or an empty string if the path is empty.
|
* @return string The block identifier, or an empty string if the path is empty.
|
||||||
*/
|
*/
|
||||||
private static function default_identifier_callback( $path ) {
|
private static function default_identifier_callback( $path ) {
|
||||||
@@ -302,8 +305,8 @@ class WP_Block_Metadata_Registry {
|
|||||||
*
|
*
|
||||||
* @since 6.7.2
|
* @since 6.7.2
|
||||||
*
|
*
|
||||||
* @param string $path Block metadata collection path, without trailing slash.
|
* @param string $path Normalized block metadata collection path, without trailing slash.
|
||||||
* @param string[] $collection_roots List of collection root paths, without trailing slashes.
|
* @param string[] $collection_roots List of normalized collection root paths, without trailing slashes.
|
||||||
* @return bool True if the path is allowed, false otherwise.
|
* @return bool True if the path is allowed, false otherwise.
|
||||||
*/
|
*/
|
||||||
private static function is_valid_collection_path( $path, $collection_roots ) {
|
private static function is_valid_collection_path( $path, $collection_roots ) {
|
||||||
|
|||||||
@@ -16,7 +16,7 @@
|
|||||||
*
|
*
|
||||||
* @global string $wp_version
|
* @global string $wp_version
|
||||||
*/
|
*/
|
||||||
$wp_version = '6.8-beta1-59937';
|
$wp_version = '6.8-beta1-59938';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
||||||
|
|||||||
Reference in New Issue
Block a user