ay_keys( self::$collections );
foreach ( $collection_paths as $collection_path ) {
if ( str_starts_with( $path, $collection_path ) ) {
self::$last_matched_collection = $collection_path;
return $collection_path;
}
}
return null;
}
/**
* Checks if metadata exists for a given block name in a specific collection.
*
* @since 6.7.0
*
* @param string $file_or_folder The path to the file or folder containing the block metadata.
* @return bool True if metadata exists for the block, false otherwise.
*/
public static function has_metadata( $file_or_folder ) {
return null !== self::get_metadata( $file_or_folder );
}
/**
* Default identifier function to determine the block identifier from a given path.
*
* This function extracts the block identifier from the path:
* - For 'block.json' files, it uses the parent directory name.
* - For directories, it uses the directory name itself.
* - For empty paths, it returns an empty string.
*
* For example:
* - Path: '/wp-content/plugins/my-plugin/blocks/example/block.json'
* Identifier: 'example'
* - Path: '/wp-content/plugins/my-plugin/blocks/another-block'
* Identifier: 'another-block'
*
* This default behavior matches the standard WordPress block structure.
*
* @since 6.7.0
*
* @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.
*/
private static function default_identifier_callback( $path ) {
// Ensure $path is not empty to prevent unexpected behavior.
if ( empty( $path ) ) {
return '';
}
if ( str_ends_with( $path, 'block.json' ) ) {
// Return the parent directory name if it's a block.json file.
return basename( dirname( $path ) );
}
// Otherwise, assume it's a directory and return its name.
return basename( $path );
}
/**
* Checks whether the given block metadata collection path is valid against the list of collection roots.
*
* @since 6.7.2
*
* @param string $path Normalized block metadata collection path, without trailing slash.
* @param string[] $collection_roots List of normalized collection root paths, without trailing slashes.
* @return bool True if the path is allowed, false otherwise.
*/
private static function is_valid_collection_path( $path, $collection_roots ) {
foreach ( $collection_roots as $allowed_root ) {
// If the path matches any root exactly, it is invalid.
if ( $allowed_root === $path ) {
return false;
}
// If the path is a parent path of any of the roots, it is invalid.
if ( str_starts_with( $allowed_root, $path ) ) {
return false;
}
}
return true;
}
/**
* Gets the default collection root directory paths.
*
* @since 6.7.2
*
* @return string[] List of directory paths within which metadata collections are allowed.
*/
private static function get_default_collection_roots() {
if ( isset( self::$default_collection_roots ) ) {
return self::$default_collection_roots;
}
$collection_roots = array(
wp_normalize_path( ABSPATH . WPINC ),
wp_normalize_path( WP_CONTENT_DIR ),
wp_normalize_path( WPMU_PLUGIN_DIR ),
wp_normalize_path( WP_PLUGIN_DIR ),
);
$theme_roots = get_theme_roots();
if ( ! is_array( $theme_roots ) ) {
$theme_roots = array( $theme_roots );
}
foreach ( $theme_roots as $theme_root ) {
$collection_roots[] = trailingslashit( wp_normalize_path( WP_CONTENT_DIR ) ) . ltrim( wp_normalize_path( $theme_root ), '/' );
}
self::$default_collection_roots = array_unique( $collection_roots );
return self::$default_collection_roots;
}
}
Fatal error: Uncaught Error: Class 'WP_Block_Metadata_Registry' not found in /var/www/html/tribunadainternet.com.br/web/wp-includes/blocks.php:438
Stack trace:
#0 /var/www/html/tribunadainternet.com.br/web/wp-includes/blocks/index.php(174): wp_register_block_metadata_collection('/var/www/html/t...', '/var/www/html/t...')
#1 /var/www/html/tribunadainternet.com.br/web/wp-includes/class-wp-hook.php(341): wp_register_core_block_metadata_collection('')
#2 /var/www/html/tribunadainternet.com.br/web/wp-includes/class-wp-hook.php(365): WP_Hook->apply_filters(NULL, Array)
#3 /var/www/html/tribunadainternet.com.br/web/wp-includes/plugin.php(522): WP_Hook->do_action(Array)
#4 /var/www/html/tribunadainternet.com.br/web/wp-settings.php(742): do_action('init')
#5 /var/www/html/tribunadainternet.com.br/web/wp-config.php(160): require_once('/var/www/html/t...')
#6 /var/www/html/tribunadainternet.com.br/web/wp-load.php(50): require_once('/var/www/html/t...')
#7 /var/www/html/tribunadainternet.com.br/web/wp-blog-header.php(13): require_onc in /var/www/html/tribunadainternet.com.br/web/wp-includes/blocks.php on line 438