Changing the Divi Role Editor Defaults

Written by Dan Mossop

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);
The first time the code runs, it sets the named role setting to off for all but the administrator. It then records the roles it has affected, so that a) it doesn't change them in the future, and b) it can detect and set the default on any roles added in the future. By only modifying the value for a role once, it ensures that subsequent changes made by the administrator are not overwritten.

We may earn a commission when you visit links on our website.

Run PHP Code Directly in your Divi Layouts

Unlock endless customization, automation, and dynamic functionality by seamlessly adding PHP code to your Divi pages and posts with the Divi PHP Code Module. Style, preview, and debug your PHP creations directly in the visual builder with robust error handling and enhanced security.

Latest Posts

Customize Lightbox Title Styling in the Divi Gallery Module

Adjust the appearance of the lightbox title that appears when visitors open images from a Divi Gallery to align with your brand and improve readability. Refining the title’s color, size, and weight enhances visual hierarchy, accessibility, and overall polish. In this...

Center the Lightbox Image Count in the Divi Gallery Module

Centering the image count in a gallery lightbox creates a cleaner, more balanced presentation and makes it easier for visitors to see where they are in the image set. This simple visual tweak can enhance readability, especially with larger images and longer captions,...

Style the Divi Gallery Module Lightbox Image Count

Tailor the appearance of the image counter in the Divi Gallery module lightbox to match your brand and improve readability. By customizing the counter’s color and typography, you ensure it displays clearly and suits your design. In this guide we show you how to style...

Customize the Lightbox Image Background Color in the Divi Gallery

Control the color that appears behind your images when users open in the gallery lightbox, including support for semi-transparent hues. This helps improve contrast for transparent images, align the experience with your brand palette, and create a more polished viewing...

About Dan Mossop

Dan is a Scottish-born web developer, now living in Brisbane with his wife and son. He has been sharing tips and helping users with Divi since 2014. He created Divi Booster, the first Divi plugin, and continues to develop it along with 20+ other Divi plugins. Dan has a PhD in Computer Science, a background in web security and likes a lot of stuff, 

2 Comments

  1. 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.

    Reply
    • 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!

      Reply

Submit a Comment

Comments are manually moderated and approved at the time they are answered. A preview is shown while pending but may disappear if your are cookies cleared - don't worry though, the comment is still in the queue.

Your email address will not be published. Required fields are marked *.