Repository navigation
Expand file tree
/
Copy pathmasterblocks.php
More file actions
63 lines (53 loc) · 1.66 KB
/
Copy pathmasterblocks.php
File metadata and controls
63 lines (53 loc) · 1.66 KB
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
<?php
/**
* Plugin Name: MasterBlocks
* Description: Custom blocks to enhance the gutenberg editing experience.
* Requires at least: 6.1
* Requires PHP: 8.0
* Version: 0.1.0
* Author: Arischvaran Puvanesvaran
* License: GPL-2.0-or-later
* License URI: https://www.gnu.org/licenses/gpl-2.0.html
* Text Domain: masterblocks
*
* @package MasterBlocks
*/
namespace MasterBlocks;
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly.
}
define( 'MASTERBLOCKS_VERSION', '0.1.0' );
define( 'MASTERBLOCKS_PLUGIN_DIR', plugin_dir_path( __FILE__ ) );
define( 'MASTERBLOCKS_PLUGIN_URL', plugin_dir_url( __FILE__ ) );
/**
* Init blocks.
*/
function masterblocks_init() {
$directory_path = MASTERBLOCKS_PLUGIN_DIR . 'src/';
$directories = scandir( $directory_path, SCANDIR_SORT_NONE );
foreach ( $directories as $directory ) {
// Skip '.' and '..' from directory.
if ( '.' === $directory || '..' === $directory ) {
continue;
}
$file_path = $directory_path . $directory;
// Check if directory and name is valid.
if ( is_dir( $file_path ) && preg_match( '/^[a-zA-Z0-9_-]+$/', $directory ) ) {
register_block_type( __DIR__ . '/build/' . $directory );
}
}
}
add_action( 'init', __NAMESPACE__ . '\masterblocks_init' );
/**
* Add custom category for blocks.
*
* @param array $categories - Array of categories.
*/
function masterblocks_custom_category( $categories ) {
$categories[] = array(
'slug' => 'masterblocks',
'title' => __( 'MasterBlocks', 'masterblocks' ),
);
return $categories;
}
add_filter( 'block_categories', __NAMESPACE__ . '\masterblocks_custom_category', 10, 2 );