The Divi Theme comes with a role editor that lets you control which user roles (administrator, editor, contributor, etc) can use which Divi features. By default, everyone has access to everything and you must explicitly disable any features you don't want accessed by particular user roles. Today I was looking for a way to programmatically restrict a module so that, by default, it would only be enabled for administrators.
It would be easy to do this if there was a suitable filter on the role editor settings, but as yet there isn't. Instead, I was able to do it by directly altering the option which stores the role editor settings. Here's an example of my approach, in this case setting the login module to be enabled for the administrator only:
$role_setting = 'et_pb_login'; // module / role setting slug
// Get the role settings and list of roles which have already had defaults applied
$defaults_set = get_option($role_setting.'_defaulted_roles', array());
$et_pb_role_settings = get_option('et_pb_role_settings', array());
foreach($et_pb_role_settings as $role=>$settings) {
if (!in_array($role, $defaults_set) && is_array($settings)) {
// Enable the setting for the admin role only
$state = ($role === 'administrator')?'on':'off';
$et_pb_role_settings[$role][$role_setting] = $state;
$defaults_set[] = $role;
}
}
// Save the updated role settings and role default list
update_option($role_setting.'_defaulted_roles', $defaults_set);
update_option('et_pb_role_settings', $et_pb_role_settings);
Related Post: Adding PHP to the Divi Theme
You need to add the ability to make Divi AI off by default. What would be great is a way to do that across many sites in one go… Agencies REALLY need this ability.
Hey Concerned Citizen, I've just put up a post which modifies the code in this post to specifically give some control over the Divi AI role editor option, namely allowing you to disable it by default for non-administrators, disable it by default for administrators, and / or keep it permanently disabled:
Disable Divi AI by default in the Divi Role Editor
I hope it helps!