Opened 3 years ago
Closed 3 years ago
#53993 closed enhancement (duplicate)
Consider deprecating "function widgets"
Reported by: | zieladam | Owned by: | |
---|---|---|---|
Milestone: | Priority: | normal | |
Severity: | normal | Version: | |
Component: | Widgets | Keywords: | dev-feedback |
Focuses: | Cc: |
Description (last modified by )
WordPress supports two kinds of widgets: based on classes and functions.
Widgets based on classes extend the WP_Widget
class. They are registered like this:
<?php class WP_Widget_Text { /* ... */ } register_widget ( 'WP_Widget_Text' );
They have a nice API and may be used multiple times with different parameters.
Widgets based on functions are registered like this:
<?php wp_register_sidebar_widget( 'marquee_greeting', 'Marquee Greeting', function() { $greeting = get_option( 'marquee_greeting', 'Hello!' ); printf( '<marquee>%s</marquee>', esc_html( $greeting ) ); } ); wp_register_widget_control( /* ... */ );
They don't support multiple instances and can be only used once. In addition, they don't benefit from the WP_Widget API.
Widgets based on functions seem to be extremely uncommon and more of a BC artifact rather than a popular, actively used feature. They also required adding a lot of custom code into the new block-based widgets editor and will continue to be a maintenance burden in the future.
In the Gutenberg repo there was a discussion about deprecating them to make life easier. Now I'm opening this Trac issue so that we can either take action or decide against it.
Technically speaking, I am not sure where to place the _deprecated_function()
call. At first I thought about wp_register_sidebar_widget
and company, but that API is internally used by WP_Widget
itself:
<?php public function _register_one( $number = -1 ) { wp_register_sidebar_widget( $this->id, $this->name, $this->_get_display_callback(), $this->widget_options, array( 'number' => $number ) );
The second best idea I have is checking if number
is passed via that last argument and issue a notice if it's missing. I wonder if there's a better way though.
cc @adraganescu @hellofromtonya @azaozz @noisysocks
Possible duplicate of #35656?