Developer Documentation – Elegant Themes Documentation https://www.elegantthemes.com/documentation Just another WordPress site Sun, 10 Jan 2021 00:27:22 +0000 en-US hourly 1 https://wordpress.org/?v=5.7.2 Settings Field Visibility https://www.elegantthemes.com/documentation/developers/divi-module/settings-field-visibility/ Thu, 19 Apr 2018 02:37:53 +0000 https://www.elegantthemes.com/documentation/?p=2524 Learn how to show or hide a setting depending on the value of other settings.

The post Settings Field Visibility appeared first on Elegant Themes Documentation.

]]>

Note: This tutorial series is intended for advanced users. At least a basic understanding of coding in PHP and JavaScript is required.

The visibility of a module setting can depend on the value of other settings by including one or both of the parameters described below in the setting definition.

Setting Visibility Parameters

  • show_if (array)
    • setting (string|string[]) — Setting value(s)
  • show_if_not (array)
    • setting (string|string[]) — Setting value(s)

Setting Visibility Examples

Only show setting_a when:

  • setting_b is on

 

Only show setting_c when:

  • setting_b is on
  • AND setting_a is not some_value

 

Only show setting_a when:

  • setting_b is one of value_1, value_3value_4
  • AND setting_c is not some_value
  • AND setting_d is not one of value_1value_4

 

The post Settings Field Visibility appeared first on Elegant Themes Documentation.

]]>
Module Settings Groups https://www.elegantthemes.com/documentation/developers/divi-module/module-settings-groups/ Thu, 19 Apr 2018 02:37:54 +0000 https://www.elegantthemes.com/documentation/?p=2529 Learn how to configure the toggle groups in the module settings modal.

The post Module Settings Groups appeared first on Elegant Themes Documentation.

]]>

Note: This tutorial series is intended for advanced users. At least a basic understanding of coding in PHP and JavaScript is required.

When editing modules inside the Divi Builder, their settings appear in collapsable groups . You can assign a setting to a specific group using the toggle_slug parameter in the setting definition. You can use one of the builder’s predefined settings groups or you can use a custom group.

Predefined Settings Groups

The following groups are predefined and can be used by simply including one of their slugs as the toggle_slug parameter in a setting definition.

Display Name Slug
Admin Label admin_label
Alignment alignment
Animation animation
Arrows Color arrows_color
Attributes attributes
Audio audio
Background background
Bar Counter bar
Body Text body
Border border
Box Shadow box_shadow
Bullet bullet
Button One button_one
Button Two button_two
Button button
CSS ID & Classes classes
Caption Text caption
Categories categories
Circle circle
Color color
Conditional Logic conditional_logic
Content Text content
Controls Colors colors
Controls controls
Currency & Frequency Text currency_frequency
Custom CSS custom_css
Dividers dividers
Dropdown Menu dropdown
Elements elements
Email Account provider
Email email
Exceptions exceptions
Excluded Item excluded
Featured Image featured_image
Field Options field_options
Field Text form_field
Fields fields
Filter Criteria Text filter
Filters filters
Icon icon
Image & Icon icon_settings
Image & Video image_video
Images images
Image image
Input Text input
Label Text label
Layout layout
Links links
Link link
Map child_filters
Map map
Menu Text menu
Meta Text meta
Module Text module
Navigation navigation
Number Text number
Numbers Text numbers
Overlay overlay
Pagination Text pagination
Percentage Text percent
Play Icon play_icon
Player Pause player_pause
Portfolio Title Text portfolio_header
Price Text price
Redirect redirect
Result Message Text result_message
Rotation rotation
Sale Badge badge
Scroll Down Icon scroll_down
Search Field field
Sizing width
Spacing margin_padding
State state
Styles styles
Subhead Text subhead
Subheader Text subheader
Success Action success_action
Tab Text tab
Text main_content
Text text
Title Text header
Title Text title
Toggle Text toggle
Visibility visibility

Custom Settings Groups

Settings can be assigned to a custom group in the same way that you would assign them to predefined groups. However, you must also define all custom groups in the get_settings_modal_toggles() method of your module’s PHP class.

Settings Group Definition

  • tab_slug (array)
    • toggles (array) — All settings group definitions for the tab
      • toggle_slug (array) — Settings group definition
        • priority (int) — Groups are sorted based on this number (from lowest to highest)
        • sub_toggles (array) — Sub groups for this group (optional)
          • sub_toggle_slug (array) — Sub group definition
            • icon (string) — The slug of a predefined icon (optional)
            • icon_svg (string) — Raw SVG icon (optional)
            • name (string) — Display Name (only shown when no icon is defined)
        • tabbed_subtoggles (bool) — Whether or not to display sub groups as tabs
        • title (string) — Display name (localized)

Custom Settings Groups Example

The post Module Settings Groups appeared first on Elegant Themes Documentation.

]]>
How To Create a Custom Field For a Divi Builder Module https://www.elegantthemes.com/documentation/developers/how-to-create-a-custom-field-for-a-divi-builder-module/ Sun, 10 Jan 2021 00:27:22 +0000 https://www.elegantthemes.com/documentation/?p=3131 Note: This tutorial series is intended for advanced users. At least a basic understanding of coding in PHP and JavaScript is required. Custom Fields for Divi Module Settings Creating a custom field for a Divi module is similar to creating a custom Divi module in the Divi Builder. Both methods require some Javascript, HTML, & […]

The post How To Create a Custom Field For a Divi Builder Module appeared first on Elegant Themes Documentation.

]]>

Note: This tutorial series is intended for advanced users. At least a basic understanding of coding in PHP and JavaScript is required.

Custom Fields for Divi Module Settings

Creating a custom field for a Divi module is similar to creating a custom Divi module in the Divi Builder. Both methods require some Javascript, HTML, & CSS code. However, to create a custom field for a module, there is no need for any PHP because you don’t need to write a PHP class to render the HTML output on the frontend. The main component needed is a ReactJS component class that handles rendering the field inside of the Divi Builder. Then you can define the custom field on your module definition.

In this tutorial, you’ll learn how to create custom fields for a Divi Builder module that will be fully functional in the builder.

Getting Started

Keep in mind. Custom Divi Builder fields must be implemented within a theme, child-theme, or Divi Extension. In this tutorial, we’re going to create a custom field for a custom module in a Divi Extension.

Also, this tutorial is a continuation of previous tutorials that have a specific setup already in place.

If you haven’t already done so, go ahead and do the following before you start this tutorial:

  1. Create a Divi Extension
  2. Create a Custom Module.

Once done, you are ready to continue.

Run Yarn

Before we can test our custom field later on in the Divi Builder we’ll need to compile the JSX code into regular JavaScript. To do that, we need to run yarn. To do this, simply run the following command inside your plugin’s directory:

yarn start

IMPORTANT: Be sure that yarn start is running in the root folder of your plugin. Furthermore, you should keep yarn start running as you develop so that the files continue to compile successfully.

Upgrading Divi Scripts

Custom Divi Builder Fields is a new feature and only available on divi-scripts version 1.0.2 above. So, if you want to add custom field on your existing extension, please upgrade your divi-scripts to version 1.0.2. You can do this by changing divi-scripts version on your package.json located at at the root of your extension directory.

custom fields for divi builder modules

Then run yarn install to update. You can also find a custom field example on this documentation here.

Update Field Directory and File Names

We’ll get to update the code in our files in a bit. But before we can do that, we need to change the default directory and file names for our new custom field.

Look inside your extension’s directory and locate the example custom field located at /includes/fields/Input/Input.jsx.

custom fields for divi builder modules

We’ll use this as a starting point to create a custom input field.

First, rename the Input directory to SimpleInput.

Inside the directory (now named SimpleInput), rename the file Input.jsx to SimpleInput.jsx.

The path to the file should now be includes/fields/SimpleInput/SimpleInput.jsx

how to create a custom field for a Divi Builder Module

Update the Field File

Open the SimpleInput.jsx file and edit it as follows:

Update the React Component Class

For our custom field to be available and fully functional inside the Divi Builder we must create a React Component class that handles the rendering of our custom field based on its props.

By default, the component class is named Input. Change the name of the class Input to SimpleInput.

Then change the name Input to SimpleInput at the bottom of the file to reflect the new name of our component class in order to be exported for use.

Also make sure to update the slug, input id, and input className to reflect the name of the new field.

(NOTE: Depending on the prefix id you chose when setting up your Divi Extension, you may see different names for the static slug, input id, input class, etc. This example has the prefix simp which was chosen when creating the Divi Extension.)

custom fields for divi builder modules

Here is an example of what the code should look like after the change has been made:

// External Dependencies
import React, { Component } from 'react';

// Internal Dependencies
import './style.css';

class SimpleInput extends Component {

  static slug = 'simp_simple_input';

  /**
   * Handle input value change.
   *
   * @param {object} event
   */
  _onChange = (event) => {
    this.props._onChange(this.props.name, event.target.value);
  }

  render() {
    return(
      <input
        id={`simp-simple-input-${this.props.name}`}
        name={this.props.name}
        value={this.props.value}
        type='text'
        className='simp-simple-input'
        onChange={this._onChange}
        placeholder='Your text here ...'
      />
    );
  }
}

export default SimpleInput;

The _onChange() prop is a method handler to save or remove the field setting’s value. It passes 2 parameters.

custom fields for divi builder modules

The first parameter is the field setting’s name. You can use name prop here because it’s already supplied with the correct field name based on the current active tab mode. For example: when you are editing the Title option in Tablet tab mode, the field’s name generated is title_tablet. The second parameter is the field setting value that you want to save.

The field setting type is actually a third parameter that is automatically defined with the current field type prop. So we don’t have to include that parameter with the other 2.

Update the index.js file for the Custom Field

Next, let’s update the import and export statements in the index.js file located at /includes/fields/index.js. To do this, open to edit the index.js file.

Replace all instances of the name for the class and directory (which is Input by default) to the new name SimpleInput.

custom fields for divi builder modules

Here is an example of the final code:

import SimpleInput from './SimpleInput/SimpleInput';

export default [SimpleInput];

Custom Field CSS Styles

Styles for our custom field can be defined using the style.css file in its directory located at /includes/fields/SimpleInput/style.css.

how to create a custom field for a Divi Builder Module

Our custom field is only a basic input element that comes with default builder styling. For now, let’s change the default class selector to .simp-simple-input (rendered in SimpleInput.jsx) throughout the style.css file:

input.simp-simple-input {
  background: #f1f5f9;
  max-height: 30px;
  border: 0;
  border-radius: 3px;
  padding: 7px 10px;
  box-sizing: border-box;
  transition: background 200ms ease;
  color: #4C5866;
  font-family: 'Open Sans', Helvetica, Roboto, Arial, sans-serif;
  font-size: 13px;
  font-weight: 600;
  line-height: normal;
  display: block;
  width: 100%;
}

input.simp-simple-input:focus {
  background: #e6ecf2;
}

input.simp-simple-input::-webkit-input-placeholder {
  color: #98a7b8;
}

input.simp-simple-input:-moz-placeholder {
  color: #98a7b8;
}

input.simp-simple-input::-moz-placeholder {
  color: #98a7b8;
}

input.simp-simple-input:-ms-input-placeholder {
  color: #98a7b8;
}

input.simp-simple-input[readonly] {
  background: #ffffff !important;
  border: 1px solid #eaedf0 !important;
  cursor: not-allowed;
}

Field Definition

To use our custom field, we need to define it on the module definition of our intended module. For this example, let’s add it to the Simple Header module we created in the previous tutorial.

Open the SimpleHeader.php file located at /includes/modules/SimpleHeader/SimpleHeader.php.

Then add the code to define the custom field. Don’t forget to use simp_simple_input as the field type.

custom fields for divi builder modules

The final code will look like this:


class SIMP_SimpleHeader extends ET_Builder_Module {

	public $slug       = 'simp_simple_header';
	public $vb_support = 'on';

	public function init() {
		$this->name = esc_html__( 'Simple Header', 'simp-simple-extension' );
	}

	public function get_fields() {
		return array(
			'heading'     => array(
				'label'           => esc_html__( 'Heading', 'simp-simple-extension' ),
				'type'            => 'text',
				'option_category' => 'basic_option',
				'description'     => esc_html__( 'Input your desired heading here.', 'simp-simple-extension' ),
				'toggle_slug'     => 'main_content',
			),
			'content'     => array(
				'label'           => esc_html__( 'Content', 'simp-simple-extension' ),
				'type'            => 'tiny_mce',
				'option_category' => 'basic_option',
				'description'     => esc_html__( 'Content entered here will appear below the heading text.', 'simp-simple-extension' ),
				'toggle_slug'     => 'main_content',
			),
			'field'       => array(
				'label'           => esc_html__( 'Custom Field', 'simp-simple-extension' ),
				'type'            => 'simp_simple_input',
				'option_category' => 'basic_option',
				'description'     => esc_html__( 'Text entered here will appear inside the module.', 'simp-simple-extension' ),
				'toggle_slug'     => 'main_content',
			),
		);
	}

	public function render( $unprocessed_props, $content = null, $render_slug ) {
		return sprintf(
			'<h1 class="simp-simple-header-heading">%1$s</h1>
			<div>%2$s</div>',
			esc_html( $this->props['heading'] ),
			$this->props['content']
		);
	}
}

new SIMP_SimpleHeader;

The properties that were added to the field are only the required properties you need to define. But you can add more properties to use on the custom field if you want. For instance, you can add both responsive and hover options for your custom field as well.

Divi Builder and Frontend Output

Our field definition is ready. We just need to update the render() method so that it will display the custom field value. Let’s start with the render() method on the module PHP class.

Open the SimpleHeader.php file and update the render() method as follows:

how to create a custom field for a Divi Builder Module

The final code should look like this:


class SIMP_SimpleHeader extends ET_Builder_Module {

	public $slug       = 'simp_simple_header';
	public $vb_support = 'on';

	public function init() {
		$this->name = esc_html__( 'Simple Header', 'simp-simple-extension' );
	}

	public function get_fields() {
		return array(
			'heading'     => array(
				'label'           => esc_html__( 'Heading', 'simp-simple-extension' ),
				'type'            => 'text',
				'option_category' => 'basic_option',
				'description'     => esc_html__( 'Input your desired heading here.', 'simp-simple-extension' ),
				'toggle_slug'     => 'main_content',
			),
			'content'     => array(
				'label'           => esc_html__( 'Content', 'simp-simple-extension' ),
				'type'            => 'tiny_mce',
				'option_category' => 'basic_option',
				'description'     => esc_html__( 'Content entered here will appear below the heading text.', 'simp-simple-extension' ),
				'toggle_slug'     => 'main_content',
			),
			'field'       => array(
				'label'           => esc_html__( 'Custom Field', 'simp-simple-extension' ),
				'type'            => 'simp_simple_input',
				'option_category' => 'basic_option',
				'description'     => esc_html__( 'Text entered here will appear inside the module.', 'simp-simple-extension' ),
				'toggle_slug'     => 'main_content',
			),
		);
	}

	public function render( $unprocessed_props, $content = null, $render_slug ) {
		return sprintf(
			'<h1 class="simp-simple-header-heading">%1$s</h1>
			<div>%2$s</div>
			<p>%3$s</p>',
			esc_html( $this->props['heading'] ),
			$this->props['content'],
			$this->props['field']
		);
	}
}

new SIMP_SimpleHeader;

Now, let’s edit the render() method of the React component and make it produce the same output that we defined in our PHP render() method.

Open the SimpleHeader.jsx file and update the render() method as follows:

how to create a custom field for a Divi Builder Module

The final code should look like this:

// External Dependencies
import React, { Component, Fragment } from 'react';

// Internal Dependencies
import './style.css';


class SimpleHeader extends Component {

  static slug = 'simp_simple_header';

  render() {
    return (
      <Fragment>
        <h1 className="simp-simple-header-heading">{this.props.heading}</h1>
        <div>
          {this.props.content()}
        </div>
        <p>
          {this.props.field}
        </p>
      </Fragment>
    );
  }
}

export default SimpleHeader;

Here you can see how the output of the render() method of the php file corresponds to the output of the render() method of the php file which now includes the new field wrapped in a p tag.

how to create a custom field for a Divi Builder Module

Add Selectors if Needed

Wrapping the new field output with a p tag makes sense here because we are interested in simple text output. This also is a good opportunity to add your own custom selectors (CSS ID, CSS Class) to the p tag for your own needs. Just make sure you add the same selectors to the output of the render() method of the PHP file and the JSX file.

Testing Your Custom Fields

If you already have yarn start running as we suggested in the first step, you can now launch the Divi Builder and check out your Simple Input field!

If not, before we can test our custom field in the Divi Builder we need to compile the JSX code into regular JavaScript. To do that, simply run the following command inside your plugin’s directory:

yarn start

As a reminder, you should keep yarn start running as you continue to edit your files so that the files continue to compile successfully.

To test out the custom field, go to your Divi site and open the settings of the custom Simple Header Module. The new Custom Field will be under the content tab.

custom fields for divi builder modules

Wrapping up

When you are finished development, remember to stop yarn start from running in your terminal (hitting ctrl + c within the terminal usually does the trick).

The post How To Create a Custom Field For a Divi Builder Module appeared first on Elegant Themes Documentation.

]]>
Divi Template Hooks https://www.elegantthemes.com/documentation/developers/hooks/divi-template-hooks/ Thu, 19 Apr 2018 02:37:58 +0000 https://www.elegantthemes.com/documentation/?p=2548 Learn about the hooks that are available in Divi's template files.

The post Divi Template Hooks appeared first on Elegant Themes Documentation.

]]>
 footer.php

et_after_main_content

Fires after the main content, before the footer is output.

Type: Action
Since: 3.1


header.php

et_head_meta

Fires in the head, before wp_head() is called. This action can be used to insert elements into the beginning of the head before any styles or scripts.

Type: Action
Since: 1.0

et_html_top_header

Filters the HTML output for the top header.

Type: Filter
Since: 3.1

Param Type Description
$top_header string HTML output for the top header

et_html_slide_header

Filters the HTML output for the slide header.

Type: Filter
Since: 3.1

Param Type Description
$slide_header string HTML output for the slide header

et_html_logo_container

Filters the HTML output for the logo container.

Type: Filter
Since: 3.1

Param Type Description
$logo_container string HTML output for the logo container

et_header_top

Fires at the end of the et-top-navigation element, just before its closing tag.

Type: Action
Since: 1.0

et_html_main_header

Filters the HTML output for the main header.

Type: Filter
Since: 3.1

Param Type Description
$main_header string HTML output for the main header

et_before_main_content

Fires after the header, before the main content is output.

Type: Action
Since: 3.1


index.php

et_pb_index_blog_image_width

Filters the width used to retrieve featured images via wp_get_attachment_image_src().

Type: Filter
Since: 1.0

Param Type Description
$width string Width value as a string

et_pb_index_blog_image_height

Filters the height used to retrieve featured images via wp_get_attachment_image_src().

Type: Filter
Since: 1.0

Param Type Description
$height string Height value as a string

page.php

et_pb_index_blog_image_width

See index.php above for definition.

et_pb_index_blog_image_height

See index.php above for definition.


single.php

et_before_content

Fires right before the_content() is called.

Type: Action
Since: 1.0

et_pb_index_blog_image_width

See index.php above for definition.

et_pb_index_blog_image_height

See index.php above for definition.


single-project.php

et_pb_portfolio_single_image_width

Filters the width used to retrieve featured images via wp_get_attachment_image_src().

Type: Filter
Since: 1.0

Param Type Description
$width string Width value as a string

et_pb_portfolio_single_image_height

Filters the height used to retrieve featured images via wp_get_attachment_image_src().

Type: Filter
Since: 1.0

Param Type Description
$height string Height value as a string

The post Divi Template Hooks appeared first on Elegant Themes Documentation.

]]>
Divi Builder JavaScript API https://www.elegantthemes.com/documentation/developers/code-reference/divi-builder-javascript-api/ Thu, 19 Apr 2018 02:37:56 +0000 https://www.elegantthemes.com/documentation/?p=2533 The builder's JavaScript API definition.

The post Divi Builder JavaScript API appeared first on Elegant Themes Documentation.

]]>
window : Window

Global window object.

Kind: global typedef
Emits: event:et_builder_api_ready

ETBuilderModule : React.Component | object

Custom module for the Divi Builder.

Kind: global typedef

Static Properties (Required)

Name Type Description
slug string The module’s slug as defined in it’s PHP class

 

Methods (Required)

Name Type Description
render function

API

Divi Builder API object passed to registered callbacks of the event:et_builder_api_ready event.

Kind: global constant

 

API.Modules

Manage custom modules.

Kind: static property of API
Since: 3.1

Modules.register(modules)

Register one or more custom modules.

Kind: static method of Modules
Since: 3.1

Param Type Description
modules Array.<ETBuilderModule> Modules to register.

 

API.Utils

Useful functions

Kind: static property of API
Since: 3.1

 

Utils._()

Lodash – A modern JavaScript utility library delivering modularity, performance & extras.

Kind: static method of Utils
Link: https://github.com/lodash/lodash
License: MIT
Copyright: JS Foundation and other contributors https://js.foundation/

Utils.classnames() ⇒ string

Generates className value based on the args provided. Takes any number of args which can be a string or an object. The argument foo is short for { foo: true }. If the value associated with a given key is falsy, the key won’t be included in the output.

Kind: static method of Utils
Link: https://github.com/JedWatson/classnames
License: MIT
Copyright: 2017 Jed Watson

Type
string | Object.<string, boolean>

Examples:

classNames('foo', 'bar');                 // => 'foo bar'
classNames('foo', { bar: true });         // => 'foo bar'
classNames({ 'foo-bar': true });          // => 'foo-bar'
classNames({ 'foo-bar': false });         // => ''
classNames({ foo: true }, { bar: true }); // => 'foo bar'
classNames({ foo: true, bar: true });     // => 'foo bar'

 

Utils.decodeOptionListValue(encoded_value) ⇒ object

Decode string value of option_list module setting field type.

Kind: static method of Utils
Since: 3.1

Param Type Description
encoded_value string Value to be decoded

 

Utils.fontnameToClass(font_name) ⇒ string

Returns CSS class for a google font.

Kind: static method of Utils
Since??:

Param Type Description
font_name string Font name for which to return a CSS class

 

Utils.linkRel(saved_value) ⇒ string

Generate link rel HTML attribute value based on a value saved in a module’s settings.

Kind: static method of Utils
Since: 3.1

Param Type Description
saved_value string Value saved in module settings

 

Utils.maybeLoadFont(font_name)

Loads a Google Font if it hasn’t already been loaded.

Kind: static method of Utils
Since: 3.1

Param Type Description
font_name string The name of the font to load

 

Utils.processFontIcon(icon, is_down_icon) ⇒ string

Generates HTML for a saved font-based icon value.

Kind: static method of Utils
Since: 3.1

Param Type Description
icon string The saved icon value
is_down_icon boolean Whether or not the icon is one of the down arrow icons

 

Utils.setElementFont(font_data, use_important, default_values) ⇒ string

Generates font related CSS style properties from font data saved in a module’s settings.

Kind: static method of Utils
Since: 3.1

Param Type Description
font_data string Font data saved in module settings
use_important boolean Whether or not to use !important
default_values object Mapping of default values for the font settings

 

API.isRegistered(slug) ⇒ boolean

Whether or not a component is registered.

Kind: static method of API
Since: 3.1

Param Type Description
slug string The component’s slug

 

API.registerModules(modules)

Convenience wrapper for register

Kind: static method of API
Since: 3.1

Param Type Description
modules Array.<ETBuilderModule> Modules to register.

The post Divi Builder JavaScript API appeared first on Elegant Themes Documentation.

]]>
Defining Module Settings https://www.elegantthemes.com/documentation/developers/divi-module/defining-module-settings/ Thu, 19 Apr 2018 02:37:50 +0000 https://www.elegantthemes.com/documentation/?p=2512 Learn how to define module settings using the field types provided by Divi.

The post Defining Module Settings appeared first on Elegant Themes Documentation.

]]>

Note: This tutorial series is intended for advanced users. At least a basic understanding of coding in PHP and JavaScript is required.

Module settings are defined in the get_fields() method of the module’s PHP class. A setting definition is simply an associative array of parameters.

Required Parameters

  • type (string) — The field type used to render the setting in the module settings modal

Optional Parameters

  • default (string) — Default value
  • description (string) — Description (localized)
  • id (string) — CSS id for the setting’s field
  • label (string) — Display name (localized)
  • option_category (string) — Option category slug (for the Divi Role Editor)
  • show_if (array) — Only show the setting when certain settings have certain values
  • show_if_not (array) — Only show the setting when certain settings do not have certain values
  • tab_slug (string) — Modal tab slug
  • toggle_slug (string) — Modal tab settings group toggle slug

Field Types

The Divi Builder has a comprehensive selection of field types for module settings. Below you’ll find a list of available field types, each with a screenshot and a list of any additional parameters that must be included in the setting definition. The value to use for the type parameter of the setting definition is in parenthesis next to each field type name.

Text (text)

Select (select)

Select Field Parameters

  • options (array) — Option slugs mapped to their display names (localized)

Checkboxes (multiple_checkboxes)

Checkboxes Field Parameters

  • options (array) — Option slugs mapped to their display names (localized)

Toggle Button (yes_no_button)


Toggle Button Field Parameters

  • options (array)
    • off (string) — Display name for the “off” state (localized)
    • on (string) — Display name for the “on” state (localized)

Range Slider (range)

Range Slider Field Parameters

  • range_settings (array)
    • min (string) — Minimum value
    • max (string) — Maximum value
    • step (string) — Minimum distance between values when using the slider
  • validate_unit (bool) — Whether or not to validate unit

The post Defining Module Settings appeared first on Elegant Themes Documentation.

]]>
Defining Custom CSS Fields For Modules https://www.elegantthemes.com/documentation/developers/divi-module/defining-custom-css-fields-for-modules/ Thu, 19 Apr 2018 02:37:52 +0000 https://www.elegantthemes.com/documentation/?p=2521 Learn how to define custom CSS fields for modules.

The post Defining Custom CSS Fields For Modules appeared first on Elegant Themes Documentation.

]]>

Note: This tutorial series is intended for advanced users. At least a basic understanding of coding in PHP and JavaScript is required.

Custom CSS fields appear in the Advanced tab of the module settings modal and allow users to set custom CSS properties for predefined target elements within the module’s HTML output. The fields are automatically generated based on the configuration defined in the module’s get_custom_css_fields_config() method.

Custom CSS Fields Configuration

  • element_one (array)
    • label (string) — Display name for the target element (localized)
    • selector (string) — CSS selector for the target element
    • no_space_before_selector (bool) — Don’t put a space before selector
  • element_two (array)
    • label (string) — Display name for the target element (localized)
    • selector (string) — CSS selector for the target element
    • no_space_before_selector (bool) — Don’t put a space before selector

Custom CSS Fields Configuration Example

The post Defining Custom CSS Fields For Modules appeared first on Elegant Themes Documentation.

]]>
Compatibility Levels https://www.elegantthemes.com/documentation/developers/divi-module/compatibility-levels/ Thu, 19 Apr 2018 02:37:59 +0000 https://www.elegantthemes.com/documentation/?p=2554 Making existing custom modules compatible with the latest version of the Divi Builder.

The post Compatibility Levels appeared first on Elegant Themes Documentation.

]]>

Note: This tutorial series is intended for advanced users. At least a basic understanding of coding in PHP and JavaScript is required.

How a custom module looks and behaves inside the builder depends on its level of compatibility with the builder. There are three levels of compatibility available to custom modules: off (this is the default), partial, and on. Custom modules can declare their level of compatibility using the vb_support property in their PHP class definition.

No Compatibility

This is the default setting for all custom modules. Live previews are not shown for modules with no support for the latest version of the Divi Builder. Instead, a generic block will be shown. The module’s settings can still be edited and it can still be moved around on the page.

Partial Compatibility

The builder will attempt to render a live preview via AJAX for custom modules that declare partial support. AJAX rendering is not ideal as it’s much slower than normal rendering and it won’t be suitable in all cases. For that reason, its important that developers test their modules and only declare partial support for modules that can actually be successfully rendered via AJAX.

Declaring Partial Compatibility Example

Full Compatibility

Modules that are fully compatible with the Divi Builder behave just like official modules. They use the builder’s JavaScript API to handle their own rendering inside the builder. You can learn more about that here.

Declaring Full Compatibility Example

The post Compatibility Levels appeared first on Elegant Themes Documentation.

]]>
Advanced Field Types For Module Settings https://www.elegantthemes.com/documentation/developers/divi-module/advanced-field-types-for-module-settings/ Thu, 19 Apr 2018 02:37:51 +0000 https://www.elegantthemes.com/documentation/?p=2515 Learn about the Advanced Field types for module settings.

The post Advanced Field Types For Module Settings appeared first on Elegant Themes Documentation.

]]>

Note: This tutorial series is intended for advanced users. At least a basic understanding of coding in PHP and JavaScript is required.

Advanced fields are added automatically to all modules that are compatible with the latest version of the Divi Builder unless they specifically opt-out. Most advanced fields are configurable. Configuration for advanced fields can be defined in the get_advanced_fields_config() method of the module’s PHP class. To opt-out of an advanced field, simply set its key in the array to false.

Background (background)

The background field allows users to set the module’s background color, gradient, image, and/or video.

Background Field Configuration

  • css (array) — CSS style configuration
    • important (bool) — Whether or not styles should include !important
    • main (string) — CSS selector for the module’s main element
  • options (array) — Field definition parameter overrides
    • module_setting_slug (array)
      • parameter_1 (mixed) — Parameter value
      • parameter_2 (mixed) — Parameter value
  • settings (array)
    • disable_toggle (bool) — Don’t add a Background toggle group to the settings modal
    • tab_slug (string) — Modal tab slug
    • toggle_slug (string) — Modal tab settings group toggle slug
  • use_background_color (bool|string) — Show the background color tab
  • use_background_color_gradient (bool|string) — Show the background gradient tab
  • use_background_image (bool|string) — Show the background image tab
  • use_background_video (bool|string) — Show the background video tab

The accepted values for use_background_color, use_background_color, use_background_gradient, use_background_image, and use_background_video are:

  • true — Display fields in the module settings and handle frontend markup
  • false — Do not display fields in the module settings and don’t handle frontend markup
  • fields_only — Display fields in the module settings but don’t handle frontend markup

Background Field Configuration Examples

Borders (borders)

The borders field allows users to set the module’s border style, color, width, & radius.

Border Field Configuration

Modules can apply borders not only to their outermost container element, but also to elements inside it. Each key in the configuration represents a separate element that will have adjustable border settings. The border field configuration for the module’s outermost container element is set under the default key.

While only parameters that are specific to borders fields are shown below, all of the common field parameters are supported.

  • default (array)
    • css (array) — CSS style configuration
      • main (array) — CSS selectors for the module’s main element
        • border_radii (string) — CSS selector to be used for border radius styles
        • border_styles (string) — CSS selector to be used for border styles
    • defaults (array)
      • border_radii (string) — Default value for border radius.
        Format: link|top-left|top-right|bottom-right|bottom-left
        Example: on|3px|3px|3px|3px
      • border_styles (array) — Default values for border style properties
        • width (string) — Default value for border width
        • color (string) — Default value for border color
        • style (string) — Default value for border style
    • label_prefix (string) — Text to display in front of the setting label (localized)
    • suffix (string) — Suffix to append to the setting slug. Not required for default border field

Borders Field Configuration Examples

Box Shadow (box_shadow)

The box shadow field allows users to set the module’s box shadow (obviously ? ).

Box Shadow Field Configuration

Modules can apply box shadows not only to their outermost container element, but also to elements inside it. Each key in the configuration represents a separate element that will have adjustable box shadow settings. The box shadow field configuration for the module’s outermost container element is set under the default key.

While only parameters that are specific to the box shadow field are shown below, all of the common field parameters are supported.

  • default (array)
    • css (array) — CSS style configuration
      • custom_style (bool) — Use custom styles generation instead of the default
      • important (bool) — Whether or not styles should include !important
      • main (string) — CSS selector for the module’s main element
      • show_if (array) — Output styles if certain settings have certain values
        • setting_slug (mixed) — Setting value
      • show_if_not (array) — Output styles if certain settings do not have certain values
        • setting_slug (mixed) — Setting value
    • suffix (string) — Suffix to append to the setting slug. Not required for default field.

Box Shadow Field Configuration Examples

Button (button)

The button field handles all of the various settings for customizing the styling of buttons included in a module on the frontend. Unlike the other advanced field types, the Button field is not added to a module unless the module specifically opts-in by including it in its advanced fields configuration.

Button Field Configuration

Modules can include one or more Divi styled buttons in their HTML output on the frontend. Each key in the configuration represents a separate button that can be customized in the module’s settings. While only parameters that are specific to the button field are shown below, all of the common field parameters are supported.

  • button_slug (array)
    • box_shadow (array) — See Box Shadow Field for array structure
    • css (array) — CSS style configuration
      • alignment (string) — CSS selector for alignment styles
      • main (string) — CSS selector for the module’s main element
      • plugin_main (string) — Like main above but applies only with the Divi Builder Plugin
    • disable_toggle (bool) — Don’t add a Button toggle group to the settings modal
    • no_rel_attr (bool) — Don’t show field for customizing the button link’s rel attribute
    • use_alignment (bool) — Show button alignment setting

Button Field Configuration Examples

Filters (filters)

The filters field allows users to control CSS filters for the module.

Filters Field Configuration

  • child_filters_target (array) — Child element filters field configuration
    • depends_show_if (mixed) — Only show field when dependency has this value
    • tab_slug (string) — Modal tab slug
    • toggle_name (string) — Modal toggle group display name (localized)
    • toggle_slug (string) — Modal toggle group slug
  • tab_slug (string) — Modal tab slug
  • toggle_name (string) — Modal toggle group display name (localized)
  • toggle_slug (string) — Modal toggle group slug

Filters Field Configuration Examples

Fonts (fonts)

The fonts field handles all the settings related to customizing the styles for text that appears in the module on the frontend.

Fonts Field Configuration

Modules allow text styles to be adjusted not only to their outermost container element, but also to elements inside it. Each key in the configuration represents a separate element that will have adjustable text style settings. The fonts field configuration for the module’s outermost container element is set under the module key.

While only parameters that are specific to the fonts field are shown below, all of the common field parameters are supported.

  • module (array)
    • defaults (array) — Default values for settings
      • setting_slug_1 (mixed) — Default value
      • setting_slug_2 (mixed) — Default value
    • depends_show_if (mixed) — Only show settings when dependency has this value
    • disable_toggle (bool) — Don’t add a toggle group to the settings modal
    • font (array) — Font family field definition (accepts common field parameters)
      • sub_toggle (string) — Modal sub-toggle group slug
    • font_size (array) — Font size field definition (accepts common field parameters)
      • sub_toggle (string) — Modal sub-toggle group slug
    • header_level (array) — Header level field definition (accepts common field parameters)
      • sub_toggle (string) — Modal sub-toggle group slug
    • hide_font (bool) — Don’t show font family setting
    • hide_font_size (bool) — Don’t show font size setting
    • hide_letter_spacing (bool) — Don’t show letter spacing setting
    • hide_line_height (bool) — Don’t show line height setting
    • hide_text_color (bool) — Don’t show text color setting
    • hide_text_shadow (bool) — Don’t show text shadow setting
    • letter_spacing (array) — Letter spacing field definition (accepts common field parameters)
      • sub_toggle (string) — Modal sub-toggle group slug
    • line_height (array) — Line height field definition (accepts common field parameters)
      • sub_toggle (string) — Modal sub-toggle group slug
    • sub_toggle (string) — Modal sub-toggle group slug
    • text_color (array) — Text color field definition (accepts common field parameters)
      • sub_toggle (string) — Modal sub-toggle group slug
    • text_shadow (array) — Text shadow field definition (accepts common field parameters)
      • sub_toggle (string) — Modal sub-toggle group slug

Fonts Field Configuration Examples

Margin & Padding (margin_padding)

The margin & padding field handles settings for the module’s margin & padding.

Margin & Padding Field Configuration

  • custom_margin (array) — Margin field definition parameter overrides
    • parameter_1 (mixed) — Parameter value
    • parameter_2 (mixed) — Parameter value
  • custom_padding (array) — Padding field definition parameter overrides
    • parameter_1 (mixed) — Parameter value
    • parameter_2 (mixed) — Parameter value
  • disable_toggle (bool) — Don’t add a toggle group to the settings modal
  • use_margin (bool) — Show the margin settings
  • use_padding (bool) — Show the padding settings

Margin & Padding Field Configuration Examples

Max Width (max_width)

The max width field handles settings for the module’s max-width and alignment.

Max Width Field Configuration

  • options (array) — Field definition parameter overrides
    • module_setting_slug (array)
      • parameter_1 (mixed) — Parameter value
      • parameter_2 (mixed) — Parameter value
  • toggle_priority (int) — The priority for the modal toggle group
  • toggle_title (string) — The display name for the modal toggle group (localized)
  • use_max_width (bool) — Show the max width setting
  • use_module_alignment (bool) — Show the alignment setting

Max Width Field Configuration Examples

All Advanced Fields Configuration Examples

The post Advanced Field Types For Module Settings appeared first on Elegant Themes Documentation.

]]>