66use Rollbar \Rollbar ;
77use Rollbar \RollbarJsHelper ;
88use Rollbar \WordPress \Admin \FlashMessages ;
9+ use Rollbar \WordPress \Admin \SettingsPage ;
910use Rollbar \WordPress \API \AdminAPI ;
1011use Rollbar \WordPress \Lib \AbstractSingleton ;
1112use Rollbar \WordPress \Settings \SettingType ;
@@ -68,14 +69,24 @@ protected function __construct()
6869 */
6970 protected function postInit (): void
7071 {
71- // Set up admin views and API.
72- AdminAPI::getInstance ();
7372 // Set up the telemetry listener.
7473 if ($ this ->getSetting ('enable_telemetry_listener ' )) {
7574 $ this ->listener = Listener::getInstance ();
7675 }
7776 }
7877
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+
7990 /**
8091 * Updates the plugin configuration
8192 *
@@ -115,21 +126,21 @@ public static function disabledAdmin(): bool
115126 * @return bool
116127 * @since 3.0.0
117128 */
118- public static function hideAdmin (): bool
129+ public static function userCanViewAdmin (): bool
119130 {
120131 if (self ::disabledAdmin ()) {
121132 return false ;
122133 }
123134
124135 /**
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 .
126137 *
127138 * This filter cannot override the `ROLLBAR_DISABLE_ADMIN` constant.
128139 *
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.
130141 * @since 3.0.0
131142 */
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 ;
133144 }
134145
135146 /**
@@ -192,6 +203,7 @@ public function settingsInstance(): Settings
192203 */
193204 private function hooks (): void
194205 {
206+ add_action ('init ' , $ this ->onInit (...));
195207 add_action ('wp_head ' , $ this ->initJsLogging (...));
196208 add_action ('admin_head ' , $ this ->initJsLogging (...));
197209 }
@@ -242,12 +254,14 @@ public static function buildIncludedErrno(int $cutoff): int
242254 * Sets up the Rollbar PHP error handler if PHP logging is enabled.
243255 * Handles configuration errors by displaying appropriate error messages.
244256 *
257+ * @param bool $ignoreEnabledSetting If true, the plugin will not check the 'php_logging_enabled' setting first.
258+ *
245259 * @return void
246260 */
247- public function initPhpLogging (): void
261+ public function initPhpLogging (bool $ ignoreEnabledSetting = false ): void
248262 {
249263 // Return if logging is not enabled
250- if (0 === $ this ->getSetting ('php_logging_enabled ' )) {
264+ if (! $ ignoreEnabledSetting && false === $ this ->getSetting ('php_logging_enabled ' )) {
251265 return ;
252266 }
253267
@@ -321,15 +335,15 @@ public function buildPHPConfig(): array
321335 public function initJsLogging (): void
322336 {
323337 // Return if logging is not enabled
324- if ($ this ->getSetting ('js_logging_enabled ' ) === 0 ) {
338+ if (false === $ this ->getSetting ('js_logging_enabled ' )) {
325339 return ;
326340 }
327341
328342 // Return if access token is not set
329- if ($ this ->getSetting ('client_side_access_token ' ) == '' ) {
343+ if (empty ( $ this ->getSetting ('client_side_access_token ' )) ) {
330344 FlashMessages::addMessage (
331345 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>. ' ,
333347 type: 'error ' ,
334348 );
335349 return ;
@@ -352,7 +366,7 @@ public function buildJsConfig(): array
352366 {
353367 $ config = [
354368 'accessToken ' => $ this ->getSetting ('client_side_access_token ' ),
355- 'captureUncaught ' => true ,
369+ 'captureUncaught ' => true ,
356370 'payload ' => [
357371 'environment ' => $ this ->getSetting ('environment ' ),
358372 ],
0 commit comments