'', 'type' => 'logos', 'height' => '' ), $atts, 'dreamwidget' ); $id = preg_replace( '/[^A-Za-z0-9_-]/', '', (string) $a['id'] ); if ( strlen( $id ) < 6 ) { return current_user_can( 'edit_posts' ) ? '

DreamWidget: add the widget id from your dashboard.

' : ''; } $type = ( $a['type'] === 'video' || $a['type'] === 'youtube' ) ? 'youtube' : ( in_array( $a['type'], array( 'popup', 'showreel' ), true ) ? 'simple' : 'logos' ); $height = (int) $a['height']; if ( $height <= 0 ) { $height = $a['type'] === 'showreel' ? 520 : ( $type === 'youtube' ? 400 : 110 ); } $src = DREAMWIDGET_CDN . '/embed/' . $type . '.html?w=' . rawurlencode( $id ); $frame_id = 'gfw-' . $id; $allow = $type === 'youtube' ? ' allow="fullscreen" allowfullscreen' : ''; $html = ''; return $html . dreamwidget_page_script(); } add_shortcode( 'dreamwidget', 'dreamwidget_render' ); /* The block: a widget id and a kind, rendered on the server through the shortcode, so * the editor and the site print the same thing. */ function dreamwidget_register_block() { if ( ! function_exists( 'register_block_type' ) ) { return; } wp_register_script( 'dreamwidget-block', plugins_url( 'block/block.js', __FILE__ ), array( 'wp-blocks', 'wp-element', 'wp-components', 'wp-block-editor' ), DREAMWIDGET_VERSION, true ); register_block_type( 'dreamwidget/widget', array( 'editor_script' => 'dreamwidget-block', 'render_callback' => function ( $attributes ) { return dreamwidget_render( array( 'id' => isset( $attributes['widgetId'] ) ? $attributes['widgetId'] : '', 'type' => isset( $attributes['kind'] ) ? $attributes['kind'] : 'logos' ) ); }, 'attributes' => array( 'widgetId' => array( 'type' => 'string', 'default' => '' ), 'kind' => array( 'type' => 'string', 'default' => 'logos' ), ), ) ); } add_action( 'init', 'dreamwidget_register_block' );