-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgutenberg-block-development.php
110 lines (91 loc) · 2.36 KB
/
gutenberg-block-development.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
<?php
/**
* Plugin Name: Gutenberg Block Development
* Plugin URI: https://github.com/HelloTalib/gutenberg-block-development
* Description: Gutenberg Startup plugins for create new blocks
* Version: 1.0.0
* Author: TALIB
* Author URI: https://talib.netlify.app
* License: GPLv3
* Text Domain: gutenberg-block-development
* Domain Path: /languages/
*/
// Stop Direct Access
if (!defined('ABSPATH')) {
exit;
}
/**
* Blocks Final Class
*/
final class GUTENBERG_BLOCK_DEVELOPMENT {
public function __construct() {
// define constants
$this->gutenberg_block_define_constants();
// block initialization
add_action('init', [$this, 'gutenberg_block_development_init']);
// blocks category
if (version_compare($GLOBALS['wp_version'], '5.7', '<')) {
add_filter('block_categories', [$this, 'gutenberg_block_register_category'], 10, 2);
} else {
add_filter('block_categories_all', [$this, 'gutenberg_block_register_category'], 10, 2);
}
// enqueue block assets
add_action('enqueue_block_assets', [$this, 'gutenberg_block_external_libraries']);
}
/**
* Initialize the plugin
*/
public static function init() {
static $instance = false;
if (!$instance) {
$instance = new self();
}
return $instance;
}
/**
* Define the plugin constants
*/
private function gutenberg_block_define_constants() {
define('GBD_VERSION', '1.0.0');
define('GBD_URL', plugin_dir_url(__FILE__));
define('GBD_LIB_URL', GBD_URL . 'library/');
}
/**
* Blocks Registration
*/
public function gutenberg_block_register($name, $options = array()) {
register_block_type(__DIR__ . '/build/blocks/' . $name, $options);
}
/**
* Blocks Initialization
*/
public function gutenberg_block_development_init() {
// register single block
$this->gutenberg_block_register('startup');
}
/**
* Register Block Category
*/
public function gutenberg_block_register_category($categories, $post) {
return array_merge(
array(
array(
'slug' => 'gutenberg-block-development',
'title' => __('Gutenberg Block Development', 'gutenberg-block-development'),
),
),
$categories,
);
}
/**
* Enqueue Block Assets
*/
public function gutenberg_block_external_libraries() {
// enqueue JS
wp_enqueue_script('external-js', GBD_LIB_URL . 'js/plugin.js', array(), GBD_VERSION, true);
}
}
/**
* tech
*/
GUTENBERG_BLOCK_DEVELOPMENT::init();