The option_page_capability_{$option_page} WordPress PHP filter allows you to modify the required capability for a specific options page when using the Settings API.
Usage
add_filter('option_page_capability_my_option_page', 'change_my_option_page_capability'); function change_my_option_page_capability($capability) { // your custom code here return 'my_custom_capability'; }
Parameters
$capability
: (string) The capability used for the page, which ismanage_options
by default.
More information
See WordPress Developer Resources: option_page_capability_{$option_page}
Examples
Change capability for a custom settings page
This example demonstrates how to change the required capability for the my_custom_settings_page
.
add_filter('option_page_capability_my_custom_settings_page', 'change_custom_settings_page_capability'); function change_custom_settings_page_capability($capability) { return 'edit_posts'; }
Require ‘publish_posts’ capability for a settings page
Change the required capability to ‘publish_posts’ for the my_publish_settings_page
.
add_filter('option_page_capability_my_publish_settings_page', 'change_publish_settings_page_capability'); function change_publish_settings_page_capability($capability) { return 'publish_posts'; }
Allow editors to access a settings page
Allow users with the ‘edit_pages’ capability to access the my_editor_settings_page
.
add_filter('option_page_capability_my_editor_settings_page', 'change_editor_settings_page_capability'); function change_editor_settings_page_capability($capability) { return 'edit_pages'; }
Set custom capability for a plugin settings page
Set a custom capability ‘manage_my_plugin’ for the my_plugin_settings_page
.
add_filter('option_page_capability_my_plugin_settings_page', 'change_my_plugin_settings_page_capability'); function change_my_plugin_settings_page_capability($capability) { return 'manage_my_plugin'; }
Use a custom role for a theme settings page
Change the required capability to a custom role’s capability for the my_theme_settings_page
.
add_filter('option_page_capability_my_theme_settings_page', 'change_my_theme_settings_page_capability'); function change_my_theme_settings_page_capability($capability) { return 'manage_my_theme'; }