On this page
Custom_Image_Header::step_2_manage_upload()
Upload the file to be cropped in the second step.
Source
File: wp-admin/includes/class-custom-image-header.php. View all references
public function step_2_manage_upload() {
$overrides = array( 'test_form' => false );
$uploaded_file = $_FILES['import'];
$wp_filetype = wp_check_filetype_and_ext( $uploaded_file['tmp_name'], $uploaded_file['name'] );
if ( ! wp_match_mime_types( 'image', $wp_filetype['type'] ) ) {
wp_die( __( 'The uploaded file is not a valid image. Please try again.' ) );
}
$file = wp_handle_upload( $uploaded_file, $overrides );
if ( isset( $file['error'] ) ) {
wp_die( $file['error'], __( 'Image Upload Error' ) );
}
$url = $file['url'];
$type = $file['type'];
$file = $file['file'];
$filename = wp_basename( $file );
// Construct the attachment array.
$attachment = array(
'post_title' => $filename,
'post_content' => $url,
'post_mime_type' => $type,
'guid' => $url,
'context' => 'custom-header',
);
// Save the data.
$attachment_id = wp_insert_attachment( $attachment, $file );
return compact( 'attachment_id', 'file', 'filename', 'url', 'type' );
}
Related
Uses
| Uses | Description |
|---|---|
| wp_handle_upload() wp-admin/includes/file.php | Wrapper for _wp_handle_upload() . |
| wp_check_filetype_and_ext() wp-includes/functions.php | Attempts to determine the real file type of a file. |
| wp_insert_attachment() wp-includes/post.php | Inserts an attachment. |
| wp_match_mime_types() wp-includes/post.php | Checks a MIME-Type against a list. |
| __() wp-includes/l10n.php | Retrieves the translation of $text. |
| wp_basename() wp-includes/formatting.php | i18n-friendly version of basename(). |
| wp_die() wp-includes/functions.php | Kills WordPress execution and displays HTML page with an error message. |
Used By
| Used By | Description |
|---|---|
| Custom_Image_Header::step_2() wp-admin/includes/class-custom-image-header.php | Display second step of custom header image page. |
Changelog
| Version | Description |
|---|---|
| 3.4.0 | Introduced. |
© 2003–2022 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/classes/custom_image_header/step_2_manage_upload