From d88ca091073052ec28f7d8d7cd76d695c812cb1a Mon Sep 17 00:00:00 2001 From: fumikito Date: Fri, 10 Jan 2020 20:09:00 +0900 Subject: [PATCH] Fix register assets timing. --- .../WpBlockCreator/Pattern/AbstractBlock.php | 32 +++++++++---------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/src/Hametuha/WpBlockCreator/Pattern/AbstractBlock.php b/src/Hametuha/WpBlockCreator/Pattern/AbstractBlock.php index 0d1e45a..8c8fe0c 100644 --- a/src/Hametuha/WpBlockCreator/Pattern/AbstractBlock.php +++ b/src/Hametuha/WpBlockCreator/Pattern/AbstractBlock.php @@ -16,16 +16,16 @@ abstract class AbstractBlock extends Singleton { use NamingConventions, Path; - + protected $prefix = ''; - + protected $block_name = ''; - + /** * @var bool If set to true, skip this block. */ protected $disabled = false; - + /** * {@inheritDoc} */ @@ -33,17 +33,17 @@ protected function init() { if ( $this->disabled || ! function_exists( 'register_block_type' ) ) { return; } - add_action( 'init', [ $this, 'register_assets' ] ); - add_action( 'init', [ $this, 'register_block' ] ); + add_action( 'init', [ $this, 'register_assets' ], 20 ); + add_action( 'init', [ $this, 'register_block' ], 30 ); add_action( 'enqueue_block_assets', [ $this, 'enqueue_block_assets' ] ); add_action( 'enqueue_block_editor_assets', [ $this, 'enqueue_block_editor_assets' ] ); } - + /** * Enqueue something both editor and front end. */ public function enqueue_block_assets() {} - + /** * Enqueue something only on editor. */ @@ -57,7 +57,7 @@ public function enqueue_block_editor_assets() {} public function register_assets() { do_action( 'hametuha_block_creator_register_assets', $this->get_block_base() ); } - + /** * Register block. */ @@ -73,7 +73,7 @@ public function register_block() { $args = apply_filters( 'hametuha_block_creator_attributes', $this->filter_attributes( $args ), $this->get_block_name() ); register_block_type( $this->get_block_name(), $args ); } - + /** * Filter attributes. * @@ -84,7 +84,7 @@ public function register_block() { protected function filter_attributes( $args ) { return $args; } - + /** * Set prefix. * @@ -93,14 +93,14 @@ protected function filter_attributes( $args ) { public function set_prefix( $prefix ) { $this->prefix = preg_replace( '/-$/u', '', $prefix ); } - + /** * Get scripts for block. * * @return string */ abstract protected function get_script(); - + /** * Get style to include. * @@ -109,7 +109,7 @@ abstract protected function get_script(); protected function get_style() { return ''; } - + /** * Use property or kebab case of class name. * @@ -120,10 +120,10 @@ protected function get_block_base() { return $this->block_name; } list( $class_name ) = array_reverse( explode( "\\", get_called_class() ) ); - + return $this->camel_to_kebab( $class_name ); } - + /** * Get block name. *