Skip to content

Commit c91739a

Browse files
committed
Merge branch 'release/1.0.4'
2 parents 2afdfc7 + d00733c commit c91739a

File tree

4 files changed

+67
-8
lines changed

4 files changed

+67
-8
lines changed

CHANGELOG.md

+7
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
# Changelog
22
All notable changes to this project will be documented in this file.
33

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+
411
## 1.0.3
512

613
* [Added] Filters for config

composer.json

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "micropackage/block-loader",
3-
"version": "1.0.3",
3+
"version": "1.0.4",
44
"description": "Block Loader - automatic Gutenberg blocks from template files.",
55
"license": "GPL-3.0-or-later",
66
"authors": [
@@ -20,7 +20,8 @@
2020
"require": {
2121
"php": ">=5.6",
2222
"micropackage/singleton": "^1.1",
23-
"micropackage/dochooks": "^1.0"
23+
"micropackage/dochooks": "^1.0",
24+
"micropackage/filesystem": "^1.1"
2425
},
2526
"require-dev": {
2627
"dealerdirect/phpcodesniffer-composer-installer": "^0.5.0",

composer.lock

+45-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/BlockLoader.php

+12-4
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ public function register_metabox_blocks( $meta_boxes ) {
185185
public function get_blocks() {
186186
$paths = apply_filters(
187187
'micropackage/block-loader/paths',
188-
[ wp_normalize_path( "$this->root_dir/blocks" ) ]
188+
[ wp_normalize_path( "{$this->root_dir}/{$this->config['dir']}" ) ]
189189
);
190190

191191
$blocks = [];
@@ -210,11 +210,19 @@ private function get_blocks_from_path( $path ) {
210210

211211
if ( $files ) {
212212
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 );
214222
$data = $this->get_block_data( $filepath );
215-
$slug = basename( $filepath, '.php' );
223+
$slug = basename( $file['name'], '.php' );
216224

217-
if ( ! $data['title'] ) {
225+
if ( ! isset( $data['title'] ) ) {
218226
continue;
219227
}
220228

0 commit comments

Comments
 (0)