I’ve only just started using the widget creation mechanism, and I’m taken with it, but I’ve struck a snag.
I’m trying to use the [Widget Shortcode plugin](https://wordpress.org/plugins/widget-shortcode/) to display a Piklist-created widget outside the sidebar context that it was originally specified.
The code fails as the render call to the_widget() passes a $class value of Piklist_Universal_Widget (derived through php’s get_class()) and that’s not the key that the widget is registered under. Digging through the code, and the piklist source, the cause is apparent:
$wp_widget_factory->widgets[$widget_class_name] = new $widget_class($widget_class_name, $title, $description, array($from => $path));
Is there a really good reason why it’s done by direct injection, instead of passing the class to register_widget() ? It seems to have unforseen side-effects in edge-cases like this.
In this case, the code can salvaged by passing the widget_name property of the widget instance to the call to the_widget(), instead of the class name.