Title: Bug with namespaced widgets
Last modified: August 21, 2016

---

# Bug with namespaced widgets

 *  Resolved [EloB](https://wordpress.org/support/users/elob/)
 * (@elob)
 * [12 years, 7 months ago](https://wordpress.org/support/topic/bug-with-namespaced-widgets/)
 * When you have namespaced widgets like:
 *     ```
       <?php
       namespace Widgets;
       class Example extends \WP_Widget { ... }
   
       function() {
       register_widget('Widgets\Example');
       }
       add_action( 'widgets_init', 'add_example_widget' );
       ```
   
 * Then its impossible to add them in the admin. I think this is because of a bug
   in jQuery or Sizzle actually.
 * I filled a jQuery bug report for backslashes in jQuery attribute value selector.
   
   [http://bugs.jquery.com/ticket/14417](http://bugs.jquery.com/ticket/14417)
 * A workaround would be to change the backslashes against normal slashes. In tpl/
   metabox-panels.php:65
 * data-class=”<?php echo esc_attr(str_replace(‘\\’, ‘/’, get_class($widget))) ?
   >”
 * [http://wordpress.org/plugins/siteorigin-panels/](http://wordpress.org/plugins/siteorigin-panels/)

Viewing 6 replies - 1 through 6 (of 6 total)

 *  Thread Starter [EloB](https://wordpress.org/support/users/elob/)
 * (@elob)
 * [12 years, 7 months ago](https://wordpress.org/support/topic/bug-with-namespaced-widgets/#post-4185893)
 * Here is a better solution:
 * In siteorigin-panels.php:399
 *     ```
       foreach ( $panels_data['widgets'] as $i => $widget ) {
       	$info = $widget['info'];
       	if ( !class_exists( $widget['info']['class'] ) ) continue;
   
       	$the_widget = new $widget['info']['class'];
       	if ( method_exists( $the_widget, 'update' ) ) {
       		unset( $widget['info'] );
       		$widget = $the_widget->update( $widget, $widget );
       	}
       	$widget['info'] = $info;
       	$panels_data['widgets'][$i] = $widget;
       }
       ```
   
 * Change to:
 *     ```
       foreach ( $panels_data['widgets'] as $i => $widget ) {
       	$info = $widget['info'];
       	if ( !class_exists( $widget['info']['class'] ) ) continue;
   
       	$the_widget = new $widget['info']['class'];
       	if ( method_exists( $the_widget, 'update' ) ) {
       		unset( $widget['info'] );
       		$widget = $the_widget->update( $widget, $widget );
       	}
       	$info['class'] = addslashes($info['class']);
       	$widget['info'] = $info;
       	$panels_data['widgets'][$i] = $widget;
       }
       ```
   
 * And in js/panels.admin.panels:42
 *     ```
       var $$ = dialogWrapper.find('.panel-type[data-class="' + type + '"]' );
       ```
   
 * Change to:
 *     ```
       var $$ = dialogWrapper.find('.panel-type' ).filter(function() { return $(this).data('class') === type });
       ```
   
 *  Thread Starter [EloB](https://wordpress.org/support/users/elob/)
 * (@elob)
 * [12 years, 7 months ago](https://wordpress.org/support/topic/bug-with-namespaced-widgets/#post-4186034)
 * This wasn’t a jQuery bug. They closed the bug report. So we need either my posted
   solution or fix the bug. 🙂
 *  Plugin Author [Greg – SiteOrigin](https://wordpress.org/support/users/gpriday/)
 * (@gpriday)
 * [12 years, 7 months ago](https://wordpress.org/support/topic/bug-with-namespaced-widgets/#post-4186035)
 * I’ll get on this for the next update. I hadn’t actually tested for namespaced
   widgets yet. Thanks for the code contributions!
 *  Thread Starter [EloB](https://wordpress.org/support/users/elob/)
 * (@elob)
 * [12 years, 7 months ago](https://wordpress.org/support/topic/bug-with-namespaced-widgets/#post-4186047)
 * Awesome! 🙂
 * _[Moderator Note: [No bumping](http://codex.wordpress.org/Forum_Welcome#No_Bumping),
   thank you.]_
 *  Plugin Author [Greg – SiteOrigin](https://wordpress.org/support/users/gpriday/)
 * (@gpriday)
 * [12 years, 6 months ago](https://wordpress.org/support/topic/bug-with-namespaced-widgets/#post-4186115)
 * Just letting you know I’ve applied the changes. It seems like everything is working
   with namespaced widgets now. I’ll be pushing the 1.3.8 update either later today
   or tomorrow.
 *  Thread Starter [EloB](https://wordpress.org/support/users/elob/)
 * (@elob)
 * [12 years, 6 months ago](https://wordpress.org/support/topic/bug-with-namespaced-widgets/#post-4186116)
 * Hi Mate!
 * Great but I doesn’t work… It only works the first time you save but when you 
   click update the widget will get removed… You must addslashes to the class…
 *     ```
       $info['class'] = get_class($the_widget);
       ```
   
 * To
 *     ```
       $info['class'] = addslashes(get_class($the_widget));
       ```
   

Viewing 6 replies - 1 through 6 (of 6 total)

The topic ‘Bug with namespaced widgets’ is closed to new replies.

 * ![](https://ps.w.org/siteorigin-panels/assets/icon.svg?rev=2556869)
 * [Page Builder by SiteOrigin](https://wordpress.org/plugins/siteorigin-panels/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/siteorigin-panels/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/siteorigin-panels/)
 * [Active Topics](https://wordpress.org/support/plugin/siteorigin-panels/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/siteorigin-panels/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/siteorigin-panels/reviews/)

 * 6 replies
 * 2 participants
 * Last reply from: [EloB](https://wordpress.org/support/users/elob/)
 * Last activity: [12 years, 6 months ago](https://wordpress.org/support/topic/bug-with-namespaced-widgets/#post-4186116)
 * Status: resolved