diff --git a/CHANGELOG.md b/CHANGELOG.md index 4f68b52..1dda55f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,11 @@ # Changelog All notable changes to this project will be documented in this file. +## 1.0.5 + +* [Fixed] Invalid `micropackage/acf-block-creator/config` hookname +* [Added] Filters for block tamplate and style file paths + ## 1.0.4 * [Fixed] block setup fields behavior diff --git a/composer.json b/composer.json index 600f14f..6584aaa 100644 --- a/composer.json +++ b/composer.json @@ -1,6 +1,6 @@ { "name": "micropackage/acf-block-creator", - "version": "1.0.4", + "version": "1.0.5", "description": "ACF Block Creator - automatic block creation add-on for ACF", "license": "GPL-3.0-or-later", "authors": [ diff --git a/src/ACFBlockCreator.php b/src/ACFBlockCreator.php index f2913cb..29f39e1 100644 --- a/src/ACFBlockCreator.php +++ b/src/ACFBlockCreator.php @@ -62,7 +62,7 @@ public static function init( $config = [] ) { */ protected function __construct( $config ) { $this->config = apply_filters( - 'micropackage/acf-block-loader/config', + 'micropackage/acf-block-creator/config', wp_parse_args( $config, [ 'blocks_dir' => 'blocks', 'scss_dir' => false, @@ -276,14 +276,45 @@ public function update_field_group( $field_group ) { $template ); - $this->root_fs->put_contents( "{$this->config['blocks_dir']}/{$slug}.php", preg_replace( '/(^[\r\n]*|[\r\n]+)[\s\t]*[\r\n]+/', "\n\n", $template ) ); + $template_dir = apply_filters( + 'micropackage/acf-block-creator/block-template-dir', + $this->config['blocks_dir'], + $slug + ); + + $template_file = apply_filters( + 'micropackage/acf-block-creator/block-template-file', + "{$slug}.php", + $slug + ); + + if ( ! $this->maybe_mkdir( $template_dir ) ) { + return; + } + + $this->root_fs->put_contents( + "{$template_dir}/{$template_file}", + preg_replace( '/(^[\r\n]*|[\r\n]+)[\s\t]*[\r\n]+/', "\n\n", $template ) + ); + + $scss_dir = apply_filters( + 'micropackage/acf-block-creator/block-style-dir', + $this->config['scss_dir'], + $slug + ); // Create block scss partial. - if ( is_string( $this->config['scss_dir'] ) ) { + if ( is_string( $scss_dir ) ) { + $scss_file = apply_filters( + 'micropackage/acf-block-creator/block-style-file', + "_{$slug}.scss", + $slug + ); + $scss = ".block.$slug {\n/* stylelint-disable */\n}"; - if ( $this->maybe_mkdir( $this->config['scss_dir'] ) ) { - $this->root_fs->put_contents( "{$this->config['scss_dir']}/_{$slug}.scss", $scss ); + if ( $this->maybe_mkdir( $scss_dir ) ) { + $this->root_fs->put_contents( "{$scss_dir}/{$scss_file}", $scss ); } }