WP_Customize_Header_Image_Setting::sanitize( mixed $value )

Sanitizes a header value.


Description

The value is expected to be one of the following:

  • An array of header image data, with the keys attachment_id, url, thumbnail_url, timestamp, width, height, alt_text, and attachment_parent, as supplied by get_uploaded_header_images(). Any other key is discarded.
  • An array with a choice key, being the legacy format in which any of the other accepted values is nested.
  • The string remove-header, random-default-image, or random-uploaded-image.
  • A string corresponding to one of the keys for the array returned by get_uploaded_header_images(), or one of the keys for the array passed into register_default_headers().

See also


Parameters

$value

(mixed) (Required) Value to sanitize.


Return

(array|string|WP_Error|null) Sanitized value, or null/WP_Error if invalid. The array holds the header image data, or that data nested under a choice key, before the customize_sanitize_header_image_data filter, which may return anything, is applied to it.


Source

File: wp-includes/customize/class-wp-customize-header-image-setting.php

	public function sanitize( $value ) {
		/*
		 * The update() method unwraps the legacy `choice` format before handing the value off to
		 * Custom_Image_Header::set_header_image(), so the nested value is what must be sanitized.
		 */
		if ( is_array( $value ) && isset( $value['choice'] ) ) {
			$choice = $this->sanitize_choice( $value['choice'] );
			if ( is_null( $choice ) || is_wp_error( $choice ) ) {
				return $choice;
			}
			$value = array( 'choice' => $choice );
		} else {
			$value = $this->sanitize_choice( $value );
			if ( is_null( $value ) || is_wp_error( $value ) ) {
				return $value;
			}
		}

		return parent::sanitize( $value );
	}


Changelog

Changelog
Version Description
7.1.1 Introduced.