Change WordPress user roles and capabilities Forums Bug Reports New Role will not retain the ‘manage options’ setting Reply To: New Role will not retain the ‘manage options’ setting

#7471
Vladimir
Keymaster

Hi,

I confirm this. Simple banner plugin does not think that role may edited manually, and applies the logic: if role has ‘manage_simple_banner’ capability, thus it was granted automatically by SB plugin itself, then if role is not included into the list of roles allowed to work with SB (Pro feature), then automatically revoke ‘manage_simple_banner’ and ‘manage_options’ user capability from such role:


// Add permissions for other roles
foreach (get_editable_roles() as $role_name => $role_info) {
	if ( $role_name !== 'administrator') {
		if (in_array($role_name, explode(",", $permissions_array))) {
			$add_role = get_role( $role_name );
			$add_role->add_cap( $manage_simple_banner );
			$add_role->add_cap( $manage_options );
		} else {
			$remove_role = get_role( $role_name );
			// only remove capabilities if they were previously added
			if ($remove_role->has_cap( $manage_simple_banner )){
				$remove_role->remove_cap( $manage_simple_banner );
				$remove_role->remove_cap( $manage_options );
			}
		}
	}
}