-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathwp-beb.php
158 lines (120 loc) · 3.86 KB
/
wp-beb.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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
<?php
/**
* The plugin bootstrap file.
*
* This file is read by WordPress to generate the plugin information in the plugin
* admin area. This file also includes all of the dependencies used by the plugin,
* registers the activation and deactivation functions, and defines a function
* that starts the plugin.
*
* @link http://example.com
* @since 1.0.0
* @package WP_BEB
*
* @wordpress-plugin
* Plugin Name: WordPress Block Editor Boilerplate
* Plugin URI: https://neliosoftware.com/
* Description: A standardized, organized, modern foundation for building high-quality WordPress Plugins that extend the block editor.
* Version: 1.0.0
* Author: Nelio Software
* Author URI: https://neliosoftware.com
* License: GPL-2.0+
* License URI: http://www.gnu.org/licenses/gpl-2.0.txt
* Text Domain: wp-beb
* Domain Path: /languages
*/
if ( ! defined( 'ABSPATH' ) ) {
exit;
}//end if
/**
* WP_BEB
*/
class WP_BEB {
private static $instance = null;
public $plugin_path;
public $plugin_url;
public $plugin_name;
public $plugin_version;
public static function instance() {
if ( is_null( self::$instance ) ) {
self::$instance = new self();
self::$instance->init_options();
self::$instance->init_hooks();
}//end if
return self::$instance;
}//end instance()
public function init_options() {
$this->plugin_path = plugin_dir_path( __FILE__ );
$this->plugin_url = plugin_dir_url( __FILE__ );
// load textdomain.
load_plugin_textdomain( 'wp-beb', false, basename( dirname( __FILE__ ) ) . '/languages' );
}//end init_options()
public function init_hooks() {
add_action( 'init', [ $this, 'plugin_data_init' ] );
// Works only if Gutenberg is available.
if ( function_exists( 'register_block_type' ) ) {
// Add Demo category.
add_filter( 'block_categories', [ $this, 'block_categories' ], 9 );
// Enqueue scripts and styles.
add_action( 'enqueue_block_editor_assets', [ $this, 'enqueue_block_editor_assets' ], 9 );
}//end if
}//end init_hooks()
public function block_categories( $categories ) {
return array_merge(
$categories,
array(
array(
'slug' => 'demo',
'title' => __( 'Demo', 'wp-beb' ),
),
)
);
}//end block_categories()
public function enqueue_block_editor_assets() {
wp_enqueue_script(
'wp-beb-blocks',
untrailingslashit( plugin_dir_url( __FILE__ ) ) . '/assets/dist/js/blocks.js',
[ 'wp-editor', 'wp-i18n', 'wp-element', 'wp-data', 'wp-edit-post' ],
$this->plugin_version,
true
);
if ( function_exists( 'wp_set_script_translations' ) ) {
wp_set_script_translations( 'wp-beb-blocks', 'wp-beb' );
}//end if
wp_enqueue_style(
'wp-beb-blocks',
untrailingslashit( plugin_dir_url( __FILE__ ) ) . '/assets/dist/css/blocks.css',
[],
$this->plugin_version
);
wp_enqueue_script(
'wp-beb-plugin',
untrailingslashit( plugin_dir_url( __FILE__ ) ) . '/assets/dist/js/plugin.js',
[ 'wp-editor', 'wp-i18n', 'wp-element', 'wp-data', 'wp-edit-post' ],
$this->plugin_version,
true
);
if ( function_exists( 'wp_set_script_translations' ) ) {
wp_set_script_translations( 'wp-beb-plugin', 'wp-beb' );
}//end if
wp_enqueue_style(
'wp-beb-plugin',
untrailingslashit( plugin_dir_url( __FILE__ ) ) . '/assets/dist/css/plugin.css',
[],
$this->plugin_version
);
}//end enqueue_block_editor_assets()
public function plugin_data_init() {
$data = get_file_data( __FILE__, [ 'Plugin Name', 'Version' ], 'plugin' );
$this->plugin_name = $data[0];
$this->plugin_version = $data[1];
$this->plugin_slug = plugin_basename( __FILE__, '.php' );
$this->plugin_name_sanitized = basename( __FILE__, '.php' );
}//end plugin_data_init()
public function admin_menu() {
}//end admin_menu()
}
function wp_beb() {
return WP_BEB::instance();
}//end wp_beb()
add_action( 'plugins_loaded', 'wp_beb' );