Skip to content

Commit c8fa932

Browse files
Tsvetan StoychevTsvetan Stoychev
authored andcommitted
Add plugin development mode for HTTP beacons
1 parent a12a2ca commit c8fa932

9 files changed

Lines changed: 103 additions & 37 deletions

File tree

‎README.md‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ Default local administrator credentials are `admin` /
3737
port, database, site, or administrator values. `make down` preserves the
3838
site data; `make clean` resets it.
3939

40+
To use an HTTP beacon URL during local testing, enable **Development Mode**
41+
under **Basicrum > Developer Settings**. Keep it disabled on production sites
42+
so HTTP beacon URLs are automatically upgraded to HTTPS.
43+
4044
## Plugin Source
4145

4246
The WordPress plugin itself lives in `plugins/basicrum/`.

‎plugins/basicrum/languages/basicrum-bg_BG.po‎

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -148,66 +148,74 @@ msgstr ""
148148
msgid "Developer Settings"
149149
msgstr ""
150150

151-
#: src/Admin/Settings/Page.php:260
151+
#: src/Admin/Settings/Page.php:272
152152
msgid "Script Position"
153153
msgstr ""
154154

155-
#: src/Admin/Settings/Page.php:266
155+
#: src/Admin/Settings/Page.php:278
156156
msgid "Where to insert the monitoring script."
157157
msgstr ""
158158

159-
#: src/Admin/Settings/Page.php:268
159+
#: src/Admin/Settings/Page.php:280
160160
msgid "Header (wp_head)"
161161
msgstr ""
162162

163-
#: src/Admin/Settings/Page.php:269
163+
#: src/Admin/Settings/Page.php:281
164164
msgid "Footer (wp_footer)"
165165
msgstr ""
166166

167-
#: src/Admin/Settings/Page.php:276
167+
#: src/Admin/Settings/Page.php:288
168168
msgid "Use Unminified Loaders"
169169
msgstr ""
170170

171-
#: src/Admin/Settings/Page.php:282
171+
#: src/Admin/Settings/Page.php:294
172172
msgid "Load unminified JavaScript loaders for debugging."
173173
msgstr ""
174174

175-
#: src/Admin/Settings/Page.php:468
175+
#: src/Admin/Settings/Page.php:480
176176
msgid "~30 KB gzipped"
177177
msgstr ""
178178

179-
#: src/Admin/Settings/Page.php:482
179+
#: src/Admin/Settings/Page.php:494
180180
msgid "Consent JavaScript API"
181181
msgstr ""
182182

183-
#: src/Admin/Settings/Page.php:483
183+
#: src/Admin/Settings/Page.php:495
184184
msgid "When consent mode is enabled, Boomerang will not load until the user gives consent. Use the following JavaScript API in your consent banner or cookie notice:"
185185
msgstr ""
186186

187-
#: src/Admin/Settings/Page.php:484
187+
#: src/Admin/Settings/Page.php:496
188188
msgid "Call this to grant consent and start monitoring. Sets a BRUM_CONSENT cookie (1 year, Strict, Secure)."
189189
msgstr ""
190190

191-
#: src/Admin/Settings/Page.php:485
191+
#: src/Admin/Settings/Page.php:497
192192
msgid "Call this to revoke consent. Disables Boomerang and removes tracking cookies."
193193
msgstr ""
194194

195-
#: src/Admin/Settings/Page.php:486
195+
#: src/Admin/Settings/Page.php:498
196196
msgid "Example:"
197197
msgstr ""
198198

199-
#: src/Admin/Settings/Validate.php:127
199+
#: src/Admin/Settings/Validate.php:131
200200
msgid "Beacon URL was automatically upgraded to HTTPS."
201201
msgstr ""
202202

203-
#: src/Admin/Settings/Validate.php:136
203+
#: src/Admin/Settings/Validate.php:140
204204
msgid "Invalid Beacon URL. The default URL has been restored."
205205
msgstr ""
206206

207-
#: src/Admin/Settings/Validate.php:162
207+
#: src/Admin/Settings/Validate.php:166
208208
msgid "Invalid Brum Site ID. Copy it from the Basicrum backoffice and try again."
209209
msgstr "Невалиден Brum Site ID. Копирайте го от административния панел на Basicrum и опитайте отново."
210210

211-
#: src/Admin/Settings/Validate.php:189
211+
#: src/Admin/Settings/Validate.php:193
212212
msgid "Delay cannot exceed 30000 milliseconds. It has been capped at 30000."
213213
msgstr ""
214+
215+
#: src/Admin/Settings/Page.php:260
216+
msgid "Development Mode"
217+
msgstr ""
218+
219+
#: src/Admin/Settings/Page.php:266
220+
msgid "Allow HTTP beacon URLs for local testing. Do not enable this on production sites."
221+
msgstr ""

‎plugins/basicrum/languages/basicrum.pot‎

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -148,65 +148,73 @@ msgid "Developer Settings"
148148
msgstr ""
149149

150150
#: src/Admin/Settings/Page.php:260
151-
msgid "Script Position"
151+
msgid "Development Mode"
152152
msgstr ""
153153

154154
#: src/Admin/Settings/Page.php:266
155+
msgid "Allow HTTP beacon URLs for local testing. Do not enable this on production sites."
156+
msgstr ""
157+
158+
#: src/Admin/Settings/Page.php:272
159+
msgid "Script Position"
160+
msgstr ""
161+
162+
#: src/Admin/Settings/Page.php:278
155163
msgid "Where to insert the monitoring script."
156164
msgstr ""
157165

158-
#: src/Admin/Settings/Page.php:268
166+
#: src/Admin/Settings/Page.php:280
159167
msgid "Header (wp_head)"
160168
msgstr ""
161169

162-
#: src/Admin/Settings/Page.php:269
170+
#: src/Admin/Settings/Page.php:281
163171
msgid "Footer (wp_footer)"
164172
msgstr ""
165173

166-
#: src/Admin/Settings/Page.php:276
174+
#: src/Admin/Settings/Page.php:288
167175
msgid "Use Unminified Loaders"
168176
msgstr ""
169177

170-
#: src/Admin/Settings/Page.php:282
178+
#: src/Admin/Settings/Page.php:294
171179
msgid "Load unminified JavaScript loaders for debugging."
172180
msgstr ""
173181

174-
#: src/Admin/Settings/Page.php:468
182+
#: src/Admin/Settings/Page.php:480
175183
msgid "~30 KB gzipped"
176184
msgstr ""
177185

178-
#: src/Admin/Settings/Page.php:482
186+
#: src/Admin/Settings/Page.php:494
179187
msgid "Consent JavaScript API"
180188
msgstr ""
181189

182-
#: src/Admin/Settings/Page.php:483
190+
#: src/Admin/Settings/Page.php:495
183191
msgid "When consent mode is enabled, Boomerang will not load until the user gives consent. Use the following JavaScript API in your consent banner or cookie notice:"
184192
msgstr ""
185193

186-
#: src/Admin/Settings/Page.php:484
194+
#: src/Admin/Settings/Page.php:496
187195
msgid "Call this to grant consent and start monitoring. Sets a BRUM_CONSENT cookie (1 year, Strict, Secure)."
188196
msgstr ""
189197

190-
#: src/Admin/Settings/Page.php:485
198+
#: src/Admin/Settings/Page.php:497
191199
msgid "Call this to revoke consent. Disables Boomerang and removes tracking cookies."
192200
msgstr ""
193201

194-
#: src/Admin/Settings/Page.php:486
202+
#: src/Admin/Settings/Page.php:498
195203
msgid "Example:"
196204
msgstr ""
197205

198-
#: src/Admin/Settings/Validate.php:127
206+
#: src/Admin/Settings/Validate.php:131
199207
msgid "Beacon URL was automatically upgraded to HTTPS."
200208
msgstr ""
201209

202-
#: src/Admin/Settings/Validate.php:136
210+
#: src/Admin/Settings/Validate.php:140
203211
msgid "Invalid Beacon URL. The default URL has been restored."
204212
msgstr ""
205213

206-
#: src/Admin/Settings/Validate.php:162
214+
#: src/Admin/Settings/Validate.php:166
207215
msgid "Invalid Brum Site ID. Copy it from the Basicrum backoffice and try again."
208216
msgstr ""
209217

210-
#: src/Admin/Settings/Validate.php:189
218+
#: src/Admin/Settings/Validate.php:193
211219
msgid "Delay cannot exceed 30000 milliseconds. It has been capped at 30000."
212220
msgstr ""

‎plugins/basicrum/readme.txt‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,10 @@ Yes. Enable Consent Mode in the settings to require explicit user consent before
6363

6464
Yes. When WooCommerce is active, the plugin automatically detects shop, product, cart, checkout, and order confirmation page types.
6565

66+
= Can I use an HTTP beacon URL during local development? =
67+
68+
Yes. Enable Development Mode under Basicrum's Developer Settings to preserve HTTP beacon URLs. Keep it disabled on production sites so HTTP beacon URLs are automatically upgraded to HTTPS.
69+
6670
== Screenshots ==
6771

6872
1. Admin settings page - General settings with beacon URL and Brum Site ID.

‎plugins/basicrum/src/Admin/Settings/Page.php‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,18 @@ private function add_developer_section() {
255255
self::SLUG
256256
);
257257

258+
add_settings_field(
259+
'development_mode',
260+
esc_html__( 'Development Mode', 'basicrum' ),
261+
array( $this, 'render_checkbox_field' ),
262+
self::SLUG,
263+
'basicrum_section_developer',
264+
array(
265+
'id' => 'development_mode',
266+
'label' => __( 'Allow HTTP beacon URLs for local testing. Do not enable this on production sites.', 'basicrum' ),
267+
)
268+
);
269+
258270
add_settings_field(
259271
'script_position',
260272
esc_html__( 'Script Position', 'basicrum' ),

‎plugins/basicrum/src/Admin/Settings/Validate.php‎

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,11 @@ public function sanitize( $input ) {
5252
// Enabled (checkbox).
5353
$output['enabled'] = $this->sanitize_checkbox( $input, 'enabled' );
5454

55+
// Development mode (checkbox).
56+
$output['development_mode'] = $this->sanitize_checkbox( $input, 'development_mode' );
57+
5558
// Beacon URL.
56-
$output['beacon_url'] = $this->sanitize_beacon_url( $input, $defaults );
59+
$output['beacon_url'] = $this->sanitize_beacon_url( $input, $defaults, $output['development_mode'] );
5760

5861
// Brum Site ID.
5962
$output['brum_site_id'] = $this->sanitize_brum_site_id( $input );
@@ -106,19 +109,20 @@ private function sanitize_checkbox( $input, $key ) {
106109
/**
107110
* Sanitize and validate the beacon URL.
108111
*
109-
* @param array $input Raw input.
110-
* @param array $defaults Default values.
112+
* @param array $input Raw input.
113+
* @param array $defaults Default values.
114+
* @param string $development_mode Whether development mode is enabled.
111115
* @return string Sanitized URL.
112116
*/
113-
private function sanitize_beacon_url( $input, $defaults ) {
117+
private function sanitize_beacon_url( $input, $defaults, $development_mode ) {
114118
if ( empty( $input['beacon_url'] ) ) {
115119
return $defaults['beacon_url'];
116120
}
117121

118122
$url = esc_url_raw( $input['beacon_url'], array( 'https', 'http' ) );
119123

120-
// Enforce HTTPS - upgrade HTTP to HTTPS.
121-
if ( 0 === strpos( $url, 'http://' ) ) {
124+
// Enforce HTTPS unless development mode explicitly allows HTTP.
125+
if ( 0 === strpos( $url, 'http://' ) && '1' !== $development_mode ) {
122126
$url = 'https://' . substr( $url, 7 );
123127

124128
add_settings_error(

‎plugins/basicrum/src/Helpers.php‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ public static function get_settings() {
5656
public static function get_defaults() {
5757
return array(
5858
'enabled' => '0',
59+
'development_mode' => '0',
5960
'beacon_url' => '',
6061
'brum_site_id' => '',
6162
'track_admins' => '0',

‎plugins/basicrum/tests/unit/HelpersTest.php‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ public function test_get_defaults_has_all_keys() {
2424

2525
$expected_keys = array(
2626
'enabled',
27+
'development_mode',
2728
'beacon_url',
2829
'brum_site_id',
2930
'track_admins',

‎plugins/basicrum/tests/unit/ValidateTest.php‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,29 @@ public function test_valid_beacon_url_is_accepted() {
9090
$this->assertSame( 'https://example.com/beacon', $result['beacon_url'] );
9191
}
9292

93+
/**
94+
* Test HTTP beacon URLs are accepted when development mode is enabled.
95+
*/
96+
public function test_http_beacon_url_is_accepted_in_development_mode() {
97+
$input = array(
98+
'beacon_url' => 'http://127.0.0.1:3100/beacon/catcher',
99+
'development_mode' => '1',
100+
);
101+
$result = $this->validate->sanitize( $this->full_input( $input ) );
102+
$this->assertSame( 'http://127.0.0.1:3100/beacon/catcher', $result['beacon_url'] );
103+
$this->assertSame( '1', $result['development_mode'] );
104+
}
105+
106+
/**
107+
* Test HTTP beacon URLs are upgraded when development mode is disabled.
108+
*/
109+
public function test_http_beacon_url_is_upgraded_without_development_mode() {
110+
$input = array( 'beacon_url' => 'http://example.com/beacon' );
111+
$result = $this->validate->sanitize( $this->full_input( $input ) );
112+
$this->assertSame( 'https://example.com/beacon', $result['beacon_url'] );
113+
$this->assertSame( '0', $result['development_mode'] );
114+
}
115+
93116
/**
94117
* Test delay is capped at 30000ms.
95118
*/
@@ -162,6 +185,7 @@ public function test_checkbox_disabled() {
162185
private function full_input( $overrides = array() ) {
163186
$defaults = array(
164187
'enabled' => '0',
188+
'development_mode' => '0',
165189
'beacon_url' => '',
166190
'brum_site_id' => '',
167191
'consent_enabled' => '0',

0 commit comments

Comments
 (0)