File tree 4 files changed +67
-8
lines changed
4 files changed +67
-8
lines changed Original file line number Diff line number Diff line change 1
1
# Changelog
2
2
All notable changes to this project will be documented in this file.
3
3
4
+ ## 1.0.4
5
+
6
+ * [ Added] Possibility to load blocks from subfolders (block-name/template.php instead of the default block-name.php)
7
+ * [ Fixed] Error with invalid array key if file didn't have a block header
8
+ * [ Fixed] Hardcoded default blocks path
9
+ * [ Fixed] Missing Filesystem dependency, thanks to @joshuafredrickson
10
+
4
11
## 1.0.3
5
12
6
13
* [ Added] Filters for config
Original file line number Diff line number Diff line change 1
1
{
2
2
"name" : " micropackage/block-loader" ,
3
- "version" : " 1.0.3 " ,
3
+ "version" : " 1.0.4 " ,
4
4
"description" : " Block Loader - automatic Gutenberg blocks from template files." ,
5
5
"license" : " GPL-3.0-or-later" ,
6
6
"authors" : [
20
20
"require" : {
21
21
"php" : " >=5.6" ,
22
22
"micropackage/singleton" : " ^1.1" ,
23
- "micropackage/dochooks" : " ^1.0"
23
+ "micropackage/dochooks" : " ^1.0" ,
24
+ "micropackage/filesystem" : " ^1.1"
24
25
},
25
26
"require-dev" : {
26
27
"dealerdirect/phpcodesniffer-composer-installer" : " ^0.5.0" ,
Original file line number Diff line number Diff line change @@ -185,7 +185,7 @@ public function register_metabox_blocks( $meta_boxes ) {
185
185
public function get_blocks () {
186
186
$ paths = apply_filters (
187
187
'micropackage/block-loader/paths ' ,
188
- [ wp_normalize_path ( "$ this ->root_dir /blocks " ) ]
188
+ [ wp_normalize_path ( "{ $ this ->root_dir } / { $ this -> config [ ' dir ' ]} " ) ]
189
189
);
190
190
191
191
$ blocks = [];
@@ -210,11 +210,19 @@ private function get_blocks_from_path( $path ) {
210
210
211
211
if ( $ files ) {
212
212
foreach ( $ files as $ file ) {
213
- $ filepath = $ fs ->path ( $ file ['name ' ] );
213
+ if ( $ fs ->is_file ( $ file ['name ' ] ) ) {
214
+ $ filename = $ file ['name ' ];
215
+ } elseif ( $ fs ->is_file ( "{$ file ['name ' ]}/template.php " ) ) {
216
+ $ filename = "{$ file ['name ' ]}/template.php " ;
217
+ } else {
218
+ continue ;
219
+ }
220
+
221
+ $ filepath = $ fs ->path ( $ filename );
214
222
$ data = $ this ->get_block_data ( $ filepath );
215
- $ slug = basename ( $ filepath , '.php ' );
223
+ $ slug = basename ( $ file [ ' name ' ] , '.php ' );
216
224
217
- if ( ! $ data ['title ' ] ) {
225
+ if ( ! isset ( $ data ['title ' ] ) ) {
218
226
continue ;
219
227
}
220
228
You can’t perform that action at this time.
0 commit comments