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' ) ); ?>
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://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' ) );
?>
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.
-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.',
)
);
?>
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.
' . 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' ) );
?>
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.r2.dev address (R2 → bucket → Settings → Public access) before touching DNS.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).