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

Consider deprecating "function widgets" #33104

Closed
adamziel opened this issue Jun 30, 2021 · 4 comments
Closed

Consider deprecating "function widgets" #33104

adamziel opened this issue Jun 30, 2021 · 4 comments
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

Comments

@adamziel
Copy link
Contributor

adamziel commented Jun 30, 2021

Description

This issue is all about function widgets like the Marquee Widget. They are a special case of widgets and the new editor has a few problems with handling them:

  1. Changing a form field of a function widget doesn't "activate" the "Update" button
  2. Saving the widgets screen using the "Update" button does not preserve changes from the function widget form

2021-06-30 16-36-45 2021-06-30 16_51_59

  1. The function widgets tend to get added to the "Inactive widgets" section seemingly randomly, if the user doesn't notice they won't be able to add another one to their desired sidebar.
  2. ...I am willing to bet there's more. We already adressed a bunch, e.g. Widget Editor: Function-based widgets don't render and don't save #32960, Fix flaky widgets-related E2E tests #33066, Widgets: Fix creating and editing non-multi widgets #32978

There are two ways of approaching these bugs:

  1. Whack-a-mole every problem as we uncover them
  2. Deprecate the concept of a "function widget", eliminate all the code branches that are specific to function widgets, and wrap them in a class using code similar to this (props to @noisysocks):
function wp_register_sidebar_widget( $fn ) {
	register_widget( new class extends WP_Widget {
		public function widget() {
			call_user_func( $fn );
		}
	} );
}

The latter approach has some limitations. For example, there’s an implicit assumption that there’s just one instance of any function widget, which means that adding more than one of them and clicking the "Update" button would effectively update the same database entry multiple times. On the other hand, we could add $is_multi = false to such WP_Widget to simulate that behaviour in a less weird way. On yet another hand, we could just wear the weirdness and say “it’s deprecated, tread carefully!” in some place in the UI.

That being said, I am a big proponent of deprecating function widgets and would like to discuss it here.

cc @noisysocks @draganescu @talldan @kevin940726 @gziolo @spacedmonkey @ellatrix @hellofromtonya @getdave

@adamziel adamziel added [Block] Legacy Widget Affects the Legacy Widget Block - used for displaying Classic Widgets [Feature] Widgets Screen The block-based screen that replaced widgets.php. [Feature] Widgets Customizer Ability to add and edit blocks in Customize → Widgets. [Package] Edit Widgets /packages/edit-widgets labels Jun 30, 2021
@noisysocks
Copy link
Member

Thanks for creating an issue to discuss and track. I'd very much like to deprecate this kind of widget after WordPress 5.8. I think also it might make sense to do this as part of refactoring widgets to use CPTs as the storage mechanism (see Core-35669).

@noisysocks
Copy link
Member

noisysocks commented Jul 1, 2021

Just quickly noting:

Changing a form field of a function widget doesn't "activate" the "Update" button

This is expected. Function widgets bypass the normal Update flow because their data can be stored somewhere that we don't know about. That's why they have their own Save button.

The function widgets tend to get added to the "Inactive widgets" section seemingly randomly, if the user doesn't notice they won't be able to add another one to their desired sidebar.

Also expected. You can't delete a function widget and so if you try it will re-appear in Inactive widgets. I agree it's not obvious that this is happening.

Also worth noting is that these types of widgets are incredibly uncommon 🙂

@adamziel
Copy link
Contributor Author

adamziel commented Jul 1, 2021

This is expected. Function widgets bypass the normal Update flow because their data can be stored somewhere that we don't know about. That's why they have their own Save button.

If I wear my developer hat, I can understand that. If I wear my user hat, I am confused why sometimes there's another save button and why updating things doesn't always update things.

Also worth noting is that these types of widgets are incredibly uncommon 🙂

That's a good news! It should make it easier to deprecate that then.

@noisysocks noisysocks changed the title Deprecate function widgets Consider deprecating "function widgets" Jul 7, 2021
@adamziel
Copy link
Contributor Author

Let's continue in https://core.trac.wordpress.org/ticket/53993

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
Projects
None yet
Development

No branches or pull requests

2 participants