-
Notifications
You must be signed in to change notification settings - Fork 0
/
easy-blocks-for-gutenberg.php
71 lines (61 loc) · 2.05 KB
/
easy-blocks-for-gutenberg.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
<?php
/**
* Plugin Name: Easy Blocks For Gutenberg
* Description: Easy Blocks is simple block for Gutenberg.
* Plugin URI: https://easyblocks.abdul-k.com/
* Version: 1.0.0
* Requires at least: 5.2
* Requires PHP: 7.2
* Author: Md Abdul Kader
* Author URI: https://abdul-k.com/
* License: GPL-2.0-or-later
* License URI: https://www.gnu.org/licenses/gpl-2.0.html
* Text Domain: ebfg
* Domain Path: /languages
*
* @package create-block
*/
/**
* 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 ebfg_block_init() {
$blocks = [
'header',
'card',
'service',
'infobox',
'flipbox',
'gallery'
];
foreach( $blocks as $block ) {
register_block_type( plugin_dir_path( __FILE__ ) . 'build/blocks/' . $block );
}
// register_block_type_from_metadata( __DIR__ . '/build/blocks/iconbox' );
// register_block_type_from_metadata( __DIR__ . '/build/blocks/infobox' );
}
add_action( 'init', 'ebfg_block_init' );
function ebfg_block_enqueue_scripts() {
$asset_file = require plugin_dir_path( __FILE__ ) . 'build/index.asset.php';
wp_enqueue_style('fontawesome', 'https://use.fontawesome.com/releases/v5.8.1/css/all.css', '', '5.8.1', 'all');
wp_enqueue_script( 'ebfg-block-main', plugins_url( '/build/index.js', __FILE__ ), $asset_file['dependencies'], 1.0, false);
}
add_action( 'enqueue_block_editor_assets', 'ebfg_block_enqueue_scripts');
// New Managing block categories custom_blocks_category
function ebfg_block_category($block_categories, $editor_context) {
if (!empty($editor_context->post)) {
array_push(
$block_categories,
array(
'slug' => 'ebfg-block',
'title' => __('Easy Blocks', 'ebfg'),
'icon' => null,
)
);
}
return $block_categories;
}
add_filter('block_categories_all', 'ebfg_block_category', 10, 2);