Cloudflare R2 media offload manager for peptiderepo.com. Built on WP Offload Media Lite. Supersedes the one-off migration script and mu-plugin peptiderepo-r2-endpoint.php. Features: - Admin page under Peptide Repo > R2 Media Manager (shared umbrella menu) - ensure_umbrella_menu() guard — safe for multi-plugin umbrella sharing - Batch AJAX migration to R2 with pause/resume and progress bar - Remove-local-copies batch with physical disk presence check - Activity log table (wp_pr_r2_log) with self-healing on plugins_loaded - Test R2 connection button - R2 endpoint injection via as3cf_aws_s3_client_args filter
55 lines
1.9 KiB
PHP
Executable File
55 lines
1.9 KiB
PHP
Executable File
<?php
|
|
/**
|
|
* What: Injects the Cloudflare R2 endpoint into WP Offload Media's AWS SDK client.
|
|
* Supersedes wp-content/mu-plugins/peptiderepo-r2-endpoint.php — that
|
|
* mu-plugin should be deleted once this plugin is active.
|
|
* Who: Registered via `as3cf_aws_s3_client_args` filter; fires whenever WP
|
|
* Offload Media initialises its S3 client (uploads, deletes, URL signing).
|
|
* Depends: WP Offload Media Lite (amazon-s3-and-cloudfront).
|
|
*
|
|
* @see peptiderepo-r2-manager.php (bootstraps this class)
|
|
* @see https://deliciousbrains.com/wp-offload-media/doc/custom-s3-compatible-storage/
|
|
*/
|
|
|
|
if ( ! defined( 'ABSPATH' ) ) {
|
|
exit;
|
|
}
|
|
|
|
class PR_R2_Endpoint {
|
|
|
|
/**
|
|
* Cloudflare R2 account-level S3-compatible endpoint.
|
|
* Using the account endpoint (not the public URL) so the AWS SDK can reach
|
|
* the bucket via path-style access regardless of custom domain routing.
|
|
*/
|
|
const ENDPOINT = 'https://a16f4baa82a1074c47f696e7cb6d5995.r2.cloudflarestorage.com';
|
|
|
|
/**
|
|
* Register the endpoint-injection filter.
|
|
* Called once from the plugin bootstrap.
|
|
*
|
|
* @return void
|
|
*/
|
|
public static function init(): void {
|
|
add_filter( 'as3cf_aws_s3_client_args', [ __CLASS__, 'inject_r2_endpoint' ], 10, 1 );
|
|
}
|
|
|
|
/**
|
|
* Override the AWS SDK S3 client endpoint to Cloudflare R2.
|
|
*
|
|
* Uses path-style endpoint so the bucket name appears in the URL path
|
|
* (required with the account-level R2 endpoint, which doesn't support
|
|
* virtual-hosted-style bucket subdomains).
|
|
*
|
|
* @param array<string,mixed> $args AWS SDK client constructor args from WP Offload Media.
|
|
* @return array<string,mixed> Modified args with R2 endpoint injected.
|
|
*
|
|
* Side effects: none — pure filter.
|
|
*/
|
|
public static function inject_r2_endpoint( array $args ): array {
|
|
$args['endpoint'] = self::ENDPOINT;
|
|
$args['use_path_style_endpoint'] = true;
|
|
return $args;
|
|
}
|
|
}
|