Skip to content

Commit 98ea208

Browse files
committed
Only show admin pages when configured
Wrap additional WorkOS admin submenu pages and tabs in an is_configured() check so Roles, Usage, Learning Mode, and Diagnostics are only visible after API keys/client ID are set. Add a private fetch_workos_roles_error() helper to surface role-fetch errors in the UI for debugging and show the error message when roles cannot be retrieved. Bump plugin version to 1.1.4 (WORKOS_WP_VERSION and header). Minor markup/indent changes around the settings tabs.
1 parent d20b584 commit 98ea208

2 files changed

Lines changed: 65 additions & 39 deletions

File tree

includes/Plugin.php

Lines changed: 63 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -330,41 +330,44 @@ public function register_settings_page(): void {
330330
[$this, 'render_api_config_page']
331331
);
332332

333-
add_submenu_page(
334-
'workos-settings',
335-
__('Roles', 'workos-for-wordpress'),
336-
__('Roles', 'workos-for-wordpress'),
337-
'manage_options',
338-
'workos-role-mapping',
339-
[$this, 'render_role_mapping_page']
340-
);
333+
// Only show additional pages when API Key and Client ID are configured.
334+
if ($this->is_configured()) {
335+
add_submenu_page(
336+
'workos-settings',
337+
__('Roles', 'workos-for-wordpress'),
338+
__('Roles', 'workos-for-wordpress'),
339+
'manage_options',
340+
'workos-role-mapping',
341+
[$this, 'render_role_mapping_page']
342+
);
341343

342-
add_submenu_page(
343-
'workos-settings',
344-
__('Usage', 'workos-for-wordpress'),
345-
__('Usage', 'workos-for-wordpress'),
346-
'manage_options',
347-
'workos-usage',
348-
[$this, 'render_usage_page']
349-
);
344+
add_submenu_page(
345+
'workos-settings',
346+
__('Usage', 'workos-for-wordpress'),
347+
__('Usage', 'workos-for-wordpress'),
348+
'manage_options',
349+
'workos-usage',
350+
[$this, 'render_usage_page']
351+
);
350352

351-
add_submenu_page(
352-
'workos-settings',
353-
__('Learning Mode', 'workos-for-wordpress'),
354-
__('Learning Mode', 'workos-for-wordpress'),
355-
'manage_options',
356-
'workos-learning-mode',
357-
[$this, 'render_learning_mode_page']
358-
);
353+
add_submenu_page(
354+
'workos-settings',
355+
__('Learning Mode', 'workos-for-wordpress'),
356+
__('Learning Mode', 'workos-for-wordpress'),
357+
'manage_options',
358+
'workos-learning-mode',
359+
[$this, 'render_learning_mode_page']
360+
);
359361

360-
add_submenu_page(
361-
'workos-settings',
362-
__('Diagnostics', 'workos-for-wordpress'),
363-
__('Diagnostics', 'workos-for-wordpress'),
364-
'manage_options',
365-
'workos-diagnostics',
366-
[$this, 'render_diagnostics_page']
367-
);
362+
add_submenu_page(
363+
'workos-settings',
364+
__('Diagnostics', 'workos-for-wordpress'),
365+
__('Diagnostics', 'workos-for-wordpress'),
366+
'manage_options',
367+
'workos-diagnostics',
368+
[$this, 'render_diagnostics_page']
369+
);
370+
}
368371
}
369372

370373
public function register_settings(): void {
@@ -426,12 +429,15 @@ private function render_global_header(string $current_slug): void {
426429
$logo_url = plugins_url('WorkOS-branding/SVG/WorkOS_Lockup_Full_Color.svg', WORKOS_WP_PLUGIN_FILE);
427430

428431
$tabs = [
429-
'workos-settings' => __('Welcome', 'workos-for-wordpress'),
430-
'workos-role-mapping' => __('Roles', 'workos-for-wordpress'),
431-
'workos-learning-mode' => __('Learning Mode', 'workos-for-wordpress'),
432-
'workos-usage' => __('Usage', 'workos-for-wordpress'),
433-
'workos-diagnostics' => __('Diagnostics', 'workos-for-wordpress'),
432+
'workos-settings' => __('Welcome', 'workos-for-wordpress'),
434433
];
434+
435+
if ($this->is_configured()) {
436+
$tabs['workos-role-mapping'] = __('Roles', 'workos-for-wordpress');
437+
$tabs['workos-learning-mode'] = __('Learning Mode', 'workos-for-wordpress');
438+
$tabs['workos-usage'] = __('Usage', 'workos-for-wordpress');
439+
$tabs['workos-diagnostics'] = __('Diagnostics', 'workos-for-wordpress');
440+
}
435441
?>
436442
<div class="workos-global-header">
437443
<div class="workos-global-header-left">
@@ -722,6 +728,13 @@ public function render_role_mapping_page(): void {
722728
<?php if ($this->is_configured() && !empty($org_id) && empty($workos_roles)): ?>
723729
<div class="workos-alert workos-alert-error">
724730
<?php esc_html_e('Could not fetch roles for this organization. Verify the organization is correct and your API key has access.', 'workos-for-wordpress'); ?>
731+
<?php
732+
// Show the actual error for debugging.
733+
$role_error = $this->fetch_workos_roles_error($org_id);
734+
if ($role_error) {
735+
echo '<br><small>' . esc_html($role_error) . '</small>';
736+
}
737+
?>
725738
</div>
726739
<?php endif; ?>
727740

@@ -1856,6 +1869,19 @@ private function fetch_workos_roles(): array {
18561869
}
18571870
}
18581871

1872+
/**
1873+
* Attempt to fetch roles and return the error message if it fails.
1874+
*/
1875+
private function fetch_workos_roles_error(string $org_id): ?string {
1876+
try {
1877+
$orgs = new \WorkOS\Organizations();
1878+
$orgs->listOrganizationRoles($org_id);
1879+
return null;
1880+
} catch (\Exception $e) {
1881+
return $e->getMessage();
1882+
}
1883+
}
1884+
18591885
public function sanitize_role_map($input): array {
18601886
if (!is_array($input)) {
18611887
return [];

workos-for-wordpress.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* Plugin Name: WorkOS for WordPress
44
* Plugin URI: https://github.com/AlwaysCuriousCo/workos-for-wordpress
55
* Description: Integrate WorkOS authentication and user management into WordPress.
6-
* Version: 1.1.3
6+
* Version: 1.1.4
77
* Author: Always Curious
88
* Author URI: https://alwayscurious.co
99
* License: GPL-3.0-or-later
@@ -15,7 +15,7 @@
1515

1616
defined('ABSPATH') || exit;
1717

18-
define('WORKOS_WP_VERSION', '1.1.3');
18+
define('WORKOS_WP_VERSION', '1.1.4');
1919
define('WORKOS_WP_PLUGIN_FILE', __FILE__);
2020
define('WORKOS_WP_PLUGIN_DIR', plugin_dir_path(__FILE__));
2121
define('WORKOS_WP_PLUGIN_URL', plugin_dir_url(__FILE__));

0 commit comments

Comments
 (0)