Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom Settings Pages should support specifying a capability for access #7245

Open
2 tasks
sc0ttkclark opened this issue Jan 2, 2024 · 1 comment
Open
2 tasks
Labels
Keyword: Good First Issue New contributors are encouraged to try helping on this Status: Help Wanted We have not prioritized this yet, but you can help make it happen to speed it up Type: Enhancement Enhancements to features that already exist, but are not major additions
Milestone

Comments

@sc0ttkclark
Copy link
Member

sc0ttkclark commented Jan 2, 2024

Problem to Solve

Right now, you must have access as a Pods admin (caps: pods, pods_content, or pods_edit_{pod_name}).

It would be great to override what capability check(s) are used for the Custom Settings Pages specifically.

Proposed Solution

Add a new option to the Pod edit screen for Settings pods so that you can choose from these capabilities:

  • Default: Anyone with access to pods, pods_content, or pods_edit_{pod_name} capabilities
  • Custom
  • Specify the custom capability to reference for access

Possible Workaround

add_filter( 'pods_is_admin', 'my_custom_override_for_custom_settings_page_access', 10, 3 );

function my_custom_override_for_custom_settings_page_access( $has_access, $capabilities, $capability ) {
	$my_pod_name = 'my_pod_name_here';
	$my_custom_capability = 'my_custom_capability_here';

	if (
		in_array( 'pods_edit_' . $my_pod_name, $capabilities, true )
		&& current_user_can( $my_custom_capability )
	) {
		return true;
	}

	return $has_access;
}

Todos

  • Update access check in PodsAdmin::admin_menu()
    if ( ! pods_is_admin( array( 'pods', 'pods_content', 'pods_edit_' . $pod['name'] ) ) ) {
  • Add two fields to \Pods\Admin\Config\Pod::get_fields() for Settings pods: capability_type and capability_type_custom
@sc0ttkclark sc0ttkclark added the Type: Enhancement Enhancements to features that already exist, but are not major additions label Jan 2, 2024
@sc0ttkclark sc0ttkclark added this to the Pods 3.2 milestone Jan 2, 2024
@sc0ttkclark sc0ttkclark added Status: Help Wanted We have not prioritized this yet, but you can help make it happen to speed it up Keyword: Good First Issue New contributors are encouraged to try helping on this labels Jan 2, 2024
@phkoon
Copy link

phkoon commented May 10, 2024

Much needed.

In my case, I've created a custom settings page with some image fields that serve globally throughout the site and the site manager can't access it due to not having the "manage_options" capability enabled, only an admin user has access to it, and it breaks the purpose for the settings page I've created, and I see no other mean other than creating individual custom fields for every page in which those image fields are needed to be shown.

I've tried giving the "manage_options" capability to the site manager role, but in addition to it not being safe, it didn't work also, the custom settings page only shows up in the menu for admin roles.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Keyword: Good First Issue New contributors are encouraged to try helping on this Status: Help Wanted We have not prioritized this yet, but you can help make it happen to speed it up Type: Enhancement Enhancements to features that already exist, but are not major additions
Projects
None yet
Development

No branches or pull requests

2 participants