Opened 11 years ago
Closed 8 years ago
#27770 closed defect (bug) (fixed)
Can't save a widget that uses a namespace
Reported by: |
|
Owned by: |
|
---|---|---|---|
Milestone: | 4.9 | Priority: | normal |
Severity: | normal | Version: | 3.8.2 |
Component: | Widgets | Keywords: | good-first-bug needs-testing has-patch |
Focuses: | Cc: |
Description
I am using the following plugin to provide autoload abilities: http://wordpress.org/plugins/wp-autoloader/
I have created a widget that uses the namespace '\WordPress\Widgets'. I was able to use register_widget with it.
However upon adding and saving the widget, I refresh and it is not stored. Removing the namespacing and doing a manual require allows it to function as intended.
Attachments (2)
Change History (13)
#4
@
9 years ago
Just tested in nightly build and it seems to work fine with and without the leading slash.
#6
@
8 years ago
Tested in trunk and cannot replicate. Widget saved fine, regardless of NameSpacing.
#7
@
8 years ago
- Milestone Awaiting Review deleted
- Resolution set to invalid
- Status changed from new to closed
#8
@
8 years ago
- Resolution invalid deleted
- Status changed from closed to reopened
I also ran into this problem today and can give more info on what's causing it.
This is my code:
<?php register_widget(new OurNamespace\SocialWidget);
When adding this widget to a sidebar, a POST call is made to admin_ajax.php
, with payload (Example)
{
"widget_id": "widget-ournamespace\socialwidget-2",
"id_base": "ournamespace\socialwidget"
}
The slash is causing the problem. When you call parent::__construct
with an id_base
without a slash (I used ournamespace_socialwidget
), the problem is gone.
Hope that helps you! If more info is useful, feel free to ask :)
#9
@
8 years ago
- Keywords has-patch added; 2nd-opinion removed
I've attached a basic namespaced widget in example-widget.php, for testing purposes, and come up with 27770.diff, which fixes the issue for me.
Possibly related:
http://stackoverflow.com/questions/5247302/php-namespace-5-3-and-wordpress-widget#comment12854641_5247436