Open pdewouters opened 4 years ago
Thank you for reporting the issue @pdewouters someone will look into it.
I was receiving this same warning. I added this to my theme code to alleviate it.
/**
* Remove Unsplash Block Editor Script
*
* "unsplash-featured-image-selector", which is enqueued in the front-end,
* depends on the file "unsplash-media-selector", which is not.
*
* We can check if "unsplash-media-selector" is registered before letting the dependent script through.
*/
function themename_remove_unsplash_block_editor_script() : void {
if ( wp_script_is( 'unsplash-media-selector', 'registered' ) ) {
return;
}
wp_dequeue_script( 'unsplash-featured-image-selector' );
}
add_action( 'enqueue_block_assets', 'themename_remove_unsplash_block_editor_script', 200 );
It seems like the problem is here: https://github.com/xwp/unsplash-wp/blob/develop/php/class-plugin.php#L210
The action enqueue_block_assets
is called in both front-end and admin contexts. So unless unsplash-featured-image-selector
is actually needed in the front-end, adding a check against $current_screen->is_block_editor()
should fix it.
https://core.trac.wordpress.org/browser/tags/5.5.1/src/wp-includes/script-loader.php#L2162
I test this locally by editing the plugin in place and it worked.
/**
* Enqueue block editor assets.
*
* @global WP_Screen $current_screen
*/
public function enqueue_block_assets() {
global $current_screen;
if ( ! is_admin() ) {
return;
}
if ( ! $current_screen instanceof WP_Screen ) {
return;
}
if ( ! $current_screen->is_block_editor() ) {
return;
}
Bug Description
On the front end, the
unsplash-media-selector
is added as a dependency tounsplash-featured-image-selector
but it's not been registered or enqueued in that scope.https://github.com/xwp/unsplash-wp/blob/develop/php/class-plugin.php#L222
Expected Behaviour
Steps to reproduce
Screenshots
Additional context
Do not alter or remove anything below. The following sections will be managed by moderators only.
Acceptance criteria
Implementation brief
QA testing instructions
Demo
Changelog entry