$post_data = !
empty( $_REQUEST['post_data'
] ) ?
_wp_get_allowed_postdata( _wp_translate_postdata( false,
(array) $_REQUEST['post_data'
] ) ) : array
();
if ( is_wp_error( $post_data ) ) { wp_die( $post_data->
get_error_message() );
} // If the context is custom header or background, make sure the uploaded file is an image.
if ( isset( $post_data['context'
] ) &&
in_array( $post_data['context'
], array
( 'custom-header', 'custom-background'
), true
) ) { $wp_filetype =
wp_check_filetype_and_ext( $_FILES['async-upload'
]['tmp_name'
],
$_FILES['async-upload'
]['name'
] );
if ( !
wp_match_mime_types( 'image',
$wp_filetype['type'
] ) ) { echo wp_json_encode( array
( 'success' => false,
'data' => array
( 'message' =>
__( 'The uploaded file is not a valid image. Please try again.'
),
'filename' =>
esc_html( $_FILES['async-upload'
]['name'
] ),
),
) );
wp_die();
}