How to make custom bulk actions work on the media/upload page?

If you want to use your code, try this:

If you want to check if the medias are attachments, you can try to use $_REQUEST['detached']

add_action( 'load-upload.php', 'export_media_test' );

function export_media_test() {

    if ( ! isset( $_REQUEST['action'] ) )
        return;

    echo 'Export Media';

    if ( isset( $_REQUEST['detached'] ) ) {
        die( 'No attachments' );
    } else {
        die( 'Attachments' );
    }

    exit();
}

You can not check an nonce that wasn’t set. The nonce bulk-posts is set in edit.php, and this is the the posts list. In upload.php is the bulk-media nonce set. So use check_admin_referer('bulk-media');

Leave a Comment