From 04a54c2ecbe82031c0484ff9714e6f3110372e15 Mon Sep 17 00:00:00 2001 From: Faisal Ahammad Date: Sun, 26 Jul 2026 10:34:51 +0600 Subject: [PATCH] fix(admin): add custom capability option for settings pages Settings pods let site owners gate the admin menu on any capability. Defaults keep pods/pods_content/pods_edit_{name} so existing admins do not lose access. New option is opt-in per pod, no migration. Fixes #7245 --- classes/PodsAdmin.php | 22 +++++++++++++++++++++- src/Pods/Admin/Config/Pod.php | 19 +++++++++++++++++++ 2 files changed, 40 insertions(+), 1 deletion(-) diff --git a/classes/PodsAdmin.php b/classes/PodsAdmin.php index 8956d3b0c4..d9ab7cb20d 100644 --- a/classes/PodsAdmin.php +++ b/classes/PodsAdmin.php @@ -482,7 +482,20 @@ public function admin_menu() { if ( ! empty( $settings ) ) { foreach ( (array) $settings as $pod ) { - if ( ! pods_is_admin( [ 'pods', 'pods_content', 'pods_edit_' . $pod['name'] ] ) ) { + $settings_capabilities = [ + 'pods', + 'pods_content', + 'pods_edit_' . $pod['name'], + ]; + + if ( + 'custom' === pods_v( 'capability_type', $pod['options'] ) + && ! empty( $pod['options']['capability_type_custom'] ) + ) { + $settings_capabilities[] = (string) $pod['options']['capability_type_custom']; + } + + if ( ! pods_is_admin( $settings_capabilities ) ) { continue; } @@ -3990,6 +4003,13 @@ public function admin_capabilities( $capabilities ) { foreach ( $pods as $pod ) { if ( 'settings' === $pod['type'] ) { $capabilities[] = 'pods_edit_' . $pod['name']; + + if ( + 'custom' === pods_v( 'capability_type', $pod['options'] ) + && ! empty( $pod['options']['capability_type_custom'] ) + ) { + $capabilities[] = (string) $pod['options']['capability_type_custom']; + } } elseif ( 'post_type' === $pod['type'] ) { $capability_type = pods_v_sanitized( 'capability_type_custom', $pod['options'], pods_v( 'name', $pod ) ); diff --git a/src/Pods/Admin/Config/Pod.php b/src/Pods/Admin/Config/Pod.php index 193e013231..fc354dfc37 100644 --- a/src/Pods/Admin/Config/Pod.php +++ b/src/Pods/Admin/Config/Pod.php @@ -1452,6 +1452,25 @@ public function get_fields( \Pods\Whatsit\Pod $pod, array $tabs ) { 'default' => '', 'depends-on' => [ 'menu_location' => 'top' ], ], + 'capability_type' => [ + 'label' => __( 'User Capability', 'pods' ), + 'help' => __( 'Controls which capability gates access to this Settings Page in the admin menu.', 'pods' ), + 'type' => 'pick', + 'default' => 'default', + 'data' => [ + 'default' => __( 'Default (Pods admin)', 'pods' ), + 'custom' => __( 'Custom Capability', 'pods' ), + ], + 'pick_format_single' => 'dropdown', + 'dependency' => true, + ], + 'capability_type_custom' => [ + 'label' => __( 'Custom User Capability', 'pods' ), + 'help' => __( 'Enter the exact capability name required to access this Settings Page (for example: manage_options).', 'pods' ), + 'type' => 'text', + 'text_placeholder' => 'manage_options', + 'depends-on' => [ 'capability_type' => 'custom' ], + ], ]; } elseif ( 'pod' === $pod_type ) { $actions_enabled = [