- This topic has 9 replies, 3 voices, and was last updated 7 years, 5 months ago by
Steve.
-
AuthorPosts
-
-
September 4, 2014 at 1:37 pm #2368
jmayhakMemberI have created a new sub_menu page and set the capability to a custom permission “manage_scda”. I can view the page, but when I click “Save Settings” I am shown “Cheatin’ huh?” If I grant the user the “manage_options” permission, I can save. I do not want this user to have that permission.
add_filter( ‘piklist_admin_pages’, ‘scag_theme_export_farmers_markets’ );
function scag_theme_export_farmers_markets( $pages ) {
$pages[] = array(
‘page_title’ => __( ‘Export Farmers Markets to CSV’ ),
‘menu_title’ => __( ‘Export to CSV’),
‘capability’ => ‘manage_scda’,
‘menu_slug’ => ‘export-fm’,
‘setting’ => ‘scda_export_farmers_markets’,
‘single_line’ => true,
‘save_text’ => ‘Export to CSV’,
‘sub_menu’ => ‘edit.php?post_type=farmers_market’,
);return $pages;
}I do not think the “manage_options” permission is required, so I’m confused. Have I set up this new page incorrectly?
-
September 4, 2014 at 2:18 pm #2369
JasonKeymasterThe “capability” element is simply a way to limit what level of capabilities the user has to have in order to save. You can use any of the capabilities listed here: http://codex.wordpress.org/Roles_and_Capabilities
If you don’t want “manage_options” (administrator capability) level necessary, then select a capability from a lower role. For example, “edit_other_posts” would require them to be at least an Editor.
Hope this helps!
-
September 4, 2014 at 2:24 pm #2370
jmayhakMemberRight, so the current capability of “manage_scda” is a permission the user has but is still unable to save. If I add the permission “manage_options” to the user, said user can now save without altering the capability setting in Piklist.
If I change the capability to “read”, the user can still not save.
It seems that “manage_options” is a required permission for the user to have to save. The capability setting does not affect whether or not a permission is checked, it seems.
-
September 4, 2014 at 2:32 pm #2371
JasonKeymasterAh, I see what you’re saying. Well.. that does make sense. The capability provided simply determines whether or not the capability necessary for the page to show up. But it would seem like a WordPress limit that only users with “manage_options” can actually.. manage options. 🙂
I assume Piklist is only passing that parameter along since it’s there in add_menu_page. In that context, though, you might make a page for displaying data, etc., so you’re not always saving settings. I guess the benefit here is that at least users without said capability can at least view the settings.
-
September 4, 2014 at 2:51 pm #2372
SteveKeymaster@jmayhak– Based on this codex page, there is an additional filter needed when changing the capability which Piklist does not have. We will add this in a future version.
Since Piklist does everything the WordPress way, you can just use the instructions at the codex. Add this to your plugin file, replacing ‘menu_slug’ with the slug you set when you registered your page with Piklist.
function my_page_capability($capability) { return 'manage_scda'; } add_filter('option_page_capability_menu_slug', 'my_page_capability');Let us know if that worked.
-
September 4, 2014 at 3:16 pm #2373
JasonKeymasterWow, that’s one of those annoying, undocumented hooks: http://wphooks.info/filters/option_page_capability_%7B$option_page%7D/
@Steve, it’d probably be a publicly spirited move to include information about this hook in the settings doc.
-
September 4, 2014 at 3:46 pm #2374
JasonKeymasterI just tested this.. and the hook name {option_page} is misleading. Don’t use the menu slug, as that doesn’t work. Use the setting. The following works:
add_filter('piklist_post_types', 'add_program_post_type'); function add_program_post_type( $post_types ) { $post_types[PROGRAM_TYPE] = array( 'labels' => piklist('post_type_labels', 'Program'), 'title' => __('Title'), 'supports' => array( 'title' ), 'public' => true, 'has_archive' => true, 'rewrite' => array( 'slug' => 'does' ), 'capability_type' => 'post', 'hide_meta_box' => array( 'slug' ), 'post_states' => false ); return $post_types; } add_filter('piklist_admin_pages', 'add_program_admin_pages'); function add_program_admin_pages($pages) { $pages[] = array( 'page_title' => __('Archive Settings'), 'menu_title' => __('Archive Settings'), 'sub_menu' => 'edit.php?post_type=' . PROGRAM_TYPE, 'capability' => 'edit_others_posts', 'menu_slug' => 'program-archive-settings', 'setting' => 'program-settings' ); return $pages; } add_filter('option_page_capability_program-settings', 'set_program_archive_capability'); function set_program_archive_capability() { return 'edit_others_posts'; }Notice that I’m using “program-settings” in the hook, not “program-archive-settings”.
-
September 4, 2014 at 4:00 pm #2375
SteveKeymaster@jason– Thanks for flushing this out. Our docs have been updated >
-
September 5, 2014 at 9:05 am #2377
jmayhakMemberGot it working. Thanks for the help!
-
September 5, 2014 at 10:27 am #2378
SteveKeymasterAwesome. Closing ticket.
-
-
AuthorPosts
- The topic ‘Do admin page setting changes require manage_options permission?’ is closed to new replies.