[wp-trac] [WordPress Trac] #53993: Consider deprecating "function widgets"
WordPress Trac
noreply at wordpress.org
Tue Aug 24 13:45:17 UTC 2021
#53993: Consider deprecating "function widgets"
-------------------------+-----------------------------
Reporter: zieladam | Owner: (none)
Type: enhancement | Status: new
Priority: normal | Milestone: Awaiting Review
Component: General | Version:
Severity: normal | Keywords: dev-feedback
Focuses: |
-------------------------+-----------------------------
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
<?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
<?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
[https://github.com/WordPress/gutenberg/issues/33104: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
[https://github.com/WordPress/gutenberg/issues/33104: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
<?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
--
Ticket URL: <https://core.trac.wordpress.org/ticket/53993>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list