Skip to content

Commit

Permalink
Merge branch 'release/v1.3.7'
Browse files Browse the repository at this point in the history
  • Loading branch information
wpmark committed Oct 30, 2024
2 parents 2d9c76c + 032ec94 commit 0e47a7e
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 26 deletions.
74 changes: 49 additions & 25 deletions better-core-video-embeds.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
Description: A plugin which enhances the core video embeds for Youtube and Vimeo videos by not loading unnecessary scripts until they are needed.
Requires at least: 6.0
Requires PHP: 7.0
Version: 1.3.6
Version: 1.3.7
Author: Highrise Digital
Author URI: https://highrise.digital/
License: GPL-2.0-or-later
Expand All @@ -15,7 +15,7 @@
// define variable for path to this plugin file.
define( 'HD_BCVE_LOCATION', dirname( __FILE__ ) );
define( 'HD_BCVE_LOCATION_URL', plugins_url( '', __FILE__ ) );
define( 'HD_BCVE_VERSION', '1.3.6' );
define( 'HD_BCVE_VERSION', '1.3.7' );

/**
* Function to run on plugins load.
Expand All @@ -33,24 +33,45 @@ function hd_bcve_plugins_loaded() {
/**
* Enqueues the frontend JS for the plugin.
*/
function hd_bcve_enqueue_scripts() {
function hd_bcve_register_enqueue_scripts() {

// register the script for the front end.
wp_register_script(
'better-core-video-embeds-js',
HD_BCVE_LOCATION_URL . '/assets/js/better-core-video-embeds.min.js',
false,
HD_BCVE_VERSION,
true
);

// only if the page has a core embed block present.
if ( has_block( 'core/embed' ) ) {
}

// enqueue the front end script to invoking the video embed on image click.
wp_enqueue_script(
'better-core-video-embeds-js',
HD_BCVE_LOCATION_URL . '/assets/js/better-core-video-embeds.min.js',
false,
HD_BCVE_VERSION,
true
add_action( 'init', 'hd_bcve_register_enqueue_scripts' );

/**
* Add the front end JS to the core/embed block metadata.
*
* @param array $metadata The block metadata.
* @return array $metadata The block metadata.
*/
function hd_bcve_filter_embed_metadata( $metadata ) {

// if this is the core/embed block.
if ( 'core/embed' === $metadata['name'] ) {

$metadata['viewScript'] = array_merge(
(array) ( $metadata['viewScript'] ?? array() ),
['better-core-video-embeds-js']
);

}

// return the metadata.
return $metadata;

}

add_action( 'wp_enqueue_scripts', 'hd_bcve_enqueue_scripts' );
add_filter( 'block_type_metadata', 'hd_bcve_filter_embed_metadata' );

/**
* Enqueues the block editor JS for the plugin.
Expand Down Expand Up @@ -78,22 +99,25 @@ function hd_bcve_enqueue_block_editor_assets() {
*/
function hd_bcve_register_block_style() {

// only if the page has a core embed block present.
if ( has_block( 'core/embed' ) ) {

// register the style for this block.
wp_enqueue_style(
'better-core-video-embeds-styles',
HD_BCVE_LOCATION_URL . '/assets/css/better-core-video-embeds.min.css',
[],
HD_BCVE_VERSION
);
// register the block styles.
wp_register_style(
'better-core-video-embeds-styles',
HD_BCVE_LOCATION_URL . '/assets/css/better-core-video-embeds.min.css',
[],
HD_BCVE_VERSION
);

}
// enqueue the registered block style.
wp_enqueue_block_style(
'core/embed',
[
'handle' => 'better-core-video-embeds-styles',
]
);

}

add_action( 'wp_enqueue_scripts', 'hd_bcve_register_block_style' );
add_action( 'init', 'hd_bcve_register_block_style' );

/**
* Filters the code embed block output for improved performance on Youtube videos.
Expand Down
6 changes: 5 additions & 1 deletion readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Donate link: https://example.com/
Tags: embed, oembed, youtube, vimeo, performance, blocks
Requires at least: 6.0
Tested up to: 6.5.4
Stable tag: 1.3.6
Stable tag: 1.3.7
Requires PHP: 8.0
License: GPLv2 or later
License URI: https://www.gnu.org/licenses/gpl-2.0.html
Expand Down Expand Up @@ -49,6 +49,10 @@ Yes! As of version 1.3, you can set a custom thumbnail on the embed block and th

== Changelog ==

= 1.3.7 (30/10/2024) =
* Ensures that better core embeds work even when they are included in a synced pattern.
* Improves the enqueuing of the JS and CSS to be more robust.

= 1.3.6 (12/06/2024) =
* Improve the play button CSS to ensure it works with videos at aspect rations other than 16:9 and 4:3.

Expand Down

0 comments on commit 0e47a7e

Please sign in to comment.