WordPress.org

Make WordPress Core

Opened 5 years ago

Last modified 8 months ago

#12342 new defect (bug)

New widget option after calling register_widget creating empty widget

Reported by: jimisaacs Owned by: azaozz
Milestone: Future Release Priority: normal
Severity: normal Version: 2.9.2
Component: Widgets Keywords: widgets dev-feedback
Focuses: Cc:

Description

After I register a new widget class that has never been registered before, navigate to the widgets.php admin page and allow the option to be created automatically. The option value looks like this as serialized data:

a:2:{i:2;a:0:{}s:12:"_multiwidget";i:1;}

As you can see there is an empty widget in there for some reason. Basically the unserialized option value looks like the following as an array:

array( '2' => array(), _multiwidget => 1 );

This is odd behavior since the first multi number has always started at 2, but with that previous array in there it starts at 3, and randomly which is what irks me. i can't seem to find when it happens or a pattern, so naturally this feels like a bug.

As this does not seem to break anything with the core functionality of WordPress, I would say this is normal priority. What this does do is pose many questions for those of us that dive deep into the Widget API, where our plugins and the functionality of them are dependent on how these things work. My widget plugin is quite large, and I need to know if I can depend on the first multi number of a widget when the class is first registered.

If this is not a bug, and normal functionality, I apologize, and would like to ask for a heads up on the subject.

Thank You,
Jim Isaacs

Change History (5)

comment:1 @scribu5 years ago

  • Keywords dev-feedback added; options defaults removed
  • Milestone changed from 2.9.3 to 3.0

comment:2 @jimisaacs5 years ago

@azaozz

It looks as though you are the widget master. therefore I wanted to ask you about the plugin of which I spoke about in this report. I am not asking for any beta testing or craziness.

I am not looking for feedback on my plugin, I wanted to show it, my ideas, which essentially is my thought process to maybe give you and anybody else ideas regarding the WordPress Widget API in general.

The plugin is still in beta as I am the only one testing, trying to do a lot with it, clean things up, etc... before a final release. It shouldn't break anything in a blog running on PHP 5.

Give it a gander if you can:
http://wordpress.org/extend/plugins/extensible-widgets/
http://jidd.jimisaacs.com/archives/863

There is a little more documentation within the plugin itself.

comment:3 @azaozz5 years ago

  • Milestone changed from 3.0 to 3.1

This seems to be caused by the (tons of) back-compat code in the API. It would be best fixed when we remove most of that code hopefully in 3.1.

However you shouldn't be working directly with the widget option in your plugin. Best is to use the API, it has a lot of hooks everywhere to make that easy. When a user creates and deletes instances of the same widget several times, that number will always increment so the widget option would look something like 5 => array(options...), 9 => array(options...), 15 => array(options...) etc. and some of these instances could be in the inactive widgets area too.

If you really need to access the widget option directly you'll need to check the sidebars_widgets too to determine which are active.

comment:4 @nacin5 years ago

  • Milestone changed from Awaiting Triage to Future Release

comment:5 @chriscct78 months ago

@azaozz or others. Does anyone know if this was fixed?

Note: See TracTickets for help on using tickets.