Manage R2 API Tokens → Create token with Object Read & Write for your bucket. Copy the Access Key ID and Secret Access Key.', array( 'show_if' => 'r2_enabled' ) ); ?>
'Shown on the R2 overview page.' ) ); CFSP_UI::input( 'r2_bucket', 'Bucket name', array( 'placeholder' => 'example-media' ) ); CFSP_UI::input( 'r2_access_key', 'Access Key ID', array( 'disabled' => $cfsp_keys_def, 'placeholder' => $cfsp_keys_def ? 'Set in wp-config.php' : '', ) ); CFSP_UI::input( 'r2_secret_key', 'Secret Access Key', array( 'type' => 'password', 'disabled' => defined( 'CFSP_R2_SECRET_KEY' ) && CFSP_R2_SECRET_KEY, 'placeholder' => CFSP_Settings::get( 'r2_secret_key' ) ? '•••••••• saved (leave blank to keep)' : '', ) ); ?>
'url', 'placeholder' => 'https://cdn.example.com', 'help' => 'The custom domain connected to the bucket (R2 → bucket → Settings → Custom Domains). Avoid the rate-limited r2.dev address for a live site.', ) ); ?>
Advanced 'Folder inside the bucket. The default wp-content/uploads keeps the same paths as today, so /wp-content/uploads/2026/09/photo.jpg becomes ' . esc_html( $cfsp_public ) . '/2026/09/photo.jpg.', ) ); CFSP_UI::input( 'r2_endpoint', 'S3 endpoint (optional)', array( 'type' => 'url', 'placeholder' => 'https://.r2.cloudflarestorage.com', 'help' => 'Only for EU-jurisdiction buckets (https://<account>.eu.r2.cloudflarestorage.com).' ) ); CFSP_UI::input( 'r2_cache_control', 'Cache-Control header', array( 'help' => 'Sent with every file. WordPress never overwrites a file under the same name, so long caching is safe.' ) ); ?>

Lists the bucket, then writes and deletes a small test file.

CFSP_R2_ACCESS_KEY / CFSP_R2_SECRET_KEY).', 'info' ); } CFSP_UI::card_end(); /* ---------------------------------------------------------------- Sync */ CFSP_UI::card_start( 'Sync media library', '', array( 'show_if' => 'r2_enabled' ) ); ?>
Files in R2…
Last upload…
Sourceuploads/
Loading…

Uploads everything in wp-content/uploads that isn't in R2 yet or has changed: originals, -scaled copies and every thumbnail size. Safe to run again at any time; unchanged files are skipped. Runs in the background. Pause before updating the plugin and Resume afterwards; it continues from the same folder.

4, 'help' => 'Folders inside uploads that are never uploaded (plugin caches, logs, backups). PHP files and dotfiles are always skipped.', ) ); CFSP_UI::textarea( 'r2_exclude_names', 'Skip files named', array( 'rows' => 4, 'placeholder' => "-150x150\n*.bak\n*-scaled.*\n2019/*", 'help' => 'One rule per line. Plain text skips files whose name contains it (-150x150). Use * and ? to match the whole name (*.bak). A rule with / matches the path inside uploads (2019/*). Not case-sensitive. Applies to the full sync and to new uploads.', 'warn' => 'Skipped files are not in R2. If a page uses one, it will be missing on the static site once media is served from R2.', ) ); ?>
Counts the files these rules would skip, before you save.
Remove skipped files from R2

Deletes files that are already in the bucket but match the saved Skip folders or Skip files named rules, for example sizes uploaded before you added a rule. Only files under the key prefix are checked. Save your rules and use Preview first.

'r2_enabled' ) ); CFSP_UI::toggle( 'r2_auto_upload', 'Upload new media automatically', array( 'help' => 'As soon as WordPress finishes creating the image sizes, the original and all sizes are uploaded. Also after editing an image or regenerating thumbnails.' ) ); CFSP_UI::select( 'r2_resync', 'Full re-sync', array( 'off' => 'Off', 'hourly' => 'Hourly', 'twicedaily' => 'Twice daily', 'daily' => 'Daily', 'weekly' => 'Weekly', ), array( 'help' => 'Catches files added outside WordPress\' media flow, e.g. WebP copies made later by an image optimizer.' ) ); CFSP_UI::toggle( 'r2_delete', 'Delete from R2 when media is deleted in WordPress', array( 'help' => 'Off keeps everything in R2 as a backup.', 'warn' => 'Deleting an image in WordPress then removes it, and all its sizes, from the bucket too.', ) ); CFSP_UI::card_end(); /* ---------------------------------------------------------------- Static site */ CFSP_UI::card_start( 'Static pages', '', array( 'show_if' => 'r2_enabled' ) ); CFSP_UI::toggle( 'r2_rewrite', 'Serve media from the public media URL', array( 'help' => 'In exported pages, ' . esc_html( untrailingslashit( $cfsp_uploads['baseurl'] ) ) . '/… becomes ' . esc_html( $cfsp_public ) . '/… in src, srcset, CSS backgrounds, social images and schema.', ) ); CFSP_UI::toggle( 'r2_exclude_export', 'Leave media out of the static site', array( 'show_if' => 'r2_rewrite', 'help' => 'Keeps the GitHub repository and Cloudflare Pages deployment to HTML, CSS and JS, well under the 20,000-file Pages limit. Media already in the repository is removed on the next full push.', ) ); CFSP_UI::notice( 'Finish the first sync before your next Full Site push, otherwise images not yet in R2 will show as broken on the static site.', 'warn', array( 'show_if' => 'r2_rewrite' ) ); CFSP_UI::card_end(); /* ---------------------------------------------------------------- Switch-over guide */ CFSP_UI::card_start( 'Moving an existing media domain to R2', 'If your pages already use a media domain such as https://cdn.example.com/wp-content/uploads/… on another CDN, you can switch it to R2. With the default key prefix the bucket uses exactly the same paths, so after the switch every existing image URL keeps working.', array( 'show_if' => 'r2_enabled' ) ); ?>
  1. Create the bucket and API token, fill in R2 connection and click Test connection.
  2. Set Public media URL to https://cdn.example.com, save, and click Sync media library now. Wait until it reports finished with 0 errors. The Dashboard log shows each folder.
  3. Spot-check a few files via the bucket's temporary r2.dev address (R2 → bucket → Settings → Public access) before touching DNS.
  4. In Cloudflare: R2 → your bucket → Settings → Custom Domains → add cdn.example.com. The domain must be on Cloudflare DNS; Cloudflare replaces the existing CDN's CNAME record for you (remove it first if it asks).
  5. Test a few image URLs, then run a Full Site push. Keep the old CDN active for a day or two until DNS has fully switched, then cancel it.