WP_Widget_Links::update( array $new_instance, array $old_instance ): array

In this article

Handles updating settings for the current Links widget instance.

Parameters

$new_instancearrayrequired
New settings for this instance as input by the user via WP_Widget::form().
$old_instancearrayrequired
Old settings for this instance.

Return

array Updated settings to save.

Source

public function update( $new_instance, $old_instance ) {
	$new_instance = (array) $new_instance;
	$instance     = array(
		'images'      => 0,
		'name'        => 0,
		'description' => 0,
		'rating'      => 0,
	);
	foreach ( $instance as $field => $val ) {
		if ( isset( $new_instance[ $field ] ) ) {
			$instance[ $field ] = 1;
		}
	}

	$instance['orderby'] = 'name';
	if ( in_array( $new_instance['orderby'], array( 'name', 'rating', 'id', 'rand' ), true ) ) {
		$instance['orderby'] = $new_instance['orderby'];
	}

	$instance['category'] = (int) $new_instance['category'];
	$instance['limit']    = ! empty( $new_instance['limit'] ) ? (int) $new_instance['limit'] : -1;

	return $instance;
}

Changelog

VersionDescription
2.8.0Introduced.

User Contributed Notes

You must log in before being able to contribute a note or feedback.