title: Wordpress shortcode displays widget but not content
body: <p>I am trying to create a shortcode that will display a current widget and it's contents. It seems to function perfectly fine for wordpress default widgets, however when it comes to my custom widgets it does not work. Any ideas on how to fix it?</p>
  
  <p>Shortcode (I believe the issue stands with $widget_id not working on custom widgets):</p>
  
  <pre><code>function widget_shortcodes($atts) {
  global $wp_widget_factory;//Connects to all registered widgets
  
  $parts = shortcode_atts(array( //sets the attributes for the shortcode
      'id' =&gt; '1', //sets the id field of the shortcode
      'type' =&gt; 'text' //sets the type field of the shortcode
  ), $atts );
  
  $widget_id = $atts['id']; //sets the widget id variable to the input id in the shortcode
  
  
  //this if/elseif statement block checks to see the value of the type field and sets the widget type variable depending on the value
  if($atts['type'] == 'calendar'){
      $widget_type = 'WP_Widget_Calendar';
  } elseif ($atts['type'] == 'posts') {
      $widget_type = 'My_Recent_Posts_Widget';
  } elseif ($atts['type'] == 'text') {
      $widget_type = 'WP_Widget_Text';
  } elseif ($atts['type'] == 'form') {
      $widget_type = 'quickform_widget';
  } elseif ($atts['type'] == 'newsletter') {
      $widget_type = 'newsletter_widget';
  } elseif ($atts['type'] == 'reviews') {
      $widget_type = 'reviews_widget';
  }
  
  ob_start(); //initiates the object
  if(!empty($widget_type)) {
      the_widget($widget_type, $instance, array('widget_id'=&gt; $widget_id)); //gets the widget if the type is correct
      $widget_output = ob_get_contents(); //sets the widget output to the object content
  } else { //if the type is not supported it displays an error message
      echo "&lt;p&gt;Please make sure you have set a valid type in your shortcode.&lt;/p&gt;";
      echo "&lt;p&gt;Accepted Types: calendar, posts, text, form, newsletter and reviews.&lt;p&gt;";
      $widget_output = ob_get_contents(); //sets the widget output to the object content
  }
  ob_end_clean(); //ends the object
  return $widget_output; //returns the widget code
  } add_shortcode('widget','widget_shortcodes');
  </code></pre>
  
  <p>Custom Widget:</p>
  
  <pre><code>&lt;?php // Creating the widget 
  class newsletter_widget extends WP_Widget {
  
  function __construct() {
      parent::__construct(
          // Base ID of your widget
          'newsletter_widget', 
  
          // Widget name will appear in UI
          __('Newsletter', 'wpb_widget_domain'), 
  
          // Widget description
          array( 'description' =&gt; __( 'Newsletter widget', 'wpb_widget_domain' ), ) 
      );
  }
  
  // Creating widget front-end
  // This is where the action happens
  public function widget( $args, $instance ) { 
      $title = apply_filters( 'widget_title', $instance['title'] );
      $code = apply_filters( 'widget_code', $instance['code'] );
      $desc = apply_filters( 'widget_desc', $instance['desc'] );
      ?&gt;
  
      &lt;aside class="widget widget_newsletter"&gt;
          &lt;h3&gt;&lt;?php echo $title; ?&gt;&lt;/h3&gt;
          &lt;p&gt;&lt;?php echo ( $desc ); ?&gt;&lt;/p&gt;
          &lt;?php echo do_shortcode($code);?&gt;
      &lt;/aside&gt;
  &lt;?php }
  
  // Widget Backend 
  public function form( $instance ) {
      if ( isset( $instance[ 'title' ] ) ) {
          $title = $instance[ 'title' ];
      }
      else {
          $title = __( 'Receive our monthly newsletter', 'wpb_widget_domain' );
      }
  
      if ( isset( $instance[ 'code' ] ) ) {
          $code = $instance[ 'code' ];
      }
      else {
          $code = __( 'Form Code...', 'wpb_widget_domain' );
      }
  
      if ( isset( $instance[ 'desc' ] ) ) {
          $desc = $instance[ 'desc' ];
      }
      else {
          $desc = __( 'Newsletter description...', 'wpb_widget_domain' );
      }
      // Widget admin form?&gt;
      &lt;p&gt;
          &lt;label for="&lt;?php echo $this-&gt;get_field_id( 'title' ); ?&gt;"&gt;&lt;?php _e( 'Title:' ); ?&gt;&lt;/label&gt; 
          &lt;input class="widefat" id="&lt;?php echo $this-&gt;get_field_id( 'title' ); ?&gt;" name="&lt;?php echo $this-&gt;get_field_name( 'title' ); ?&gt;" type="text" value="&lt;?php echo esc_attr( $title ); ?&gt;" /&gt;
      &lt;/p&gt;
      &lt;p&gt;
          &lt;label for="&lt;?php echo $this-&gt;get_field_id( 'desc' ); ?&gt;"&gt;&lt;?php _e('Newsletter Description:'); ?&gt;&lt;/label&gt;
          &lt;textarea class="widefat" id="&lt;?php echo $this-&gt;get_field_id( 'desc' ); ?&gt;" name="&lt;?php echo $this-&gt;get_field_name( 'desc' ); ?&gt;" type="text" value="&lt;?php echo esc_attr( $desc ); ?&gt;"&gt;&lt;?php echo $desc;?&gt;&lt;/textarea&gt;
      &lt;/p&gt;
      &lt;p&gt;
          &lt;label for="&lt;?php echo $this-&gt;get_field_id( 'code' ); ?&gt;"&gt;&lt;?php _e( 'Form code:' ); ?&gt;&lt;/label&gt; 
          &lt;input class="widefat" id="&lt;?php echo $this-&gt;get_field_id( 'code' ); ?&gt;" name="&lt;?php echo $this-&gt;get_field_name( 'code' ); ?&gt;" type="text" value="&lt;?php echo esc_attr( $code ); ?&gt;" /&gt;
      &lt;/p&gt;
  &lt;?php }
  
  // Updating widget replacing old instances with new
  public function update( $new_instance, $old_instance ) {
      $instance = array();
      $instance['title'] = ( ! empty( $new_instance['title'] ) ) ? strip_tags( $new_instance['title'] ) : '';
      $instance['code'] = ( ! empty( $new_instance['code'] ) ) ? strip_tags( $new_instance['code'] ) : '';
      $instance['desc'] = ( ! empty( $new_instance['desc'] ) ) ? strip_tags( $new_instance['desc'] ) : '';
      return $instance;
  }
  }
  
  // Register and load the widget
  function newsletter_load_widget() {
  register_widget( 'newsletter_widget' );
  }
  add_action( 'widgets_init', 'newsletter_load_widget' );?&gt;
  </code></pre>