WP_Widget_Text::update() WordPress Method

The WP_Widget_Text::update() method is used to update the widget settings. This is called when the user saves the widget settings from the WordPress admin. The method accepts two arguments, the first is the widget settings array and the second is the new settings array.

WP_Widget_Text::update( array $new_instance, array $old_instance ) #

Handles updating settings for the current Text widget instance.


Parameters

$new_instance

(array)(Required)New settings for this instance as input by the user via WP_Widget::form().

$old_instance

(array)(Required)Old settings for this instance.


Top ↑

Return

(array) Settings to save or bool false to cancel saving.


Top ↑

Source

File: wp-includes/widgets/class-wp-widget-text.php

	public function update( $new_instance, $old_instance ) {
		$new_instance = wp_parse_args(
			$new_instance,
			array(
				'title'  => '',
				'text'   => '',
				'filter' => false, // For back-compat.
				'visual' => null,  // Must be explicitly defined.
			)
		);

		$instance = $old_instance;

		$instance['title'] = sanitize_text_field( $new_instance['title'] );
		if ( current_user_can( 'unfiltered_html' ) ) {
			$instance['text'] = $new_instance['text'];
		} else {
			$instance['text'] = wp_kses_post( $new_instance['text'] );
		}

		$instance['filter'] = ! empty( $new_instance['filter'] );

		// Upgrade 4.8.0 format.
		if ( isset( $old_instance['filter'] ) && 'content' === $old_instance['filter'] ) {
			$instance['visual'] = true;
		}
		if ( 'content' === $new_instance['filter'] ) {
			$instance['visual'] = true;
		}

		if ( isset( $new_instance['visual'] ) ) {
			$instance['visual'] = ! empty( $new_instance['visual'] );
		}

		// Filter is always true in visual mode.
		if ( ! empty( $instance['visual'] ) ) {
			$instance['filter'] = true;
		}

		return $instance;
	}


Top ↑

Changelog

Changelog
VersionDescription
2.8.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.