foreach ( $images_array as $attachment ) {
$image_src = wp_get_attachment_url( $attachment, 'et-pb-post-main-image-fullwidth' );
$gallery_output .= sprintf(
'<div class="et_pb_slide" style="background: url(%1$s);"></div>',
'<div class="et_pb_slider et_pb_slider_fullwidth_off et_pb_gallery_post_type">
<div class="et_pb_slides">
et_core_esc_previously( $gallery_output )
add_filter( 'et_gallery_layout_enable', 'et_gallery_layout_turn_on' );
et_core_intentionally_unescaped( get_post_gallery(), 'html' )
remove_filter( 'et_gallery_layout_enable', 'et_gallery_layout_turn_on' );
* Used to always use divi gallery on et_pb_gallery_images
function et_gallery_layout_turn_on() {
* Remove Elegant Builder plugin filter, that activates visual mode on each page load in WP-Admin
function et_pb_remove_lb_plugin_force_editor_mode() {
remove_filter( 'wp_default_editor', 'et_force_tmce_editor' );
add_action( 'admin_init', 'et_pb_remove_lb_plugin_force_editor_mode' );
* Generates array of all Role options
function et_pb_all_role_options() {
// get all the modules and build array of capabilities for them.
$all_modules_array = ET_Builder_Element::get_modules_array();
$custom_user_tabs = ET_Builder_Element::get_tabs();
$options_categories = ET_Builder_Element::get_options_categories();
$module_capabilies = array();
'general_settings' => array(
'name' => esc_html__( 'Content Settings', 'et_builder' ),
'advanced_settings' => array(
'name' => esc_html__( 'Design Settings', 'et_builder' ),
'custom_css_settings' => array(
'name' => esc_html__( 'Advanced Settings', 'et_builder' ),
// add all custom user tabs into list.
if ( ! empty( $custom_user_tabs ) ) {
foreach ( $custom_user_tabs as $module => $tabs_data ) {
if ( ! empty( $tabs_data ) ) {
foreach ( $tabs_data as $tab_slug => $tab_data ) {
$tabs_array[ $tab_slug ] = array(
'name' => $tab_data['name'],
foreach ( $all_modules_array as $module => $module_details ) {
if ( ! in_array( $module_details['label'], array( 'et_pb_section', 'et_pb_row', 'et_pb_row_inner', 'et_pb_column' ), true ) ) {
$module_capabilies[ $module_details['label'] ] = array(
'name' => sanitize_text_field( $module_details['title'] ),
// we need to display some options only when theme activated.
$theme_only_options = ! et_is_builder_plugin_active()
'theme_customizer' => array(
'name' => esc_html__( 'Theme Customizer', 'et_builder' ),
'applicability' => array( 'administrator' ),
'name' => esc_html__( 'Page Options', 'et_builder' ),
$all_role_options = array(
'general_capabilities' => array(
'theme_options' => array(
'name' => et_is_builder_plugin_active() ? esc_html__( 'Plugin Options', 'et_builder' ) : esc_html__( 'Theme Options', 'et_builder' ),
'applicability' => array( 'administrator' ),
'name' => esc_html__( 'Divi Library', 'et_builder' ),
'theme_builder' => array(
'name' => esc_html__( 'Theme Builder', 'et_builder' ),
'applicability' => array( 'administrator', 'editor' ),
'name' => esc_html__( 'Split Testing', 'et_builder' ),
'builder_capabilities' => array(
'section_title' => esc_html__( 'Builder Interface', 'et_builder' ),
'name' => esc_html__( 'Add/Delete Item', 'et_builder' ),
'name' => esc_html__( 'Edit Item', 'et_builder' ),
'name' => esc_html__( 'Move Item', 'et_builder' ),
'disable_module' => array(
'name' => esc_html__( 'Disable Item', 'et_builder' ),
'name' => esc_html__( 'Lock Item', 'et_builder' ),
'divi_builder_control' => array(
'name' => esc_html__( 'Toggle Divi Builder', 'et_builder' ),
'name' => esc_html__( 'Load Layout', 'et_builder' ),
'use_visual_builder' => array(
'name' => esc_html__( 'Use Visual Builder', 'et_builder' ),
'custom_fonts_management' => array(
'name' => esc_html__( 'Upload/Remove Fonts', 'et_builder' ),
'read_dynamic_content_custom_fields' => array(
'name' => esc_html__( 'Dynamic Content Custom Fields', 'et_builder' ),
'library_capabilities' => array(
'section_title' => esc_html__( 'Library Settings', 'et_builder' ),
'name' => esc_html__( 'Save To Library', 'et_builder' ),
'name' => esc_html__( 'Add From Library', 'et_builder' ),
'edit_global_library' => array(
'name' => esc_html__( 'Edit Global Items', 'et_builder' ),
'section_title' => esc_html__( 'Settings Tabs', 'et_builder' ),
'options' => $tabs_array,
'general_module_capabilities' => array(
'section_title' => esc_html__( 'Settings Types', 'et_builder' ),
'options' => $options_categories,
'module_capabilies' => array(
'section_title' => esc_html__( 'Module Use', 'et_builder' ),
'options' => $module_capabilies,
$all_role_options = apply_filters( 'add_et_builder_role_options', $all_role_options );
$all_role_options['general_capabilities']['options'] = array_merge( $all_role_options['general_capabilities']['options'], $theme_only_options );
// Set portability capabilities.
$registered_portabilities = et_core_cache_get_group( 'et_core_portability' );
if ( ! empty( $registered_portabilities ) ) {
$all_role_options['general_capabilities']['options']['portability'] = array(
'name' => esc_html__( 'Portability', 'et_builder' ),
$all_role_options['portability'] = array(
'section_title' => esc_html__( 'Portability', 'et_builder' ),
// Dynamically create an option foreach portability.
foreach ( $registered_portabilities as $portability_context => $portability_instance ) {
$all_role_options['portability']['options'][ "{$portability_context}_portability" ] = array(
'name' => esc_html( $portability_instance->name ),
return $all_role_options;
* Prints the admin page for Role Editor
function et_pb_display_role_editor() {
$all_role_options = et_pb_all_role_options();
$builder_roles_array = et_pb_get_all_roles_list();
foreach ( $builder_roles_array as $role => $role_title ) {
$option_tabs .= et_pb_generate_roles_tab( $all_role_options, $role );
'<a href="#" class="et-pb-layout-buttons%4$s" data-open_tab="et_pb_role-%3$s_options" title="%1$s">
'administrator' === $role ? ' et_pb_roles_active_menu' : ''
'<div class="et_pb_roles_main_container">
<a href="#" id="et_pb_save_roles" class="button button-primary button-large">%3$s</a>
<h3 class="et_pb_roles_title"><span>%2$s</span></h3>
<div id="et_pb_main_container" class="post-type-page">
<div id="et_pb_layout_controls">
<a href="#" class="et-pb-layout-buttons et-pb-layout-buttons-reset" title="Reset all settings">
<span class="icon"></span><span class="label">Reset</span>
<div class="et_pb_roles_container_all">
et_core_esc_previously( $menu_tabs ),
esc_html__( 'Divi Role Editor', 'et_builder' ),
esc_html__( 'Save Divi Roles', 'et_builder' ),
et_core_esc_previously( et_builder_portability_link( 'et_pb_roles', array( 'class' => 'et-pb-layout-buttons et-pb-portability-button' ) ) ),
et_core_esc_previously( $option_tabs )
* Generates the options tab for specified role.
* @param array $all_role_options array of all Role options.
* @param string $role role.
function et_pb_generate_roles_tab( $all_role_options, $role ) {
// generate all sections of the form for current role.
if ( ! empty( $all_role_options ) ) {
foreach ( $all_role_options as $capability_id => $capability_options ) {
$form_sections .= sprintf(
'<div class="et_pb_roles_section_container">
<div class="et_pb_roles_options_internal">
! empty( $capability_options['section_title'] )
? sprintf( '<h4 class="et_pb_roles_divider">%1$s <span class="et_pb_toggle_all"></span></h4>', esc_html( $capability_options['section_title'] ) )
et_pb_generate_capabilities_output( $capability_options['options'], $role )
'<div class="et_pb_roles_options_container et_pb_role-%2$s_options%3$s">
<p class="et_pb_roles_notice">%1$s</p>
<form id="et_pb_%2$s_role" data-role_id="%2$s">
esc_html__( 'Using the Divi Role Editor, you can limit the types of actions that can be taken by WordPress users of different roles. This is a great way to limit the functionality available to your customers or guest authors to ensure that they only have the necessary options available to them.', 'et_builder' ),
'administrator' === $role ? ' active-container' : '',
* Generates the enable/disable buttons list based on provided capabilities array and role.
* @param array $cap_array capabilities.
* @param string $role user role.
function et_pb_generate_capabilities_output( $cap_array, $role ) {
if ( ! empty( $cap_array ) ) {
foreach ( $cap_array as $capability => $capability_details ) {
if ( empty( $capability_details['applicability'] ) || ( ! empty( $capability_details['applicability'] ) && in_array( $role, $capability_details['applicability'], true ) ) ) {
'<div class="et_pb_capability_option">
<span class="et_pb_capability_title">%4$s</span>
<div class="et_pb_yes_no_button_wrapper">
<div class="et_pb_yes_no_button et_pb_on_state">
<span class="et_pb_value_text et_pb_on_value">%1$s</span>
<span class="et_pb_button_slider"></span>
<span class="et_pb_value_text et_pb_off_value">%2$s</span>
<select name="%3$s" id="%3$s" class="et-pb-main-setting regular-text">
<option value="on" %5$s>Yes</option>
<option value="off" %6$s>No</option>
esc_html__( 'Enabled', 'et_builder' ),
esc_html__( 'Disabled', 'et_builder' ),
esc_html( $capability_details['name'] ),
selected( true, et_pb_is_allowed( $capability, $role ), false ),
selected( false, et_pb_is_allowed( $capability, $role ), false )
* Loads scripts and styles for Role Editor Admin page
* @param string $hook hook name.
function et_pb_load_roles_admin( $hook ) {
// load scripts only on role editor page.
if ( apply_filters( 'et_pb_load_roles_admin_hook', 'divi_page_et_divi_role_editor' ) !== $hook ) {
et_core_load_main_fonts();
wp_enqueue_style( 'builder-roles-editor-styles', ET_BUILDER_URI . '/styles/roles_style.css', array( 'et-core-admin' ), ET_BUILDER_VERSION );
wp_enqueue_script( 'builder-roles-editor-scripts', ET_BUILDER_URI . '/scripts/roles_admin.js', array( 'jquery' ), ET_BUILDER_VERSION, true );
$pb_roles_options = array(
'ajaxurl' => admin_url( 'admin-ajax.php' ),
'et_roles_nonce' => wp_create_nonce( 'et_roles_nonce' ),
'modal_title' => esc_html__( 'Reset Roles', 'et_builder' ),
'modal_message' => esc_html__( 'All of your current role settings will be set to defaults. Do you wish to proceed?', 'et_builder' ),
'modal_yes' => et_builder_i18n( 'Yes' ),
'modal_no' => et_builder_i18n( 'No' ),
wp_localize_script( 'builder-roles-editor-scripts', 'et_pb_roles_options', $pb_roles_options );
add_action( 'admin_enqueue_scripts', 'et_pb_load_roles_admin' );
* Generates the array of allowed modules in jQuery Array format.
* @param string $role the user role.
function et_pb_allowed_modules_list( $role = '' ) {
// always return empty array if user doesn't have the edit_posts capability.
if ( ! current_user_can( 'edit_posts' ) ) {
$saved_capabilities = et_pb_get_role_settings();
$role = '' === $role ? et_pb_get_current_user_role() : $role;
$all_modules_array = ET_Builder_Element::get_modules_array( $typenow );
$saved_modules_capabilities = isset( $saved_capabilities[ $role ] ) ? $saved_capabilities[ $role ] : array();
foreach ( $all_modules_array as $module => $module_details ) {
if ( ! in_array( $module_details['label'], array( 'et_pb_section', 'et_pb_row', 'et_pb_row_inner', 'et_pb_column' ), true ) ) {
// Add module into the list if it's not saved or if it's saved not with "off" state.
if ( ! isset( $saved_modules_capabilities[ $module_details['label'] ] ) || ( isset( $saved_modules_capabilities[ $module_details['label'] ] ) && 'off' !== $saved_modules_capabilities[ $module_details['label'] ] ) ) {
$alowed_modules .= "'" . esc_attr( $module_details['label'] ) . "',";
if ( ! function_exists( 'et_divi_get_post_text_color' ) ) {
* Return text color css class.
function et_divi_get_post_text_color() {
$post_format = et_pb_post_format();
if ( in_array( $post_format, array( 'audio', 'link', 'quote' ), true ) ) {
$text_color = get_post_meta( get_the_ID(), '_et_post_bg_layout', true );
$text_color_class = $text_color ? $text_color : 'light';
$text_color_class = ' et_pb_text_color_' . $text_color_class;
return $text_color_class;
if ( ! function_exists( 'et_divi_get_post_bg_inline_style' ) ) {
* Return css style attribute that ho;d background color inline style.
function et_divi_get_post_bg_inline_style() {
$post_use_bg_color = get_post_meta( $post_id, '_et_post_use_bg_color', true ) ? true : false;
$bg_color = get_post_meta( $post_id, '_et_post_bg_color', true );
$post_bg_color = $bg_color && '' !== $bg_color ? $bg_color : '#ffffff';
if ( $post_use_bg_color ) {
$inline_style = sprintf( ' style="background-color: %1$s;"', esc_html( $post_bg_color ) );
* Remove the blockquote from post content.
* @param string $content post content.
* @return string|string[]|null
function et_remove_blockquote_from_content( $content ) {
if ( 'quote' !== et_pb_post_format() ) {
if ( et_theme_builder_overrides_layout( ET_THEME_BUILDER_BODY_LAYOUT_POST_TYPE ) ) {
// Do not remove quotes when TB has taken over.
$content = preg_replace( '/<blockquote(.+?)<\/blockquote>/is', '', $content, 1 );
add_filter( 'the_content', 'et_remove_blockquote_from_content' );
* Register rewrite rule and tag for preview page
function et_pb_register_preview_endpoint() {
add_rewrite_tag( '%et_pb_preview%', 'true' );
add_action( 'init', 'et_pb_register_preview_endpoint', 11 );
* Flush rewrite rules to fix the issue "preg_match" issue with 2.5
function et_pb_maybe_flush_rewrite_rules() {
et_builder_maybe_flush_rewrite_rules( '2_5_flush_rewrite_rules' );
add_action( 'init', 'et_pb_maybe_flush_rewrite_rules', 9 );
* Register template for preview page.
* @param string $template The path of the template to include.