wp/wp-includes/widgets/class-wp-widget-custom-html.php
changeset 18 be944660c56a
parent 16 a86126ab1dd4
child 21 48c4eec2b7e6
equal deleted inserted replaced
17:34716fd837a4 18:be944660c56a
    43 	public function __construct() {
    43 	public function __construct() {
    44 		$widget_ops  = array(
    44 		$widget_ops  = array(
    45 			'classname'                   => 'widget_custom_html',
    45 			'classname'                   => 'widget_custom_html',
    46 			'description'                 => __( 'Arbitrary HTML code.' ),
    46 			'description'                 => __( 'Arbitrary HTML code.' ),
    47 			'customize_selective_refresh' => true,
    47 			'customize_selective_refresh' => true,
       
    48 			'show_instance_in_rest'       => true,
    48 		);
    49 		);
    49 		$control_ops = array(
    50 		$control_ops = array(
    50 			'width'  => 400,
    51 			'width'  => 400,
    51 			'height' => 350,
    52 			'height' => 350,
    52 		);
    53 		);
    56 	/**
    57 	/**
    57 	 * Add hooks for enqueueing assets when registering all widget instances of this widget class.
    58 	 * Add hooks for enqueueing assets when registering all widget instances of this widget class.
    58 	 *
    59 	 *
    59 	 * @since 4.9.0
    60 	 * @since 4.9.0
    60 	 *
    61 	 *
    61 	 * @param integer $number Optional. The unique order number of this widget instance
    62 	 * @param int $number Optional. The unique order number of this widget instance
    62 	 *                        compared to other instances of the same class. Default -1.
    63 	 *                    compared to other instances of the same class. Default -1.
    63 	 */
    64 	 */
    64 	public function _register_one( $number = -1 ) {
    65 	public function _register_one( $number = -1 ) {
    65 		parent::_register_one( $number );
    66 		parent::_register_one( $number );
    66 		if ( $this->registered ) {
    67 		if ( $this->registered ) {
    67 			return;
    68 			return;
    81 		// Note this action is used to ensure the help text is added to the end.
    82 		// Note this action is used to ensure the help text is added to the end.
    82 		add_action( 'admin_head-widgets.php', array( 'WP_Widget_Custom_HTML', 'add_help_text' ) );
    83 		add_action( 'admin_head-widgets.php', array( 'WP_Widget_Custom_HTML', 'add_help_text' ) );
    83 	}
    84 	}
    84 
    85 
    85 	/**
    86 	/**
    86 	 * Filter gallery shortcode attributes.
    87 	 * Filters gallery shortcode attributes.
    87 	 *
    88 	 *
    88 	 * Prevents all of a site's attachments from being shown in a gallery displayed on a
    89 	 * Prevents all of a site's attachments from being shown in a gallery displayed on a
    89 	 * non-singular template where a $post context is not available.
    90 	 * non-singular template where a $post context is not available.
    90 	 *
    91 	 *
    91 	 * @since 4.9.0
    92 	 * @since 4.9.0
   144 		unset( $simulated_text_widget_instance['content'] ); // Was moved to 'text' prop.
   145 		unset( $simulated_text_widget_instance['content'] ); // Was moved to 'text' prop.
   145 
   146 
   146 		/** This filter is documented in wp-includes/widgets/class-wp-widget-text.php */
   147 		/** This filter is documented in wp-includes/widgets/class-wp-widget-text.php */
   147 		$content = apply_filters( 'widget_text', $instance['content'], $simulated_text_widget_instance, $this );
   148 		$content = apply_filters( 'widget_text', $instance['content'], $simulated_text_widget_instance, $this );
   148 
   149 
   149 		// Adds noreferrer and noopener relationships, without duplicating values, to all HTML A elements that have a target.
   150 		// Adds 'noopener' relationship, without duplicating values, to all HTML A elements that have a target.
   150 		$content = wp_targeted_link_rel( $content );
   151 		$content = wp_targeted_link_rel( $content );
   151 
   152 
   152 		/**
   153 		/**
   153 		 * Filters the content of the Custom HTML widget.
   154 		 * Filters the content of the Custom HTML widget.
   154 		 *
   155 		 *
   155 		 * @since 4.8.1
   156 		 * @since 4.8.1
   156 		 *
   157 		 *
   157 		 * @param string                $content  The widget content.
   158 		 * @param string                $content  The widget content.
   158 		 * @param array                 $instance Array of settings for the current widget.
   159 		 * @param array                 $instance Array of settings for the current widget.
   159 		 * @param WP_Widget_Custom_HTML $this     Current Custom HTML widget instance.
   160 		 * @param WP_Widget_Custom_HTML $widget   Current Custom HTML widget instance.
   160 		 */
   161 		 */
   161 		$content = apply_filters( 'widget_custom_html_content', $content, $instance, $this );
   162 		$content = apply_filters( 'widget_custom_html_content', $content, $instance, $this );
   162 
   163 
   163 		// Restore post global.
   164 		// Restore post global.
   164 		$post = $original_post;
   165 		$post = $original_post;
   245 	 * @param array $instance Current instance.
   246 	 * @param array $instance Current instance.
   246 	 */
   247 	 */
   247 	public function form( $instance ) {
   248 	public function form( $instance ) {
   248 		$instance = wp_parse_args( (array) $instance, $this->default_instance );
   249 		$instance = wp_parse_args( (array) $instance, $this->default_instance );
   249 		?>
   250 		?>
   250 		<input id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" class="title sync-input" type="hidden" value="<?php echo esc_attr( $instance['title'] ); ?>"/>
   251 		<input id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" class="title sync-input" type="hidden" value="<?php echo esc_attr( $instance['title'] ); ?>" />
   251 		<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>
   252 		<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>
   252 		<?php
   253 		<?php
   253 	}
   254 	}
   254 
   255 
   255 	/**
   256 	/**
   279 				?>
   280 				?>
   280 				<?php if ( ! empty( $disallowed_html ) ) : ?>
   281 				<?php if ( ! empty( $disallowed_html ) ) : ?>
   281 					<# if ( data.codeEditorDisabled ) { #>
   282 					<# if ( data.codeEditorDisabled ) { #>
   282 						<p>
   283 						<p>
   283 							<?php _e( 'Some HTML tags are not permitted, including:' ); ?>
   284 							<?php _e( 'Some HTML tags are not permitted, including:' ); ?>
   284 							<code><?php echo join( '</code>, <code>', $disallowed_html ); ?></code>
   285 							<code><?php echo implode( '</code>, <code>', $disallowed_html ); ?></code>
   285 						</p>
   286 						</p>
   286 					<# } #>
   287 					<# } #>
   287 				<?php endif; ?>
   288 				<?php endif; ?>
   288 			<?php endif; ?>
   289 			<?php endif; ?>
   289 
   290