Skip to content

Commit

Permalink
VideoPress: improve asset enqueuing for P2 and Classic themes (#33042)
Browse files Browse the repository at this point in the history
* [not verified] re-add asset enqueueing logic with extra care for P2s

* [not verified] changelog
  • Loading branch information
CGastrell authored Sep 15, 2023
1 parent 2da6ccb commit becaca5
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: minor
Type: changed

Add VideoPress assets enqueuing logic after the revert c9fa94de7886af75b65b8c75e642fb529144eb31 (reverted d5ca47d8de53df832e67ac8b9d6bda3663c3e8df). This time P2s should not be affected.
31 changes: 31 additions & 0 deletions projects/packages/videopress/src/class-initializer.php
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,37 @@ public static function register_videopress_video_block() {
return;
}

// check current theme
$is_block_theme = wp_get_theme()->is_block_theme();

// Check if the site is a P2 site
$is_p2_site = function_exists( '\WPForTeams\is_wpforteams_site' ) && \WPForTeams\is_wpforteams_site( get_current_blog_id() );

// for non block themes frontend, we defer the enqueuing to the frontend, so we're able to tell if we need the assets
// If site is p2, load the assets in the frontend
if ( ! $is_block_theme && ! is_admin() && ! $is_p2_site ) {
add_action(
'wp_enqueue_scripts',
function () use ( $videopress_video_metadata_file ) {
$post_content = get_the_content();

if ( ! has_block( 'videopress/video', $post_content ) && ! has_shortcode( $post_content, 'videopress' ) ) {
return;
}
self::enqueue_block_assets( $videopress_video_metadata_file );
}
);
return;
}
self::enqueue_block_assets( $videopress_video_metadata_file );
}

/**
* Enqueue scripts used by the VideoPress video block and register block type.
*
* @param string $videopress_video_metadata_file Path to the block metadata file.
*/
public static function enqueue_block_assets( $videopress_video_metadata_file ) {
// Register script used by the VideoPress video block in the editor.
Assets::register_script(
self::JETPACK_VIDEOPRESS_VIDEO_HANDLER,
Expand Down

0 comments on commit becaca5

Please sign in to comment.