wp_ajax_upload_attachment example

require_once ABSPATH . 'wp-admin/admin.php';

header( 'Content-Type: text/plain; charset=' . get_option( 'blog_charset' ) );

if ( isset( $_REQUEST['action'] ) && 'upload-attachment' === $_REQUEST['action'] ) {
    require ABSPATH . 'wp-admin/includes/ajax-actions.php';

    send_nosniff_header();
    nocache_headers();

    wp_ajax_upload_attachment();
    die( '0' );
}

if ( ! current_user_can( 'upload_files' ) ) {
    wp_die( __( 'Sorry, you are not allowed to upload files.' ) );
}

// Just fetch the detail form for that attachment. if ( isset( $_REQUEST['attachment_id'] ) && (int) $_REQUEST['attachment_id'] && $_REQUEST['fetch'] ) {
    $id   = (int) $_REQUEST['attachment_id'];
    $post = get_post( $id );
    
Home | Imprint | This part of the site doesn't use cookies.