Disable Divi AI by default in the Divi Role Editor

Written by Dan Mossop

Divi's built-in artificial intelligence feature, Divi AI, lets you quickly generate content and images for your Divi modules. For designers and agencies, maintaining control over its usage by clients can be crucial. Disabling Divi AI where it is not needed helps keep the interface streamlined for clients, but it also conserves the agency’s own Divi AI resources. In this post, we'll guide you through the process of changing how the Divi AI role editor option works – allowing you to disable it by default for non-administrators, disable it by default for administrators, and / or keep it permanently disabled. 

Please note that the PHP code given in this post must be deployed on the client's site (e.g. via a child theme or custom plugin), and could be removed again by a sufficiently knowledgeable / motivated client. As such, it should be considered more of a barrier to their use of Divi AI than a fool-proof security mechanism.

Disabling Divi AI by default for non-administrators

Divi AI can be deactivated in the Divi role editor, but if you manage a lot of sites and want to streamline the process, you can use the PHP code below to disable Divi AI for all non-administrator roles by default. This minimizes potential interface clutter and ensures only the necessary functions are available for these user roles.

// === Disable Divi AI for non-administrators by default === //

if (false === get_option('et_pb_role_settings')) {
    add_option( 'et_pb_role_settings', array());
}

add_filter('option_et_pb_role_settings', 'dbc_disable_divi_ai_by_default');

function dbc_disable_divi_ai_by_default($option) {

	$allow_on_admin = apply_filters('dbc_disable_divi_ai_allow_on_admin', true);
	$allow_reactivation = apply_filters('dbc_disable_divi_ai_allow_reenable_in_role_editor', true);
	
    // Get a list of user roles
    $roles = array('administrator', 'editor', 'author', 'contributor'); 
    if (function_exists('et_pb_get_all_roles_list')) {
        $et_pb_roles = et_pb_get_all_roles_list();
        if (is_array($et_pb_roles)) {
          $roles = array_keys($et_pb_roles);
        }
    }

	// Disable "Divi AI" role as needed
    if (!is_array($option)) { 
        $option = array(); 
    }
    foreach($roles as $role) {
		
        if ($allow_on_admin && $role === 'administrator') { 
            continue; 
        }
        if (!isset($option[$role]) || !is_array($option[$role])) { 
            $option[$role] = array(); 
        }
        if (!$allow_reactivation || !isset($option[$role]['divi_ai'])) { 
            $option[$role]['divi_ai'] = 'off'; 
        }
    }

    return $option;
}

Note that this sets the default value for the Divi AI option, which is used in the event that there is not already a value set for the Divi AI state. It won't work if the role editor options have already been saved since the Divi AI role editor option was introduced – in that case the value set at the time of the save will be used. Likewise, if the Divi AI role editor option is enabled for a role and saved after installing this code, this newly set value will override the default.

Disabling Divi AI by default for administrators

To extend this default to include administrators, you can add this PHP code to that given above.

// Optional - disallow Divi AI for administrators by default
add_filter('dbc_disable_divi_ai_allow_on_admin', '__return_false');

With this piece of code, Divi AI will also be disabled for administrators by default. They can, of course, re-enable it in the role editor if they wish.

Preventing re-activation of Divi AI from within the role editor

If you need to ensure that the Divi AI feature remains disabled and cannot be re-enabled later in the Role Editor, add this code snippet to the above:

// Optional - disallow reactivation of Divi AI via the role editor
add_filter('dbc_disable_divi_ai_allow_reenable_in_role_editor', '__return_false');

This code prevents those roles for which Divi AI is off by default from switching the Divi AI feature back on from within the Role Editor setting, effectively making them permanently disabled. 

Note that in the role editor, it will look like the setting can be re-activated and saved, but when the role editor is reloaded you should see that the setting is actually still disabled. Likewise Divi AI should remain unavailable in the Divi Builder interface for those roles.

By controlling access to the Divi AI feature, you can ensure a focused and simplified interface for your clients and better manage your own Divi AI quota.

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

Supercharge Your Posts with AI-Generated CTAs

Transform the way you manage your WordPress posts with WP Magic CTAs. Streamline post engagement and conversions by harnessing AI to create tailored call-to-actions, perfect for guiding users and efficiently managing engagement without compromising control over Divi AI resources.

Latest Posts

Adjust Lightbox Arrow Size in Divi Gallery

Customize the size of the navigation arrows that appear in your gallery lightbox so they’re easier to see and aligned with your site’s design. Whether you want larger, more accessible controls or a subtler look, setting a precise arrow size creates a more polished...

Change Lightbox Arrow Color in the Divi Gallery Module

Make the lightbox navigation arrows in your Divi Gallery match your brand and stand out against your images by assigning a custom color. This improves visual consistency, enhances accessibility with better contrast, and elevates the overall browsing experience for...

Change the Divi Gallery Module Grid Image Scaling

Divi’s Gallery module offers a great way to showcase images, but it can sometimes stretch or crop them in unwanted ways. This article explains how to manage the module’s image scaling behavior to ensure your images are displayed at the correct size and aspect...

Set Custom CSS IDs for Individual Divi Accordion Items

Assigning unique CSS IDs to specific Divi Accordion items allows for precise control over styling, targeting, and linking within your page content. This ability is particularly useful when you want to apply custom designs or create anchor links to particular accordion...

Enable Swipe Navigation in the Divi Gallery Lightbox

Enabling swipe navigation in the Divi Gallery module's lightbox allows users to seamlessly browse through gallery images by swiping left or right, creating a more interactive and mobile-friendly experience. This functionality can significantly improve user engagement...

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, 

0 Comments

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