From 4aaa643106e9880e233db9a72b17867d0037e915 Mon Sep 17 00:00:00 2001 From: jc_dkonakh Date: Wed, 14 Aug 2019 11:32:55 +0300 Subject: [PATCH 1/2] add support for ACF Gutenberg block --- framework/ACF/ACF_Gutenberg.php | 94 +++++++++++++++++++++++++++++++++ 1 file changed, 94 insertions(+) create mode 100644 framework/ACF/ACF_Gutenberg.php diff --git a/framework/ACF/ACF_Gutenberg.php b/framework/ACF/ACF_Gutenberg.php new file mode 100644 index 0000000..2e56256 --- /dev/null +++ b/framework/ACF/ACF_Gutenberg.php @@ -0,0 +1,94 @@ +register_block() + */ + abstract public function init(); + + + /** + * Register ACF Gutenberg Block. + */ + public function register_block() { + $block_defaults = array( + 'category' => 'formatting', + 'icon' => 'admin-generic', + ); + + add_filter( 'jc_register_acf_gutenberg_block', function ( $blocks, $block_defaults ) { + array_push( $blocks, array( + 'name' => $this->slug, + 'title' => $this->title, + 'description' => $this->description, + 'icon' => $this->icon, + 'keywords' => $this->keywords, + 'render_template' => get_stylesheet_directory() . '/views/blocks/' . $this->slug . '.php', + ) ); + + return $blocks; + }, 10, 2 ); + + $blocks = apply_filters( 'jc_register_acf_gutenberg_block', array(), $block_defaults ); + + foreach ( $blocks as $block ) { + $block = wp_parse_args( $block, $block_defaults ); + + acf_register_block( $block ); + + if ( isset( $block['fields'] ) ) { + acf_add_local_field_group( $block['fields'] ); + } + } + } +} \ No newline at end of file From ae1feb5cd757bd9100f48e0c2dbcc428bcba9dd8 Mon Sep 17 00:00:00 2001 From: Vitaly Germanov Date: Wed, 17 Nov 2021 13:40:49 +0200 Subject: [PATCH 2/2] rework class to avoid blocks duplication fatal error --- framework/ACF/ACF_Gutenberg.php | 40 ++++++++++++++------------------- 1 file changed, 17 insertions(+), 23 deletions(-) diff --git a/framework/ACF/ACF_Gutenberg.php b/framework/ACF/ACF_Gutenberg.php index 2e56256..f534604 100644 --- a/framework/ACF/ACF_Gutenberg.php +++ b/framework/ACF/ACF_Gutenberg.php @@ -2,9 +2,11 @@ namespace JustCoded\WP\Framework\ACF; - use JustCoded\WP\Framework\Objects\Singleton; +/** + * Class ACF_Gutenberg + */ abstract class ACF_Gutenberg { use Singleton; @@ -60,35 +62,27 @@ abstract public function init(); /** * Register ACF Gutenberg Block. */ - public function register_block() { + public function register_block(): void { $block_defaults = array( 'category' => 'formatting', 'icon' => 'admin-generic', ); - add_filter( 'jc_register_acf_gutenberg_block', function ( $blocks, $block_defaults ) { - array_push( $blocks, array( - 'name' => $this->slug, - 'title' => $this->title, - 'description' => $this->description, - 'icon' => $this->icon, - 'keywords' => $this->keywords, - 'render_template' => get_stylesheet_directory() . '/views/blocks/' . $this->slug . '.php', - ) ); - - return $blocks; - }, 10, 2 ); - - $blocks = apply_filters( 'jc_register_acf_gutenberg_block', array(), $block_defaults ); + $block = array( + 'name' => $this->slug, + 'title' => $this->title, + 'description' => $this->description, + 'icon' => $this->icon, + 'keywords' => $this->keywords, + 'render_template' => get_stylesheet_directory() . '/views/blocks/' . $this->slug . '.php', + ); - foreach ( $blocks as $block ) { - $block = wp_parse_args( $block, $block_defaults ); + $block = wp_parse_args( $block, $block_defaults ); - acf_register_block( $block ); + acf_register_block( $block ); - if ( isset( $block['fields'] ) ) { - acf_add_local_field_group( $block['fields'] ); - } + if ( isset( $block['fields'] ) ) { + acf_add_local_field_group( $block['fields'] ); } } -} \ No newline at end of file +}