-
Notifications
You must be signed in to change notification settings - Fork 2
/
eo-blocks.php
45 lines (40 loc) · 1.37 KB
/
eo-blocks.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
<?php
/**
* Plugin Name: EO Blocks
* Description: A collection of Gutenberg blocks for WordPress made by Eoxia
* Requires at least: 6.6.2
* Requires PHP: 7.0
* Version: 1.0.0
* Author: Eoxia
* License: GPL-3.0-or-later
* License URI: https://www.gnu.org/licenses/gpl-3.0.html
* Text Domain: eo-blocks
*
* @package EoBlocks
*/
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly.
}
define( 'EO_BLOCKS_BASEFILE', __FILE__ );
define( 'EO_BLOCKS_URL', plugins_url( '/', __FILE__ ) );
define( 'EO_BLOCKS_PATH', dirname( __FILE__ ) );
define( 'EO_BLOCKS_VERSION', '0.1.0' );
/**
* Registers the block using the metadata loaded from the `block.json` file.
* Behind the scenes, it registers also all assets so they can be enqueued
* through the block editor in the corresponding context.
*
* @see https://developer.wordpress.org/reference/functions/register_block_type/
*/
function eo_blocks_block_init() {
$block_build_dir = EO_BLOCKS_PATH . "/blocks/build/";
// Register all blocks in build Blocks directory.
$block_dir_urls = scandir( $block_build_dir );
foreach ( $block_dir_urls as $url ) {
$block_dir = $block_build_dir . '/' . $url;
if ( ! empty( $url ) && file_exists( $block_dir . '/block.json' ) ) {
register_block_type( $block_dir );
}
}
}
add_action( 'init', 'eo_blocks_block_init' );