|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * Plugin Name: Blocks Gamestore |
| 4 | + * Description: Example block scaffolded with Create Block tool. |
| 5 | + * Version: 1.0.0 |
| 6 | + * Requires at least: 6.7 |
| 7 | + * Requires PHP: 7.4 |
| 8 | + * Author: The WordPress Contributors |
| 9 | + * License: GPL-2.0-or-later |
| 10 | + * License URI: https://www.gnu.org/licenses/gpl-2.0.html |
| 11 | + * Text Domain: blocks-gamestore |
| 12 | + * |
| 13 | + * @package CreateBlock |
| 14 | + */ |
| 15 | + |
| 16 | +if ( ! defined( 'ABSPATH' ) ) { |
| 17 | + exit; // Exit if accessed directly. |
| 18 | +} |
| 19 | +/** |
| 20 | + * Registers the block using a `blocks-manifest.php` file, which improves the performance of block type registration. |
| 21 | + * Behind the scenes, it also registers all assets so they can be enqueued |
| 22 | + * through the block editor in the corresponding context. |
| 23 | + * |
| 24 | + * @see https://make.wordpress.org/core/2025/03/13/more-efficient-block-type-registration-in-6-8/ |
| 25 | + * @see https://make.wordpress.org/core/2024/10/17/new-block-type-registration-apis-to-improve-performance-in-wordpress-6-7/ |
| 26 | + */ |
| 27 | +function create_block_blocks_gamestore_block_init() { |
| 28 | + /** |
| 29 | + * Registers the block(s) metadata from the `blocks-manifest.php` and registers the block type(s) |
| 30 | + * based on the registered block metadata. |
| 31 | + * Added in WordPress 6.8 to simplify the block metadata registration process added in WordPress 6.7. |
| 32 | + * |
| 33 | + * @see https://make.wordpress.org/core/2025/03/13/more-efficient-block-type-registration-in-6-8/ |
| 34 | + */ |
| 35 | + if ( function_exists( 'wp_register_block_types_from_metadata_collection' ) ) { |
| 36 | + wp_register_block_types_from_metadata_collection( __DIR__ . '/build', __DIR__ . '/build/blocks-manifest.php' ); |
| 37 | + return; |
| 38 | + } |
| 39 | + |
| 40 | + /** |
| 41 | + * Registers the block(s) metadata from the `blocks-manifest.php` file. |
| 42 | + * Added to WordPress 6.7 to improve the performance of block type registration. |
| 43 | + * |
| 44 | + * @see https://make.wordpress.org/core/2024/10/17/new-block-type-registration-apis-to-improve-performance-in-wordpress-6-7/ |
| 45 | + */ |
| 46 | + if ( function_exists( 'wp_register_block_metadata_collection' ) ) { |
| 47 | + wp_register_block_metadata_collection( __DIR__ . '/build', __DIR__ . '/build/blocks-manifest.php' ); |
| 48 | + } |
| 49 | + /** |
| 50 | + * Registers the block type(s) in the `blocks-manifest.php` file. |
| 51 | + * |
| 52 | + * @see https://developer.wordpress.org/reference/functions/register_block_type/ |
| 53 | + */ |
| 54 | + $manifest_data = require __DIR__ . '/build/blocks-manifest.php'; |
| 55 | + foreach ( array_keys( $manifest_data ) as $block_type ) { |
| 56 | + register_block_type( __DIR__ . "/build/{$block_type}" ); |
| 57 | + } |
| 58 | +} |
| 59 | +add_action( 'init', 'create_block_blocks_gamestore_block_init' ); |
0 commit comments