'Permission denied.' ) ); } check_ajax_referer( 'upload-attachment', 'nonce' ); if ( empty( $_FILES['async-upload'] ) ) { wp_send_json_error( array( 'message' => 'No file uploaded.' ) ); } $file = $_FILES['async-upload']; $overrides = array( 'test_form' => false, 'mimes' => null, ); $attachment_id = media_handle_upload( 'async-upload', 0, array(), $overrides ); if ( is_wp_error( $attachment_id ) ) { wp_send_json_error( array( 'message' => $attachment_id->get_error_message() ) ); } $attachment = get_post( $attachment_id ); $url = wp_get_attachment_url( $attachment_id ); wp_send_json_success( array( 'id' => $attachment_id, 'url' => $url, 'title' => $attachment->post_title, ) ); } } endif;