How to display some settings for super admin user only using Settings API

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?

2 Answers
2

Test the current user’s role with current_user_can( 'administrator' ):

if ( current_user_can( 'administrator' ) )
{
    add_settings_field( /* arguments */ );
    // or
    add_settings_section( /* arguments */ );
}

Make sure to use the same check when you save the options. Otherwise your regular users might delete the values.

Leave a Comment