Changeset 54276
- Timestamp:
- 09/21/2022 01:55:25 PM (2 years ago)
- Location:
- trunk
- Files:
-
- 1 added
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Gruntfile.js
r53688 r54276 4 4 var webpackConfig = require( './webpack.config' ); 5 5 var installChanged = require( 'install-changed' ); 6 var json2php = require( 'json2php' ); 6 7 7 8 module.exports = function(grunt) { … … 1404 1405 } ); 1405 1406 1407 grunt.registerTask( 'copy:block-json', 'Copies block.json file contents to block-json.php.', function() { 1408 var blocks = {}; 1409 grunt.file.recurse( SOURCE_DIR + 'wp-includes/blocks', function( abspath, rootdir, subdir, filename ) { 1410 if ( /^block\.json$/.test( filename ) ) { 1411 blocks[ subdir ] = grunt.file.readJSON( abspath ); 1412 } 1413 } ); 1414 grunt.file.write( 1415 SOURCE_DIR + 'wp-includes/blocks/blocks-json.php', 1416 '<?php return ' + json2php( blocks ) + ';' 1417 ); 1418 } ); 1419 1406 1420 grunt.registerTask( 'copy:js', [ 1407 1421 'copy:npm-packages', … … 1452 1466 'clean:files', 1453 1467 'copy:files', 1468 'copy:block-json', 1454 1469 'copy:version', 1455 1470 ] ); -
trunk/package-lock.json
r54261 r54276 4327 4327 "json2php": "^0.0.4", 4328 4328 "webpack-sources": "^3.2.2" 4329 }, 4330 "dependencies": { 4331 "json2php": { 4332 "version": "0.0.4", 4333 "resolved": "https://registry.npmjs.org/json2php/-/json2php-0.0.4.tgz", 4334 "integrity": "sha512-hFzejhs28f70sGnutcsRS459MnAsjRVI85RgPAL1KQIZEpjiDitc27CZv4IgOtaR86vrqOVlu9vJNew2XyTH4g==", 4335 "dev": true 4336 } 4329 4337 } 4330 4338 }, … … 17764 17772 }, 17765 17773 "json2php": { 17766 "version": "0.0.4", 17767 "resolved": "https://registry.npmjs.org/json2php/-/json2php-0.0.4.tgz", 17768 "integrity": "sha512-hFzejhs28f70sGnutcsRS459MnAsjRVI85RgPAL1KQIZEpjiDitc27CZv4IgOtaR86vrqOVlu9vJNew2XyTH4g==", 17769 "dev": true 17774 "version": "0.0.5", 17775 "resolved": "https://registry.npmjs.org/json2php/-/json2php-0.0.5.tgz", 17776 "integrity": "sha512-jWpsGAYlQDKOjJcyq3rYaxcZ+5YMhZIKHKTjdIKJPI9zLSX+yRWHSSwtV8hvIg7YMhbKkgPO669Ve2ZgFK5C7w==" 17770 17777 }, 17771 17778 "json5": { -
trunk/package.json
r54257 r54276 144 144 "jquery-form": "4.3.0", 145 145 "jquery-hoverintent": "1.10.2", 146 "json2php": "^0.0.5", 146 147 "lodash": "4.17.21", 147 148 "masonry-layout": "4.2.2", -
trunk/src/wp-includes/blocks.php
r54181 r54276 284 284 */ 285 285 function register_block_type_from_metadata( $file_or_folder, $args = array() ) { 286 $filename = 'block.json'; 287 $metadata_file = ( substr( $file_or_folder, -strlen( $filename ) ) !== $filename ) ? 288 trailingslashit( $file_or_folder ) . $filename : 286 /* 287 * Get an array of metadata from a PHP file. 288 * This improves performance for core blocks as it's only necessary to read a single PHP file 289 * instead of reading a JSON file per-block, and then decoding from JSON to PHP. 290 * Using a static variable ensures that the metadata is only read once per request. 291 */ 292 static $core_blocks_meta; 293 if ( ! $core_blocks_meta ) { 294 $core_blocks_meta = include_once ABSPATH . WPINC . '/blocks/blocks-json.php'; 295 } 296 297 $metadata_file = ( ! str_ends_with( $file_or_folder, 'block.json' ) ) ? 298 trailingslashit( $file_or_folder ) . 'block.json' : 289 299 $file_or_folder; 300 290 301 if ( ! file_exists( $metadata_file ) ) { 291 302 return false; 292 303 } 293 304 294 $metadata = wp_json_file_decode( $metadata_file, array( 'associative' => true ) ); 305 // Try to get metadata from the static cache for core blocks. 306 $metadata = false; 307 if ( str_starts_with( $file_or_folder, ABSPATH . WPINC ) ) { 308 $core_block_name = str_replace( ABSPATH . WPINC . '/blocks/', '', $file_or_folder ); 309 if ( ! empty( $core_blocks_meta[ $core_block_name ] ) ) { 310 $metadata = $core_blocks_meta[ $core_block_name ]; 311 } 312 } 313 314 // If metadata is not found in the static cache, read it from the file. 315 if ( ! $metadata ) { 316 $metadata = wp_json_file_decode( $metadata_file, array( 'associative' => true ) ); 317 } 318 295 319 if ( ! is_array( $metadata ) || empty( $metadata['name'] ) ) { 296 320 return false;
Note: See TracChangeset
for help on using the changeset viewer.