Skip to content

Commit

Permalink
Merge branch 'release/1.0.6'
Browse files Browse the repository at this point in the history
  • Loading branch information
jakubmikita committed Mar 19, 2022
2 parents 91457f0 + d2c90d6 commit 02331a6
Show file tree
Hide file tree
Showing 5 changed files with 96 additions and 71 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
# Changelog
All notable changes to this project will be documented in this file.

## 1.0.6

* [Removed] `block_categories` deprecated filter
* [Changed] Updated Composer dependencies

## 1.0.5

* [Fixed] Deprecated filter name being used
Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
<img src="https://bracketspace.com/extras/micropackage/micropackage-small.png" alt="Micropackage logo"/>
</p>

Requires WordPress >=5.8.0.

## 🧬 About Block Loader

Block Loader loads the Gutenberg Block configuration directly out of the block template file. It parses the file header comment figuring out hwo to register the Block.
Expand Down Expand Up @@ -133,7 +135,7 @@ All parameters are optional.
| Parameter | Type | Description |
| -------------------------- | ----------------- | ------------------------------------------------------------ |
| **dir** | (*string*) | This is a directory within your theme where block templates are located. Relative path.<br/>**Default:** `'blocks'` |
| **categories** | (*array*) | Array of custom block categories passed directly to [`block_categories`](https://developer.wordpress.org/reference/hooks/block_categories/) filter.<br />If only one category will be configured, it will be used as default category for all custom blocks.<br />**Default:** `[]` (empty array) |
| **categories** | (*array*) | Array of custom block categories passed directly to [`block_categories_all`](https://developer.wordpress.org/reference/hooks/block_categories_all/) filter.<br />If only one category will be configured, it will be used as default category for all custom blocks.<br />**Default:** `[]` (empty array) |
| **wrap** | (*false\|string*) | Wrapper to each block. If set to false, the block content will be just the template file content.<br/>Works only for ACF due to the differences in block rendering mechanisms.<br/>**Default:** `'<div id="%3$s" class="%2$s">%1$s</div>'` |
| `...$block_creator_params` | - | Additional parameters passed to [ACF Block Creator](https://github.com/micropackage/acf-block-creator/) |

Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "micropackage/block-loader",
"version": "1.0.5",
"version": "1.0.6",
"description": "Block Loader - automatic Gutenberg blocks from template files.",
"license": "GPL-3.0-or-later",
"authors": [
Expand All @@ -24,7 +24,7 @@
"micropackage/filesystem": "^1.1"
},
"require-dev": {
"dealerdirect/phpcodesniffer-composer-installer": "^0.5.0",
"dealerdirect/phpcodesniffer-composer-installer": "^0.7.0",
"phpcompatibility/php-compatibility": "^9.1",
"wp-coding-standards/wpcs": "^2.0"
},
Expand Down
124 changes: 82 additions & 42 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

30 changes: 4 additions & 26 deletions src/BlockLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,6 @@ public static function init( $config = [] ) {
*/
private $config;

/**
* Flag that categories has been added.
*
* @var boolean
*/
private $categories_added = false;

/**
* Headers to read from template files
*
Expand Down Expand Up @@ -109,7 +102,7 @@ protected function __construct( $config ) {
$this->default_category = $this->categories[0]['slug'];
}

if ( class_exists( 'Micropackage\\ACFBlockCreator\\ACFBlockCreator' ) ) {
if ( class_exists( ACFBlockCreator::class ) ) {
$block_creator_config = array_filter( $this->config, function( $value, $key ) {
return in_array( $key, [
'blocks_dir',
Expand Down Expand Up @@ -338,32 +331,17 @@ public function get_unique_block_id( $id ) {
/**
* Registers custom block category.
*
* `block_categories` filter is deprecated but has been left here for backward compatibility.
*
* @filter block_categories_all
* @filter block_categories
*
* @since 1.0.0
* @param array $categories Block categories.
* @param \WP_Post|\WP_Block_Editor_Context $context Block editor context or post object.
* @param array $categories Block categories.
* @param \WP_Block_Editor_Context $context Block editor context.
*/
public function block_categories( $categories, $context ) {
$is_deprecated_hook = $context instanceof \WP_Post;

if (
$this->categories &&
( ! $is_deprecated_hook || false === $this->categories_added )
) {
if ( $this->categories ) {
$categories = array_merge( $categories, $this->categories );
}

/**
* `block_categories_all` filter gets executed first, then deprecated `block_categories` gets executed if there is a
* post object available. So we set the flag that the categories has been added already in the first case and reset it
* in the other.
*/
$this->categories_added = ! $is_deprecated_hook;

return $categories;
}

Expand Down

0 comments on commit 02331a6

Please sign in to comment.