Skip to content

Commit

Permalink
Use textarea instead of block preview
Browse files Browse the repository at this point in the history
  • Loading branch information
adamziel committed Aug 28, 2020
1 parent cefab03 commit a6d86ac
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 33 deletions.
30 changes: 0 additions & 30 deletions gutenberg.php
Original file line number Diff line number Diff line change
Expand Up @@ -191,36 +191,6 @@ function gutenberg_register_widgets() {
}

register_widget( 'WP_Widget_Block' );
// By default every widget on widgets.php is wrapped with a <form>.
// This means that you can sometimes end up with invalid HTML, e.g. when
// one of the widgets is a Search block.
//
// To fix the problem, let's add a filter that moves the form below the actual
// widget content.
global $pagenow;
if ( 'widgets.php' === $pagenow ) {
add_filter(
'dynamic_sidebar_params',
'gutenberg_override_sidebar_params_for_block_widget'
);
}
}

/**
* Overrides dynamic_sidebar_params to make sure Blocks are not wrapped in <form> tag.
*
* @param array $arg Dynamic sidebar params.
* @return array Updated dynamic sidebar params.
*/
function gutenberg_override_sidebar_params_for_block_widget( $arg ) {
if ( 'Block' === $arg[0]['widget_name'] ) {
$arg[0]['before_form'] = '';
$arg[0]['before_widget_content'] = '<div class="widget-content">';
$arg[0]['after_widget_content'] = '</div><form class="block-widget-form">';
$arg[0]['after_form'] = '</form>';
}

return $arg;
}

add_action( 'widgets_init', 'gutenberg_register_widgets' );
3 changes: 1 addition & 2 deletions lib/class-wp-widget-block.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,8 @@ public function update( $new_instance, $old_instance ) {
*/
public function form( $instance ) {
$instance = wp_parse_args( (array) $instance, $this->default_instance );
echo do_blocks( $instance['content'] );
?>
<textarea id="<?php echo $this->get_field_id( 'content' ); ?>" name="<?php echo $this->get_field_name( 'content' ); ?>" class="content sync-input" hidden><?php echo esc_textarea( $instance['content'] ); ?></textarea>
<textarea id="<?php echo $this->get_field_id( 'content' ); ?>" name="<?php echo $this->get_field_name( 'content' ); ?>" class="widefat text wp-block-textarea"><?php echo esc_textarea( $instance['content'] ); ?></textarea>
<?php
}

Expand Down
2 changes: 1 addition & 1 deletion lib/widgets-page.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ function gutenberg_widgets_init( $hook ) {
wp_enqueue_style( 'wp-block-library-theme' );
wp_add_inline_style(
'wp-block-library-theme',
'.block-widget-form .widget-control-save { display: none; }'
'.wp-block-textarea { width: 100%; min-height: 5em; margin: 8px 0 16px 0; }'
);
return;
}
Expand Down

0 comments on commit a6d86ac

Please sign in to comment.