Skip to content

Commit

Permalink
[widgets.php] Use textarea for editing block widgets (#24899)
Browse files Browse the repository at this point in the history
* Use textarea instead of block preview

* Set rows and cols on <textarea>

* Use wp-block-widget-textarea class
  • Loading branch information
adamziel authored Feb 18, 2021
1 parent fce2a47 commit e8b901c
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 14 deletions.
14 changes: 1 addition & 13 deletions lib/class-wp-widget-block.php
Original file line number Diff line number Diff line change
Expand Up @@ -175,20 +175,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 = $this->get_field_id( 'content' );
?>
<br/>
<textarea id="<?php echo $textarea_id; ?>" name="<?php echo $this->get_field_name( 'content' ); ?>"
class="content sync-input" hidden><?php echo esc_textarea( $instance['content'] ); ?></textarea>
<script>
(function() {
var link = "<?php echo esc_js( admin_url( 'themes.php?page=gutenberg-widgets' ) ); ?>";
var container = jQuery('#<?php echo $textarea_id; ?>').closest(".form").find('.widget-control-actions .alignleft');
container.prepend(jQuery('<span> |</span>'));
container.prepend(jQuery('<a href="'+link+'" class="button-link">Edit</a>'));
})();
</script>
<textarea id="<?php echo $this->get_field_id( 'content' ); ?>" name="<?php echo $this->get_field_name( 'content' ); ?>" rows="6" cols="50" class="widefat text wp-block-widget-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 @@ -33,7 +33,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-widget-textarea { width: 100%; min-height: 5em; margin: 8px 0 16px 0; }'
);
return;
}
Expand Down

0 comments on commit e8b901c

Please sign in to comment.