get_widgets_list(); array_unshift( $widgets, array( 'value' => '', 'label' => '' ) ); wp_localize_script( 'widget-shortcode-gutenberg', 'widgetShortcodeGutenberg', array( 'widgets' => $widgets, ) ); register_block_type( 'widget-shortcode/block', array( 'editor_script' => 'widget-shortcode-gutenberg', 'render_callback' => array( $this, 'render_callback' ), 'attributes' => array( 'id' => array( 'default' => '', 'type' => 'string', ), 'className' => array( 'default' => '', 'type' => 'string', ), ), ) ); } /** * Render the widget preview in Gutenberg window * * @return string */ function render_callback( $atts, $content ) { if ( ! isset( $atts['id'] ) || empty( $atts['id'] ) ) { return '
' . __( 'Select the widget you want to show.', 'widget-shortcode' ) . '
'; } return Widget_Shortcode::get_instance()->do_widget( array( 'echo' => false, 'id' => $atts['id'], 'css_class' => $atts['className'], ) ); } }