wp-config.php:

define("S3_UPLOADS_ENDPOINT", "https://<Cloudflare account ID>.r2.cloudflarestorage.com")
define("S3_UPLOADS_BUCKET", "<R2 bucket Name>")
define("S3_UPLOADS_BUCKET_URL", "<R2 bucket public url or domain>")
define("S3_UPLOADS_REGION", "auto")
define("S3_UPLOADS_KEY", "<R2 access key ID>")
define("S3_UPLOADS_SECRET", "<R2 secret access key>")

functions.php文件或自定义插件中。

function tw_s3_uploads_s3_client_params( $params ) {
    $params["endpoint"] = S3_UPLOADS_ENDPOINT;
    $params["use_path_style_endpoint"] = true;
    return $params;
}
add_filter( "s3_uploads_s3_client_params", "tw_s3_uploads_s3_client_params");

https://github.com/humanmade/S3-Uploads/issues/576#issuecomment-1511622949