Custom_Image_Header::ajax_header_add() WordPress Method

The Custom_Image_Header::ajax_header_add() method is used to add a custom image header to a WordPress site. This method allows for a custom image to be uploaded and then set as the header image for the site. This method can be used to add a custom image header to a WordPress site.

Custom_Image_Header::ajax_header_add() #

Given an attachment ID for a header image, updates its “last used” timestamp to now.


Description

Triggered when the user tries adds a new header image from the Media Manager, even if s/he doesn’t save that change.


Top ↑

Source

File: wp-admin/includes/class-custom-image-header.php

	public function ajax_header_add() {
		check_ajax_referer( 'header-add', 'nonce' );

		if ( ! current_user_can( 'edit_theme_options' ) ) {
			wp_send_json_error();
		}

		$attachment_id = absint( $_POST['attachment_id'] );
		if ( $attachment_id < 1 ) {
			wp_send_json_error();
		}

		$key = '_wp_attachment_custom_header_last_used_' . get_stylesheet();
		update_post_meta( $attachment_id, $key, time() );
		update_post_meta( $attachment_id, '_wp_attachment_is_custom_header', get_stylesheet() );

		wp_send_json_success();
	}


Top ↑

Changelog

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