WP_Customize_Nav_Menu_Setting::sanitize() WordPress Method

The WP_Customize_Nav_Menu_Setting::sanitize() method is used to sanitize nav menu settings. This is called before the menu is saved to the database.

WP_Customize_Nav_Menu_Setting::sanitize( array $value ) #

Sanitize an input.


Description

Note that parent::sanitize() erroneously does wp_unslash() on $value, but we remove that in this override.


Top ↑

Parameters

$value

(array)(Required)The menu value to sanitize.


Top ↑

Return

(array|false|null) Null if an input isn't valid. False if it is marked for deletion. Otherwise the sanitized value.


Top ↑

Source

File: wp-includes/customize/class-wp-customize-nav-menu-setting.php

	public function sanitize( $value ) {
		// Menu is marked for deletion.
		if ( false === $value ) {
			return $value;
		}

		// Invalid.
		if ( ! is_array( $value ) ) {
			return null;
		}

		$default = array(
			'name'        => '',
			'description' => '',
			'parent'      => 0,
			'auto_add'    => false,
		);
		$value   = array_merge( $default, $value );
		$value   = wp_array_slice_assoc( $value, array_keys( $default ) );

		$value['name']        = trim( esc_html( $value['name'] ) ); // This sanitization code is used in wp-admin/nav-menus.php.
		$value['description'] = sanitize_text_field( $value['description'] );
		$value['parent']      = max( 0, (int) $value['parent'] );
		$value['auto_add']    = ! empty( $value['auto_add'] );

		if ( '' === $value['name'] ) {
			$value['name'] = _x( '(unnamed)', 'Missing menu name.' );
		}

		/** This filter is documented in wp-includes/class-wp-customize-setting.php */
		return apply_filters( "customize_sanitize_{$this->id}", $value, $this );
	}


Top ↑

Changelog

Changelog
VersionDescription
4.3.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.