WordPress at Your Fingertips
function is not described

Custom_Image_Header::ajax_header_add() public WP 3.9.0

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

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

{} It's a method of the class: Custom_Image_Header{}

No Hooks.

Return

null. Nothing.

Usage

$Custom_Image_Header = new Custom_Image_Header();
$Custom_Image_Header->ajax_header_add();

Changelog

Since 3.9.0 Introduced.

Code of Custom_Image_Header::ajax_header_add() WP 5.8.2

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();
}