Make WordPress Core

Opened 3 years ago

Closed 3 years ago

#53993 closed enhancement (duplicate)

Consider deprecating "function widgets"

Reported by: zieladam's profile zieladam Owned by:
Milestone: Priority: normal
Severity: normal Version:
Component: Widgets Keywords: dev-feedback
Focuses: Cc:

Description (last modified by sabernhardt)

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:

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:

        '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:


        public function _register_one( $number = -1 ) {
                        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

Change History (5)

#1 @zieladam
3 years ago

  • Description modified (diff)

#2 @SergeyBiryukov
3 years ago

  • Component changed from General to Widgets

#3 follow-up: @swissspidy
3 years ago

Possible duplicate of #35656?

#4 @sabernhardt
3 years ago

  • Description modified (diff)

#5 in reply to: ↑ 3 @noisysocks
3 years ago

  • Milestone Awaiting Review deleted
  • Resolution set to duplicate
  • Status changed from new to closed

Replying to swissspidy:

Possible duplicate of #35656?

Indeed! I'll close this one out.

Note: See TracTickets for help on using tickets.