Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change editor asset from init to enqueue_block_editor_assets #2243

Merged
merged 3 commits into from
Jan 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .dev/tests/phpunit/includes/test-coblocks-block-assets.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public function test_construct_actions() {

$actions = [
[ 'enqueue_block_assets', 'block_assets' ],
[ 'init', 'editor_assets' ],
[ 'enqueue_block_editor_assets', 'editor_assets' ],
[ 'wp_enqueue_scripts', 'frontend_scripts' ],
];

Expand Down
35 changes: 13 additions & 22 deletions includes/class-coblocks-block-assets.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,7 @@ public static function register() {
*/
public function __construct() {
add_action( 'enqueue_block_assets', array( $this, 'block_assets' ) );
add_action( 'init', array( $this, 'editor_assets' ) );
add_action( 'enqueue_block_editor_assets', array( $this, 'editor_scripts' ) );
add_action( 'enqueue_block_editor_assets', array( $this, 'editor_assets' ) );
add_action( 'enqueue_block_editor_assets', array( $this, 'frontend_scripts' ) );
add_action( 'wp_enqueue_scripts', array( $this, 'frontend_scripts' ) );
add_action( 'save_post_wp_template_part', array( $this, 'clear_template_transients' ) );
Expand Down Expand Up @@ -144,6 +143,18 @@ public function block_assets() {
* @access public
*/
public function editor_assets() {
// Define where the vendor asset is loaded from.
$vendors_dir = CoBlocks()->asset_source( 'js/vendors' );

// Required by the events block.
wp_enqueue_script(
'coblocks-slick',
$vendors_dir . '/slick.js',
array( 'jquery' ),
COBLOCKS_VERSION,
true
);

// Styles.
$name = 'coblocks-1';
$filepath = 'dist/' . $name;
Expand Down Expand Up @@ -519,26 +530,6 @@ public function has_coblocks_block( WP_Post $post_object ) {

}

/**
* Enqueue editor scripts for blocks.
*
* @access public
* @since 1.9.5
*/
public function editor_scripts() {
// Define where the vendor asset is loaded from.
$vendors_dir = CoBlocks()->asset_source( 'js/vendors' );

// Required by the events block.
wp_enqueue_script(
'coblocks-slick',
$vendors_dir . '/slick.js',
array( 'jquery' ),
COBLOCKS_VERSION,
true
);
}

/**
* Return whether a post type should display the Block Editor.
*
Expand Down
2 changes: 1 addition & 1 deletion includes/class-coblocks-settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public static function register() {
*/
public function __construct() {
add_action( 'init', array( $this, 'register_settings' ) );
add_action( 'init', array( $this, 'coblocks_settings_assets' ) );
add_action( 'enqueue_block_editor_assets', array( $this, 'coblocks_settings_assets' ), 11 );
add_action( 'wp_loaded', array( $this, 'coblocks_feature_propagation' ) );
}

Expand Down