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

Widget Editor: Function-based widgets don't render and don't save #32960

Closed
adamziel opened this issue Jun 24, 2021 · 4 comments · Fixed by #32978
Closed

Widget Editor: Function-based widgets don't render and don't save #32960

adamziel opened this issue Jun 24, 2021 · 4 comments · Fixed by #32978
Assignees
Labels
[Block] Legacy Widget Affects the Legacy Widget Block - used for displaying Classic Widgets [Feature] Widgets Customizer Ability to add and edit blocks in Customize → Widgets. [Feature] Widgets Screen The block-based screen that replaced widgets.php. [Package] Edit Widgets /packages/edit-widgets [Status] In Progress Tracking issues with work in progress

Comments

@adamziel
Copy link
Contributor

adamziel commented Jun 24, 2021

Description

The widgets editor doesn't play nicely with a function-based marquee widget. Presumably, this is a problem also for other function-based ("reference") widgets.

Step-by-step reproduction instructions

  1. Add the marquee widget to your WP installation
  2. Go to the widgets editor and add marquee
  3. Try to save the form

Expected behaviour

  1. Everything gets saved buttery smooth.
  2. The Marquee widget shows up in the "inactive" panel as it used to in the old editor:

Zrzut ekranu 2021-06-24 o 16 54 17

Actual behaviour

  1. The form doesn't render. Then it doesn't get saved. The marquee isn't previewed. Saving the entire widgets screen produces a notice with an error.
  2. The widget can't be seen in the "inactive" panel

Screenshots or screen recording (optional)

Nagranie.z.ekranu.2021-06-24.o.16.05.45.mov
@adamziel adamziel added [Feature] Widgets Screen The block-based screen that replaced widgets.php. [Block] Legacy Widget Affects the Legacy Widget Block - used for displaying Classic Widgets [Package] Edit Widgets /packages/edit-widgets [Feature] Widgets Customizer Ability to add and edit blocks in Customize → Widgets. labels Jun 24, 2021
@adamziel
Copy link
Contributor Author

adamziel commented Jun 24, 2021

Once I opted out of the block-based widgets editor with add_filter( 'use_widgets_block_editor', '__return_false' );, I saw the marquee widget in the "Inactive" section of the old widgets editor. From that moment on, it also started showing up in the new editor (wp_get_sidebars_widgets() started returning marquee_greeting when it wouldn't previously). There must be a write operation somewhere in the legacy editor that adds such "missing" widgets to the inactive section.

@getdave
Copy link
Contributor

getdave commented Jun 24, 2021

function-based marquee widget

What is a "function based widget"? Looking at https://gist.github.com/adamziel/526436b4cc9bc82a7221c77e00137ae1 I assume it's literally a Widget that is created using a function rather than a class?

@adamziel
Copy link
Contributor Author

@getdave you got it right! There's a bunch of logic specific to this kind of widgets in WordPress core.

After resetting my wp-env, the marquee greetings showed up in the "Available widgets" section of the legacy editor, not in the "inactive widgets" section 🤔

Zrzut ekranu 2021-06-24 o 17 46 20

It was picked up from the $wp_registered_widgets global.

@adamziel
Copy link
Contributor Author

adamziel commented Jun 24, 2021

One problem is how the marquee widget triggers a request to /wp/v2/widgets/marquee_greeting where we assume that is_null( $sidebar_id ) means there is no widget with a given ID and return 404:

if ( is_null( $sidebar_id ) ) {
return new WP_Error(
'rest_widget_not_found',
__( 'No widget was found with that id.', 'gutenberg' ),
array( 'status' => 404 )
);
}

This assumption holds for widgets implemented using classes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Block] Legacy Widget Affects the Legacy Widget Block - used for displaying Classic Widgets [Feature] Widgets Customizer Ability to add and edit blocks in Customize → Widgets. [Feature] Widgets Screen The block-based screen that replaced widgets.php. [Package] Edit Widgets /packages/edit-widgets [Status] In Progress Tracking issues with work in progress
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants