• Resolved Sam Brodie

    (@sammybeats)


    I’m having trouble getting menu fields to display to certain custom user roles. The permission that the user needs is permission_x. When I add ‘capability’ => ‘permission_x’ to the addSubMenuItem() array, the page becomes available to this custom role with permission_x. However, the page only has a title and a submit button – there are no fields. I tried adding ‘capability’ => ‘permission_x’ to the arrays in addSettingsFields() but this didn’t do the trick. How can I get these to show up?

    Here’s the full array called in the load_options_page() function

    $this->addSettingFields(
    array (
    ‘field_id’ => ‘users’,
    ‘type’ => ‘checkbox’,
    ‘title’ => __( ‘Choices’, ‘plugin’ ),
    ‘description’ => __( ‘Choose one.’, ‘plugin’ ),
    ‘capability’ => ‘permission_x’,
    ‘label’ => array(
    ‘one’ => ‘One’
    ‘two’ => ‘Two’
    )
    ),
    );

    Thanks.

    https://www.ads-software.com/plugins/admin-page-framework/

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author miunosoft

    (@miunosoft)

    Maybe the form section has a higher capability level.

    Do you have a form section or use the default section (not using sections)? If you set a section, set a capability to the section definition array passed to the addSettingSections method.

    Thread Starter Sam Brodie

    (@sammybeats)

    I was not using sections. I tried it with a section and it still doesn’t work. Note that I can access these options with an admin user. Here is the code I put for the section:

    $this->addSettingSections(
    ‘options_page’,
    array(
    ‘section_id’ => ‘main’,
    ‘title’ => ”,
    ‘description’ => ”,
    ‘capability’ => ‘capability_x’
    )
    );

    And modified the fields:

    $this->addSettingFields(
    ‘main’,
    array (
    ‘field_id’ => ‘users’,
    ‘type’ => ‘checkbox’,
    ‘title’ => __( ‘Choices’, ‘plugin’ ),
    ‘description’ => __( ‘Choose one.’, ‘plugin’ ),
    ‘capability’ => ‘permission_x’,
    ‘label’ => array(
    ‘one’ => ‘One’
    ‘two’ => ‘Two’
    )
    ),
    );

    It seems that sections and fields just use the manage_options permission in the abstract class AdminPageFramework extends AdminPageFramework_Controller class definition because modifying the default value of $sCapability there does the trick.

    Plugin Author miunosoft

    (@miunosoft)

    I’ve posted a test plugin that demonstrates how you can set up capabilities for form fields on Gist.

    https://gist.github.com/michaeluno/edb2706f10ca50caf9eb

    You may examine that. In my environment, I could not confirm any issue.

    On the other hand, indeed when a form section is not set, the default capability value of the section is manage_options thus the capability values set individually in fields do not have effect. This might not be intuitive and this behavior can be changed. If you like, please post an issue on the repository issue tracker.

    Thread Starter Sam Brodie

    (@sammybeats)

    Got it to work – not sure what I was doing wrong before but your code works so thank you for posting. I also posted an issue on the tracker recommending more intuitive capability inheritance. Thanks again for a nicely made Admin Framework and great support.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Permissions for Menu Page and Field’ is closed to new replies.