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

MU WPCOM: Port enqueue_coblocks_gallery_scripts from the ETK #38731

Merged
merged 4 commits into from
Aug 7, 2024
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
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.