I’m developing a plugin with an options page using the Settings API.
I’d like to have one options array stored for my plugin, but on the settings page, I’d only like some of the settings to be visible to admin users, but the full list of settings to be available to the super admin.
Is this possible?
Test the current userâs role with
current_user_can( 'administrator' )
:Make sure to use the same check when you save the options. Otherwise your regular users might delete the values.
Alternately, you could incorporate
current_user_can()
into theadd_settings_field()
callback for each admin-only option:Using this method, you shouldn’t have to mess with your actual settings page markup at all.
If your sanitization callback is written properly, such that you check for data to be set, and array_merge() validated/sanitized values with existing option values, you shouldn’t have to worry about any admin-only settings being deleted or improperly overwritten.