PluginProbe
Gutenberg / 8.9.3
Gutenberg v8.9.3
23.9.1 23.9.0 23.8.0 23.7.2 23.7.1 23.7.0 23.6.1 23.6.2 23.6.0 23.5.3 23.5.2 23.5.1 23.5.0 23.4.0 23.3.2 23.3.1 23.3.0 23.2.0 23.2.1 23.2.2 23.1.1 23.1.0 23.0.1 12.6.0 7.4.0 All 402 releases
gutenberg / lib / class-wp-widget-block.php

class-wp-widget-block.php in Gutenberg 8.9.3, at lib/class-wp-widget-block.php

90 lines 2.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Widget API: WP_Widget_Block class
4 *
5 * @package Gutenberg
6 */
7
8 /**
9 * Core class used to implement a Block widget.
10 *
11 * @see WP_Widget
12 */
13 class WP_Widget_Block extends WP_Widget {
14
15 /**
16 * Default instance.
17 *
18 * @since 4.8.1
19 * @var array
20 */
21 protected $default_instance = array(
22 'content' => '',
23 );
24
25 /**
26 * Sets up a new Block widget instance.
27 *
28 * @since 4.8.1
29 */
30 public function __construct() {
31 $widget_ops = array(
32 'classname' => 'widget_block',
33 'description' => __( 'Gutenberg block.', 'gutenberg' ),
34 'customize_selective_refresh' => true,
35 );
36 $control_ops = array(
37 'width' => 400,
38 'height' => 350,
39 );
40 parent::__construct( 'block', __( 'Block', 'gutenberg' ), $widget_ops, $control_ops );
41 }
42
43 /**
44 * Outputs the content for the current Block widget instance.
45 *
46 * @since 4.8.1
47 *
48 * @global WP_Post $post Global post object.
49 *
50 * @param array $args Display arguments including 'before_title', 'after_title',
51 * 'before_widget', and 'after_widget'.
52 * @param array $instance Settings for the current Block widget instance.
53 */
54 public function widget( $args, $instance ) {
55 echo do_blocks( $instance['content'] );
56 }
57
58 /**
59 * Handles updating settings for the current Block widget instance.
60 *
61 * @since 4.8.1
62 *
63 * @param array $new_instance New settings for this instance as input by the user via
64 * WP_Widget::form().
65 * @param array $old_instance Old settings for this instance.
66 * @return array Settings to save or bool false to cancel saving.
67 */
68 public function update( $new_instance, $old_instance ) {
69 $instance = array_merge( $this->default_instance, $old_instance );
70 $instance['content'] = $new_instance['content'];
71 return $instance;
72 }
73
74 /**
75 * Outputs the Block widget settings form.
76 *
77 * @see WP_Widget_Custom_HTML::render_control_template_scripts()
78 *
79 * @param array $instance Current instance.
80 */
81 public function form( $instance ) {
82 $instance = wp_parse_args( (array) $instance, $this->default_instance );
83 echo do_blocks( $instance['content'] );
84 ?>
85 <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>
86 <?php
87 }
88
89 }
90