Skip to content

Commit

Permalink
MU WPCOM: Port enqueue_coblocks_gallery_scripts from the ETK (#38731)
Browse files Browse the repository at this point in the history
* MU WPCOM: Port enqueue_coblocks_gallery_scripts from the ETK

* changelog

* Fix versions

* Fix lint
  • Loading branch information
arthur791004 authored Aug 7, 2024
1 parent d49e2d3 commit efac4fd
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: minor
Type: added

MU WPCOM: Port enqueue_coblocks_gallery_scripts from the ETK
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ public static function load_etk_features_flags() {
return;
}

define( 'MU_WPCOM_COBLOCKS_GALLERY', true );
define( 'MU_WPCOM_CUSTOM_LINE_HEIGHT', true );
define( 'MU_WPCOM_BLOCK_INSERTER_MODIFICATIONS', true );
define( 'MU_WPCOM_HOMEPAGE_TITLE_HIDDEN', true );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,3 +132,52 @@ function load_wpcom_fse() {
add_action( 'init', __NAMESPACE__ . '\wpcom_fse_register_template_post_types' );
}
add_action( 'plugins_loaded', __NAMESPACE__ . '\load_wpcom_fse' );

/**
* Add front-end CoBlocks gallery block scripts.
*
* This function performs the same enqueueing duties as `CoBlocks_Block_Assets::frontend_scripts`,
* but for dotcom FSE header and footer content. `frontend_scripts` uses
* `has_block` to determine if gallery blocks are present, and `has_block` is
* not aware of content sections outside of post_content yet.
*/
function enqueue_coblocks_gallery_scripts() {
if ( ! defined( 'COBLOCKS_VERSION' ) || ! function_exists( 'CoBlocks' ) || ! is_full_site_editing_active() ) {
return;
}

$template = new WP_Template();
$header = $template->get_template_content( 'header' );
$footer = $template->get_template_content( 'footer' );

// Define where the asset is loaded from.
// @phan-suppress-next-line PhanUndeclaredFunction
$dir = CoBlocks()->asset_source( 'js' );

// Define where the vendor asset is loaded from.
// @phan-suppress-next-line PhanUndeclaredFunction
$vendors_dir = CoBlocks()->asset_source( 'js', 'vendors' );

// Masonry block.
if ( has_block( 'coblocks/gallery-masonry', $header . $footer ) ) {
wp_enqueue_script(
'coblocks-masonry',
$dir . 'coblocks-masonry.min.js',
array( 'jquery', 'masonry', 'imagesloaded' ),
COBLOCKS_VERSION,
true
);
}

// Carousel block.
if ( has_block( 'coblocks/gallery-carousel', $header . $footer ) ) {
wp_enqueue_script(
'coblocks-flickity',
$vendors_dir . '/flickity.js',
array( 'jquery' ),
COBLOCKS_VERSION,
true
);
}
}
add_action( 'wp_enqueue_scripts', __NAMESPACE__ . '\enqueue_coblocks_gallery_scripts' );
5 changes: 5 additions & 0 deletions projects/plugins/mu-wpcom-plugin/changelog/mu-wpcom-coblocks
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Significance: patch
Type: changed
Comment: Updated composer.lock.


5 changes: 5 additions & 0 deletions projects/plugins/wpcomsh/changelog/mu-wpcom-coblocks
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Significance: patch
Type: changed
Comment: Updated composer.lock.


0 comments on commit efac4fd

Please sign in to comment.