Custom_Image_Header::ajax_header_add()
- Since
- 3.9.0
- Source
wp-admin/includes/class-custom-image-header.php:1456
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.
Uses · 7
- check_ajax_referer()Verifies the Ajax request to prevent processing requests external of the blog.
- current_user_can()Returns whether the current user has the specified capability.
- wp_send_json_error()Sends a JSON response back to an Ajax request, indicating failure.
- absint()Converts a value to non-negative integer.
- get_stylesheet()Retrieves name of the current stylesheet.
- update_post_meta()Updates a post meta field based on the given post ID.
- wp_send_json_success()Sends a JSON response back to an Ajax request, indicating success.
Source
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(); }History
Introduced in 3.9.0. One change between 6.7.7 and 7.1.0.
Signature, return type and hooks compared across 5 parsed releases.
7.1.0
Return type changed from
none to never.verified against source3.9.0
Introduced.from the docblock
About this page
- Parsed data
- Generated from the wordpress-develop 6.8.8 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.