pods-framework / pods

The Pods Framework is a Content Development Framework for WordPress - It lets you create and extend content types that can be used for any project. Add fields of various types we've built in, or add your own with custom inputs, you have total control.
https://pods.io/
GNU General Public License v2.0
1.06k stars 265 forks source link

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

Open sc0ttkclark opened 6 months ago

sc0ttkclark commented 6 months ago

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:

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

phkoon commented 1 month ago

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.