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.

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.

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

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

Latest From Divi Booster

Enable Automatic Looping for YouTube Videos in the Divi Video Module

Enabling automatic looping for YouTube videos in your Divi video module ensures that content plays seamlessly and continuously without interruption. This feature can enhance user engagement, highlight key information, or create dynamic visual effects on your website....

Hide Video Controls in Divi Video Module

Disabling YouTube video controls in the Divi Video Module helps create a seamless, distraction-free viewing experience for your site visitors. This approach is useful when you want full control over how your video content appears and is interacted with on the page, or...

Mute YouTube Videos by Default in the Divi Video Module

In the Divi Video Module, starting your YouTube videos muted by default can create a more user-friendly browsing experience on your webpage. It is particularly beneficial for reducing distractions, enhancing visitor engagement, and providing a seamless content preview...

Autoplay Videos in Divi Video Module

Enabling videos in your Divi video module to start playing automatically can enhance both the site's design and user engagement. To ensure full compatibility with browser requirements, such as Chrome's autoplay policy, it's often necessary to start your videos muted...

How to Add the Post Status in Divi's Dynamic Content

Divi's Dynamic Content feature is great for enhancing your post/page templates with post-specific information. While Divi includes an option to show information such as the Post Created Date using Dynamic Content, there is no equivalent option for the Post Status....

Random Divi Posts