-
Notifications
You must be signed in to change notification settings - Fork 0
/
plugin.php
123 lines (102 loc) · 2.48 KB
/
plugin.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
<?php
/**
* Plugin Name: Layout Blocks
* Description: Provides a set of reusable layout blocks for Gutenberg.
* Version: 1.0.0
* Author: The Code Company
* Author URI: https://thecode.co
*
* @package tcc-layout-blocks
*/
namespace TheCodeCompany;
/**
* Layout engine plugin driver class.
* Here we register our blocks with WordPress and the rest is mostly React.
*/
class LayoutEngine {
/**
* Boot the plugin, register blocks etc.
*
* @return void
*/
public function boot() {
add_action( 'init', array( $this, 'hook_init' ) );
}
/**
* Called on the WP `init` hook.
*
* @return void
*/
public function hook_init() {
$this->register_blocks();
$this->register_assets();
}
/**
* Register plugin blocks in PHP.
* These are automatically registered in JS, we just need to do this so they can be filtered etc. in PHP.
*
* @return void
*/
protected function register_blocks() {
\register_block_type(
'tcc/column',
array(
'editor_script' => 'tcc-layout-engine',
'editor_style' => 'tcc-layout-engine',
)
);
\register_block_type(
'tcc/layout-1-column',
array(
'editor_script' => 'tcc-layout-engine',
'editor_style' => 'tcc-layout-engine',
)
);
\register_block_type(
'tcc/layout-2-column',
array(
'editor_script' => 'tcc-layout-engine',
'editor_style' => 'tcc-layout-engine',
)
);
\register_block_type(
'tcc/layout-3-column',
array(
'editor_script' => 'tcc-layout-engine',
'editor_style' => 'tcc-layout-engine',
)
);
\register_block_type(
'tcc/layout-4-column',
array(
'editor_script' => 'tcc-layout-engine',
'editor_style' => 'tcc-layout-engine',
)
);
}
/**
* Register the JS/CSS files to power our blocks in the wp-admin editor/Gutenberg.
*
* @return void
*/
protected function register_assets() {
// Register block script for backend/editor.
\wp_register_script(
'tcc-layout-engine',
plugins_url( '/dist/blocks.build.js', __FILE__ ),
array( 'wp-blocks', 'wp-i18n', 'wp-element', 'wp-editor' ),
filemtime( plugin_dir_path( __FILE__ ) . 'dist/blocks.build.js' ),
true
);
// Register block editor styles for backend/editor.
\wp_register_style(
'tcc-layout-engine',
plugins_url( 'dist/blocks.editor.build.css', __FILE__ ),
array( 'wp-edit-blocks' ),
filemtime( plugin_dir_path( __FILE__ ) . 'dist/blocks.editor.build.css' )
);
}
}
// Boot plugin.
$layout_engine = new LayoutEngine();
$layout_engine->boot();