Title: Namespaced classes
Last modified: August 21, 2016

---

# Namespaced classes

 *  [EloB](https://wordpress.org/support/users/elob/)
 * (@elob)
 * [12 years, 6 months ago](https://wordpress.org/support/topic/namespaced-classes/)
 * Hi mate!
 * There seems to be some problem with your new patch for namespaces… All my namespaced
   widgets are shown in the admin but when I try to save I get problem. Because 
   it then try to instance with double \\ slashes instead of single \ slash. Then
   my autoloader tries to load the class again and it will crash because of the 
   class is already defined.
 * My\Namespace\Widget
    My\\Namespace\\Widget
 * Here is my fix to get it to work. Just change the first row and replace slashes
   with one. 🙂
 *     ```
       function siteorigin_panels_the_widget( $widget, $instance, $grid, $cell, $panel, $is_first, $is_last ) {
       	$widget = str_replace('\\\\', '\\', $widget);
   
       	if ( !class_exists( $widget ) ) return;
   
       	$the_widget = new $widget;
   
       	$classes = array( 'panel', 'widget' );
       	if ( !empty( $the_widget->id_base ) ) $classes[] = 'widget_' . $the_widget->id_base;
       	if ( $is_first ) $classes[] = 'panel-first-child';
       	if ( $is_last ) $classes[] = 'panel-last-child';
   
       	$the_widget->widget( array(
       		'before_widget' => '<div class="' . esc_attr( implode( ' ', $classes ) ) . '" id="panel-' . $grid . '-' . $cell . '-' . $panel . '">',
       		'after_widget' => '</div>',
       		'before_title' => '<h3 class="widget-title">',
       		'after_title' => '</h3>',
       		'widget_id' => 'widget-' . $grid . '-' . $cell . '-' . $panel
       	), $instance );
       }
       ```
   
 * [http://wordpress.org/plugins/siteorigin-panels/](http://wordpress.org/plugins/siteorigin-panels/)

Viewing 1 replies (of 1 total)

 *  Plugin Author [Greg – SiteOrigin](https://wordpress.org/support/users/gpriday/)
 * (@gpriday)
 * [12 years, 6 months ago](https://wordpress.org/support/topic/namespaced-classes/#post-4292518)
 * Do you mind if I get you to double check the next release before I release it?
   I swear it’s working on the namespaced widgets I created to test the whole thing.

Viewing 1 replies (of 1 total)

The topic ‘Namespaced classes’ 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/)

 * 1 reply
 * 2 participants
 * Last reply from: [Greg – SiteOrigin](https://wordpress.org/support/users/gpriday/)
 * Last activity: [12 years, 6 months ago](https://wordpress.org/support/topic/namespaced-classes/#post-4292518)
 * Status: not resolved