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

Custom Blocks don't show up in Widgets #15644

Closed
JanP2ER opened this issue May 15, 2019 · 6 comments · Fixed by #25826
Closed

Custom Blocks don't show up in Widgets #15644

JanP2ER opened this issue May 15, 2019 · 6 comments · Fixed by #25826
Assignees
Labels
[Feature] Widgets Screen The block-based screen that replaced widgets.php. [Type] WP Core Ticket Requires an upstream change from WordPress. Core Trac ticket should be linked.

Comments

@JanP2ER
Copy link

JanP2ER commented May 15, 2019

Describe the bug

Custom-created Blocks can't be accessed in the widget-editor (e.g. in the Footer)

To reproduce
Steps to reproduce the behavior:

  1. Register custom block
  2. Click on 'Gutenberg' --> 'Widgets'
  3. Try to add a new block to any selection
  4. Custom blocks don't show up

Expected behavior
Custom created blocks should be displayed and accessible.

Screenshots
Block selection of regular posts:
Bildschirmfoto 2019-05-15 um 12 04 37

Block selection of widgets:
Bildschirmfoto 2019-05-15 um 12 05 17

Desktop

  • OS: macOS10.14.4
  • Browser: all browsers

Additional context

  • Gutenberg version: 5.7.0
  • Wordpress version: 5.2
@swissspidy swissspidy added the [Feature] Widgets Screen The block-based screen that replaced widgets.php. label May 23, 2019
@swissspidy
Copy link
Member

How did you register your block types? Have you verified your scripts are loaded on that screen?

@adambiggs
Copy link

I just ran into this issue. @swissspidy do you have any more info about how custom blocks should be registered so they show up in the widget editor?

I would have expected that if a block is registered successfully and shows up when editing a post, that it would automatically also show up in the widget editor, but that doesn't seem to be the case.

@noisysocks noisysocks added the Needs Testing Needs further testing to be confirmed. label Aug 14, 2020
@adamziel
Copy link
Contributor

The root cause are these two checks:

https://github.com/WordPress/wordpress-develop/blob/23528d419ab2968f250392e8552095783b138fec/src/wp-includes/script-loader.php#L2165
https://github.com/WordPress/wordpress-develop/blob/23528d419ab2968f250392e8552095783b138fec/src/wp-includes/script-loader.php#L2199

Neither widgets nor navigation editors are marked block editor pages which seems to be required for custom block types to be loaded. Unfortunately the resolution is not as simple as marking them as block editor pages since it results in the following:

Zrzut ekranu 2020-09-17 o 15 50 53

It seems like is_block_editor() is responsible for too many things at once. I suggest resolving this one by updating script-loader.php to rely on a filter as follows:

	$is_block_editor_screen = ( $current_screen instanceof WP_Screen ) && ! $current_screen->is_block_editor();
	$should_load_block_scripts_and_styles = apply_filters( 'should_load_block_scripts_and_styles', $is_block_editor_screen, $current_screen );
	if ( is_admin() && ! $should_load_block_scripts_and_styles ) {
		return;
	}

@adamziel
Copy link
Contributor

Since this requires updating the core, I created a core PR and a Trac ticket:

WordPress/wordpress-develop#537
https://core.trac.wordpress.org/ticket/51330

@annezazu annezazu added [Type] WP Core Ticket Requires an upstream change from WordPress. Core Trac ticket should be linked. and removed Needs Testing Needs further testing to be confirmed. labels Sep 24, 2020
@annezazu
Copy link
Contributor

Removing the needs testing label and changing this to a WP Core Bug since this requires a core update.

@adamziel
Copy link
Contributor

adamziel commented Oct 5, 2020

Now that the core patch is merged, I started working on the Gutenberg part here: #25826

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Widgets Screen The block-based screen that replaced widgets.php. [Type] WP Core Ticket Requires an upstream change from WordPress. Core Trac ticket should be linked.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants