Skip to content

Instantly share code, notes, and snippets.

@hegemanjr
Last active October 5, 2021 23:24
Show Gist options
  • Save hegemanjr/b58a6d54bb94121ae36a84f63dac4ee6 to your computer and use it in GitHub Desktop.
Save hegemanjr/b58a6d54bb94121ae36a84f63dac4ee6 to your computer and use it in GitHub Desktop.
WordPress - Create limited site owner role
<?php
add_action('after_setup_theme', function(){
if(!get_option('soes_roles_created')){
$site_owner_caps = get_role('administrator')->capabilities;
$unwanted_caps = array(
'activate_plugins' => true,
'delete_plugins' => true,
'install_plugins' => true,
'update_plugins' => true,
);
$site_owner_caps = array_diff_key($site_owner_caps, $unwanted_caps);
add_role('site_owner', 'Site Owner', $site_owner_caps);
update_option('soes_roles_created', true);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment