Skip to content

Commit

Permalink
Fix register assets timing.
Browse files Browse the repository at this point in the history
  • Loading branch information
fumikito committed Jan 10, 2020
1 parent 66ff6c6 commit d88ca09
Showing 1 changed file with 16 additions and 16 deletions.
32 changes: 16 additions & 16 deletions src/Hametuha/WpBlockCreator/Pattern/AbstractBlock.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,34 +16,34 @@
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}
*/
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.
*/
Expand All @@ -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.
*/
Expand All @@ -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.
*
Expand All @@ -84,7 +84,7 @@ public function register_block() {
protected function filter_attributes( $args ) {
return $args;
}

/**
* Set prefix.
*
Expand All @@ -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.
*
Expand All @@ -109,7 +109,7 @@ abstract protected function get_script();
protected function get_style() {
return '';
}

/**
* Use property or kebab case of class name.
*
Expand All @@ -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.
*
Expand Down

0 comments on commit d88ca09

Please sign in to comment.