@@ -27,6 +27,21 @@ public function add_menu_page() {
2727 }
2828
2929 public function register_settings () {
30+ // Plugin mode section.
31+ add_settings_section (
32+ 'rebelboost_mode_section ' ,
33+ __ ( 'Plugin Mode ' , 'rebelboost ' ),
34+ array ( $ this , 'render_mode_section ' ),
35+ 'rebelboost '
36+ );
37+
38+ add_settings_field ( 'rebelboost_mode ' , __ ( 'Operating Mode ' , 'rebelboost ' ), array ( $ this , 'render_mode_field ' ), 'rebelboost ' , 'rebelboost_mode_section ' );
39+
40+ register_setting ( 'rebelboost_settings ' , 'rebelboost_mode ' , array (
41+ 'type ' => 'string ' ,
42+ 'sanitize_callback ' => array ( $ this , 'sanitize_mode ' ),
43+ ) );
44+
3045 // Connection section.
3146 add_settings_section (
3247 'rebelboost_connection ' ,
@@ -109,6 +124,7 @@ public function render_settings_page() {
109124
110125 <hr>
111126
127+ <?php if ( 'proxy ' !== get_option ( 'rebelboost_mode ' , 'integration ' ) ) : ?>
112128 <h2><?php esc_html_e ( 'DNS Setup Guide ' , 'rebelboost ' ); ?> </h2>
113129 <div class="rebelboost-dns-guide">
114130 <p><?php esc_html_e ( 'To enable RebelBoost optimization, point your domain to the RebelBoost proxy: ' , 'rebelboost ' ); ?> </p>
@@ -119,6 +135,10 @@ public function render_settings_page() {
119135 <li><?php esc_html_e ( 'Verify the connection using the "Test Connection" button above. ' , 'rebelboost ' ); ?> </li>
120136 </ol>
121137 </div>
138+ <?php else : ?>
139+ <h2><?php esc_html_e ( 'Proxy Mode Active ' , 'rebelboost ' ); ?> </h2>
140+ <p><?php esc_html_e ( 'RebelBoost is operating in proxy mode. Asset URLs are being rewritten to route through the RebelBoost CDN. No DNS or CDN changes are required. ' , 'rebelboost ' ); ?> </p>
141+ <?php endif ; ?>
122142
123143 <hr>
124144
@@ -221,6 +241,32 @@ public function render_category_header_field() {
221241
222242 // Sanitizers.
223243
244+ public function render_mode_section () {
245+ echo '<p> ' . esc_html__ ( 'Choose how RebelBoost connects to your site. ' , 'rebelboost ' ) . '</p> ' ;
246+ }
247+
248+ public function render_mode_field () {
249+ $ current = get_option ( 'rebelboost_mode ' , 'integration ' );
250+ ?>
251+ <fieldset>
252+ <label style="display:block; margin-bottom:8px;">
253+ <input type="radio" name="rebelboost_mode" value="integration" <?php checked ( $ current , 'integration ' ); ?> >
254+ <strong><?php esc_html_e ( 'Integration ' , 'rebelboost ' ); ?> </strong>
255+ — <?php esc_html_e ( 'Works with your existing CDN. Handles cache invalidation and surrogate keys. Requires CDN/DNS pointing to RebelBoost. ' , 'rebelboost ' ); ?>
256+ </label>
257+ <label style="display:block;">
258+ <input type="radio" name="rebelboost_mode" value="proxy" <?php checked ( $ current , 'proxy ' ); ?> >
259+ <strong><?php esc_html_e ( 'Proxy ' , 'rebelboost ' ); ?> </strong>
260+ — <?php esc_html_e ( 'Routes assets through RebelBoost via WordPress output rewriting. No DNS or CDN changes needed. ' , 'rebelboost ' ); ?>
261+ </label>
262+ </fieldset>
263+ <?php
264+ }
265+
266+ public function sanitize_mode ( $ value ) {
267+ return in_array ( $ value , array ( 'integration ' , 'proxy ' ), true ) ? $ value : 'integration ' ;
268+ }
269+
224270 public function sanitize_host ( $ value ) {
225271 $ value = trim ( $ value );
226272 if ( empty ( $ value ) ) {
@@ -250,11 +296,36 @@ public function ajax_test_connection() {
250296 if ( ! empty ( $ _POST ['host ' ] ) ) {
251297 update_option ( 'rebelboost_host ' , $ this ->sanitize_host ( wp_unslash ( $ _POST ['host ' ] ) ) );
252298 }
299+ if ( isset ( $ _POST ['mode ' ] ) ) {
300+ update_option ( 'rebelboost_mode ' , $ this ->sanitize_mode ( wp_unslash ( $ _POST ['mode ' ] ) ) );
301+ }
253302
254303 $ this ->api_client ->reload ();
255304
256- // Register the origin first so the host has an origin config
257- // before we attempt a purge-based connection test.
305+ $ mode = get_option ( 'rebelboost_mode ' , 'integration ' );
306+
307+ if ( 'proxy ' === $ mode ) {
308+ // In proxy mode, verify the API key first.
309+ $ result = $ this ->api_client ->test_connection ( true );
310+
311+ if ( true !== $ result ) {
312+ wp_send_json_error ( array ( 'message ' => $ result ->get_error_message () ) );
313+ return ;
314+ }
315+
316+ // Still register the origin so the service knows where to
317+ // fetch content from — but don't fail if it errors (the host
318+ // may not have a full CDN config yet in proxy mode).
319+ $ this ->api_client ->register_origin ();
320+
321+ wp_send_json_success ( array (
322+ 'message ' => __ ( 'Connected! Proxy mode active — asset URLs will be rewritten. ' , 'rebelboost ' ),
323+ ) );
324+ return ;
325+ }
326+
327+ // Integration mode: register the origin first so the host has an
328+ // origin config before we attempt a purge-based connection test.
258329 $ origin_result = $ this ->api_client ->register_origin ();
259330 if ( true !== $ origin_result ) {
260331 wp_send_json_error ( array ( 'message ' => $ origin_result ->get_error_message () ) );
0 commit comments