Support » Plugin: WordPress Page Builder - Beaver Builder » Widget Module does not work with pre-instantiated widgets

  • Robin Cornett

    (@littlerchicken)


    If a widget is registered using the pre-instantiated registration introduced in WP 4.6, the widget module in BB doesn’t work with that widget. When you try to add the widget to the page/post, Beaver Builder displays “[really long string] no longer exists.”

    This can be duplicated with the Core Recent posts widget, modified per this example. Note that there are errors in the .diff code (the sprintf lines are set up incorrectly and the $post_type_obj uses the wrong function), which can be corrected with this updated method:

    
    	public function __construct( $post_type = 'post' ) {
    		$this->post_type = $post_type;
    		$post_type_obj   = get_post_type_object( $post_type );
    		$widget_ops      = array(
    			'classname'   => 'widget_recent_entries',
    			'description' => sprintf( __( 'Your site’s most recent %s.' ), $post_type_obj->labels->name ),
    		);
    		$id_base         = sprintf( 'recent-%s', $post_type === 'post' ? 'posts' : "$post_type-posts" );
    		parent::__construct(
    			$id_base,
    			sprintf( __( 'Recent %s' ), $post_type_obj->labels->name ),
    			$widget_ops
            );
    		$this->alt_option_name = 'widget_recent_entries';
    	}
    

    I tried to look through the Beaver Builder code to see if I could offer a revision, but decided I would be completely and totally guessing. If I can help narrow it down, though, please let me know. Thank you!

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Contributor Ben Carlo

    (@hinampaksh)

    Hey Robin,

    Apologies for the delayed response. I’ve already filed a bug report for this so our devs can check. Thanks for the heads up! 🙂

    Ben

    Plugin Author Justin Busa

    (@justinbusa)

    Hi Robin,

    Do you have a widget using this method other than the diff above that we can test?

    Thanks,
    Justin

    magnetize83

    (@magnetize83)

    I am experiencing the same problem,

    include_once( 'widget-class.php' );
    register_widget( 'widget_id' );

    is ok.
    However

    include_once( 'widget-class.php' );
    $widget = new Widget_Class();
    register_widget( $widget );

    is not.

    • This reply was modified 11 months ago by  magnetize83.
    Plugin Author Justin Busa

    (@justinbusa)

    Hey @littlerchicken and @magnetize83,

    I implemented a fix for this but it looks like the core the_widget function that we use to display widgets hasn’t been updated to support pre-instantiated widgets either.

    So until that’s done, we won’t be able to fully support them. I’ll go ahead and open a trac ticket with a patch to see if we can get that fixed.

    Stay tuned.

    Justin

    magnetize83

    (@magnetize83)

    @justinbusa Hey, ah I see.
    Thanks for the update!

    Regards,

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Widget Module does not work with pre-instantiated widgets’ is closed to new replies.