diff --git a/admin/class-twp-admin.php b/admin/class-twp-admin.php index e716ab9..1fc5fb7 100644 --- a/admin/class-twp-admin.php +++ b/admin/class-twp-admin.php @@ -31,6 +31,14 @@ class TWP_Admin { return; } + // Determine first available page for agents + $first_page = 'twilio-wp-browser-phone'; // Default to browser phone + if (current_user_can('twp_access_voicemails')) $first_page = 'twilio-wp-voicemails'; + elseif (current_user_can('twp_access_call_log')) $first_page = 'twilio-wp-call-logs'; + elseif (current_user_can('twp_access_agent_queue')) $first_page = 'twilio-wp-agent-queue'; + elseif (current_user_can('twp_access_sms_inbox')) $first_page = 'twilio-wp-sms-inbox'; + elseif (current_user_can('twp_access_browser_phone')) $first_page = 'twilio-wp-browser-phone'; + // Main menu - show dashboard for admins, redirect to first available page for agents if (current_user_can('manage_options')) { add_menu_page( @@ -52,14 +60,6 @@ class TWP_Admin { array($this, 'display_plugin_dashboard') ); } else { - // For agents, determine first available page - $first_page = 'twilio-wp-browser-phone'; // Default to browser phone - if (current_user_can('twp_access_voicemails')) $first_page = 'twilio-wp-voicemails'; - elseif (current_user_can('twp_access_call_log')) $first_page = 'twilio-wp-call-logs'; - elseif (current_user_can('twp_access_agent_queue')) $first_page = 'twilio-wp-agent-queue'; - elseif (current_user_can('twp_access_sms_inbox')) $first_page = 'twilio-wp-sms-inbox'; - elseif (current_user_can('twp_access_browser_phone')) $first_page = 'twilio-wp-browser-phone'; - add_menu_page( 'Twilio Phone', 'Twilio Phone', @@ -129,7 +129,7 @@ class TWP_Admin { } // Agent-accessible pages - $menu_parent = current_user_can('manage_options') ? 'twilio-wp-plugin' : null; + $menu_parent = current_user_can('manage_options') ? 'twilio-wp-plugin' : $first_page; if (current_user_can('manage_options') || current_user_can('twp_access_voicemails')) { add_submenu_page( @@ -2999,7 +2999,7 @@ class TWP_Admin { public function ajax_get_phone_numbers() { check_ajax_referer('twp_ajax_nonce', 'nonce'); - if (!current_user_can('manage_options')) { + if (!current_user_can('manage_options') && !current_user_can('twp_access_phone_numbers')) { wp_die('Unauthorized'); } @@ -4026,7 +4026,7 @@ class TWP_Admin { public function ajax_generate_capability_token() { check_ajax_referer('twp_ajax_nonce', 'nonce'); - if (!current_user_can('manage_options')) { + if (!current_user_can('manage_options') && !current_user_can('twp_access_browser_phone')) { wp_send_json_error('Insufficient permissions'); } @@ -5246,7 +5246,7 @@ class TWP_Admin { - +
To enable mode switching, update your phone number webhook to:
diff --git a/includes/class-twp-activator.php b/includes/class-twp-activator.php index 8d78a98..a810915 100644 --- a/includes/class-twp-activator.php +++ b/includes/class-twp-activator.php @@ -399,6 +399,7 @@ class TWP_Activator { 'twp_access_outbound_calls' => true, 'twp_access_sms_inbox' => true, 'twp_access_browser_phone' => true, + 'twp_access_phone_numbers' => true, )); } } \ No newline at end of file diff --git a/includes/class-twp-core.php b/includes/class-twp-core.php index 47a1096..a87d807 100644 --- a/includes/class-twp-core.php +++ b/includes/class-twp-core.php @@ -67,8 +67,9 @@ class TWP_Core { * Ensure custom user roles exist */ private function ensure_user_roles() { - // Check if the phone_agent role exists - if (!get_role('phone_agent')) { + $role = get_role('phone_agent'); + + if (!$role) { // Create the Phone Agent role with limited capabilities add_role('phone_agent', 'Phone Agent', array( // Basic WordPress capabilities @@ -84,7 +85,13 @@ class TWP_Core { 'twp_access_outbound_calls' => true, 'twp_access_sms_inbox' => true, 'twp_access_browser_phone' => true, + 'twp_access_phone_numbers' => true, )); + } else { + // Update existing role with any missing capabilities + if (!$role->has_cap('twp_access_phone_numbers')) { + $role->add_cap('twp_access_phone_numbers'); + } } }