6
6
use Rollbar \Rollbar ;
7
7
use Rollbar \RollbarJsHelper ;
8
8
use Rollbar \WordPress \Admin \FlashMessages ;
9
+ use Rollbar \WordPress \Admin \SettingsPage ;
9
10
use Rollbar \WordPress \API \AdminAPI ;
10
11
use Rollbar \WordPress \Lib \AbstractSingleton ;
11
12
use Rollbar \WordPress \Settings \SettingType ;
@@ -68,14 +69,24 @@ protected function __construct()
68
69
*/
69
70
protected function postInit (): void
70
71
{
71
- // Set up admin views and API.
72
- AdminAPI::getInstance ();
73
72
// Set up the telemetry listener.
74
73
if ($ this ->getSetting ('enable_telemetry_listener ' )) {
75
74
$ this ->listener = Listener::getInstance ();
76
75
}
77
76
}
78
77
78
+ /**
79
+ * Handles the 'init' action hook.
80
+ *
81
+ * @return void
82
+ */
83
+ public function onInit (): void
84
+ {
85
+ // Set up admin views and API.
86
+ SettingsPage::getInstance ();
87
+ AdminAPI::getInstance ();
88
+ }
89
+
79
90
/**
80
91
* Updates the plugin configuration
81
92
*
@@ -115,21 +126,21 @@ public static function disabledAdmin(): bool
115
126
* @return bool
116
127
* @since 3.0.0
117
128
*/
118
- public static function hideAdmin (): bool
129
+ public static function userCanViewAdmin (): bool
119
130
{
120
131
if (self ::disabledAdmin ()) {
121
132
return false ;
122
133
}
123
134
124
135
/**
125
- * Filter to disable the admin settings page of the plugin.
136
+ * Filter to enable / disable the admin settings page of the plugin for the current user .
126
137
*
127
138
* This filter cannot override the `ROLLBAR_DISABLE_ADMIN` constant.
128
139
*
129
- * @param bool $disable `true` to disable the admin settings page, `false` to enable it.
140
+ * @param bool $allow `true` to enable the admin settings page, `false` to disable it.
130
141
* @since 3.0.0
131
142
*/
132
- return apply_filters ('rollbar_disable_admin ' , ! current_user_can ('manage_options ' )) === true ;
143
+ return apply_filters ('rollbar_user_can_view_admin ' , current_user_can ('manage_options ' )) === true ;
133
144
}
134
145
135
146
/**
@@ -192,6 +203,7 @@ public function settingsInstance(): Settings
192
203
*/
193
204
private function hooks (): void
194
205
{
206
+ add_action ('init ' , $ this ->onInit (...));
195
207
add_action ('wp_head ' , $ this ->initJsLogging (...));
196
208
add_action ('admin_head ' , $ this ->initJsLogging (...));
197
209
}
@@ -242,12 +254,14 @@ public static function buildIncludedErrno(int $cutoff): int
242
254
* Sets up the Rollbar PHP error handler if PHP logging is enabled.
243
255
* Handles configuration errors by displaying appropriate error messages.
244
256
*
257
+ * @param bool $ignoreEnabledSetting If true, the plugin will not check the 'php_logging_enabled' setting first.
258
+ *
245
259
* @return void
246
260
*/
247
- public function initPhpLogging (): void
261
+ public function initPhpLogging (bool $ ignoreEnabledSetting = false ): void
248
262
{
249
263
// Return if logging is not enabled
250
- if (0 === $ this ->getSetting ('php_logging_enabled ' )) {
264
+ if (! $ ignoreEnabledSetting && false === $ this ->getSetting ('php_logging_enabled ' )) {
251
265
return ;
252
266
}
253
267
@@ -321,15 +335,15 @@ public function buildPHPConfig(): array
321
335
public function initJsLogging (): void
322
336
{
323
337
// Return if logging is not enabled
324
- if ($ this ->getSetting ('js_logging_enabled ' ) === 0 ) {
338
+ if (false === $ this ->getSetting ('js_logging_enabled ' )) {
325
339
return ;
326
340
}
327
341
328
342
// Return if access token is not set
329
- if ($ this ->getSetting ('client_side_access_token ' ) == '' ) {
343
+ if (empty ( $ this ->getSetting ('client_side_access_token ' )) ) {
330
344
FlashMessages::addMessage (
331
345
message: 'Rollbar is misconfigured. Please, fix your configuration here: <a href=" '
332
- . admin_url ('/options-general.php?page=rollbar_wp ' ) . '"> ' ,
346
+ . admin_url ('/options-general.php?page=rollbar_wp ' ) . '">Rollbar Settings</a>. ' ,
333
347
type: 'error ' ,
334
348
);
335
349
return ;
@@ -352,7 +366,7 @@ public function buildJsConfig(): array
352
366
{
353
367
$ config = [
354
368
'accessToken ' => $ this ->getSetting ('client_side_access_token ' ),
355
- 'captureUncaught ' => true ,
369
+ 'captureUncaught ' => true ,
356
370
'payload ' => [
357
371
'environment ' => $ this ->getSetting ('environment ' ),
358
372
],
0 commit comments