wppaste
WordPress

Custom_Image_Header::set_header_image( mixed $choice )

Since
3.4.0
Source
wp-admin/includes/class-custom-image-header.php:1173
Chooses a header image, selected from existing uploaded and default headers, or provides an array of uploaded header data (either new, or from media library).

Parameters

$choicemixed
Which header image to select. Allows for values of 'random-default-image', for randomly cycling among the default images; 'random-uploaded-image', for randomly cycling among the uploaded images; the key of a default image registered for that theme; and the key of an image uploaded for that theme (the attachment ID of the image). Or an array of arguments: attachment_id, url, width, height. All are required.

Uses · 7

Used by · 4

Source

	final public function set_header_image( $choice ) {		if ( is_array( $choice ) || is_object( $choice ) ) {			$choice = (array) $choice; 			if ( ! isset( $choice['attachment_id'] ) || ! isset( $choice['url'] ) ) {				return;			} 			$choice['url'] = sanitize_url( $choice['url'] ); 			$header_image_data = (object) array(				'attachment_id' => $choice['attachment_id'],				'url'           => $choice['url'],				'thumbnail_url' => $choice['url'],				'height'        => $choice['height'],				'width'         => $choice['width'],			); 			update_post_meta( $choice['attachment_id'], '_wp_attachment_is_custom_header', get_stylesheet() ); 			set_theme_mod( 'header_image', $choice['url'] );			set_theme_mod( 'header_image_data', $header_image_data ); 			return;		} 		if ( in_array( $choice, array( 'remove-header', 'random-default-image', 'random-uploaded-image' ), true ) ) {			set_theme_mod( 'header_image', $choice );			remove_theme_mod( 'header_image_data' ); 			return;		} 		$uploaded = get_uploaded_header_images(); 		if ( $uploaded && isset( $uploaded[ $choice ] ) ) {			$header_image_data = $uploaded[ $choice ];		} else {			$this->process_default_headers();			if ( isset( $this->default_headers[ $choice ] ) ) {				$header_image_data = $this->default_headers[ $choice ];			} else {				return;			}		} 		set_theme_mod( 'header_image', sanitize_url( $header_image_data['url'] ) );		set_theme_mod( 'header_image_data', $header_image_data );	}

History

Introduced in 3.4.0. Unchanged from 6.7.7 through 7.1.0.

  1. 6.7.7
  2. 6.8.8
  3. 6.9.7
  4. 7.0.4
  5. 7.1.0

Signature, return type and hooks compared across 5 parsed releases.

About this page

Parsed data
Generated from the wordpress-develop 6.9.7 tag, from src/wp-admin/includes/class-custom-image-header.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it.
Corrections
Something wrong on this page? Report it and it gets fixed in the next regeneration.