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

Fix: Block registrations in Themes in WordPress 6.0 by removing the filter of plugins_url #103

Merged
merged 2 commits into from
May 24, 2022
Merged
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
16 changes: 12 additions & 4 deletions themes/10up-theme/includes/blocks.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,14 @@ function setup() {
* @return void
*/
function register_theme_blocks() {
// Filter the plugins URL to allow us to have blocks in themes with linked assets. i.e editorScripts
add_filter( 'plugins_url', __NAMESPACE__ . '\filter_plugins_url', 10, 2 );
global $wp_version;

$is_pre_wp_6 = version_compare( $wp_version, '6.0', '<' );

if ( $is_pre_wp_6 ) {
// Filter the plugins URL to allow us to have blocks in themes with linked assets. i.e editorScripts
add_filter( 'plugins_url', __NAMESPACE__ . '\filter_plugins_url', 10, 2 );
}

// Register all the blocks in the theme
if ( file_exists( TENUP_THEME_BLOCK_DIR ) ) {
Expand Down Expand Up @@ -81,8 +87,10 @@ function register_theme_blocks() {
};
};

// Remove the filter after we register the blocks
remove_filter( 'plugins_url', __NAMESPACE__ . '\filter_plugins_url', 10, 2 );
if ( $is_pre_wp_6 ) {
// Remove the filter after we register the blocks
remove_filter( 'plugins_url', __NAMESPACE__ . '\filter_plugins_url', 10, 2 );
}
}

/**
Expand Down