Custom_Image_Header::step_2_manage_upload()
最后更新于:2021-11-25 19:49:41
Custom_Image_Header::step_2_manage_upload()Upload the file to be cropped in the second step.
源文件
文件: gc-admin/includes/class-custom-image-header.php
public function step_2_manage_upload() {
$overrides = array( 'test_form' => false );
$uploaded_file = $_FILES['import'];
$gc_filetype = gc_check_filetype_and_ext( $uploaded_file['tmp_name'], $uploaded_file['name'] );
if ( ! gc_match_mime_types( 'image', $gc_filetype['type'] ) ) {
gc_die( __( 'The uploaded file is not a valid image. Please try again.' ) );
}
$file = gc_handle_upload( $uploaded_file, $overrides );
if ( isset( $file['error'] ) ) {
gc_die( $file['error'], __( 'Image Upload Error' ) );
}
$url = $file['url'];
$type = $file['type'];
$file = $file['file'];
$filename = gc_basename( $file );
// Construct the object array.
$object = array(
'post_title' => $filename,
'post_content' => $url,
'post_mime_type' => $type,
'guid' => $url,
'context' => 'custom-header',
);
// Save the data.
$attachment_id = gc_insert_attachment( $object, $file );
return compact( 'attachment_id', 'file', 'filename', 'url', 'type' );
}