I developed a custom simple module for Divi builder. It shows correctly in the backend and frontend editor.
The problem is that it won't save at all in the backend or frontend editor. When I place it into the backend editor and save the post, then it will lost after reloading the backend editor!
Here is my module class:
class My_Custom_Module extends ET_Builder_Module
{
public function init()
{
$this->name = __('My Custom Module', 'wpl');
$this->slug = 'CUSTOM_SLUG';
}
}
new My_Custom_Module();
I followed this article https://jonathanbossenger.com/building-your-own-divi-builder-modules/ and How to create custom Divi module? and some other articles that I found by Google.
I already tried to put some fields in get_fields function but it didn't help too.
Also to make sure, it's not a conflict, I disabled all other plugins but it didn't fix so it's not related to a conflict.
The access the Module Customizer, click the Divi > Module Customizer link in your WordPress Dashboard. When you open the customizer, you will notice individual panels for each of the Divi Modules. To adjust the appearance of a module, open the panel to reveal the available settings.
To do this, add a new contact form module directly under the toggle module. Click the Advanced tab under the settings of the Contact Form (of any module you want to insert) and add the following CSS Class: CSS Class: divi-portable-module.
Accessing The Theme & Module Customizers To customizer panels can be accessed via the Divi > Theme Customizer and Divi > Module Customizer links in your WordPress Dashboard. The Theme Customizer gives you control over site-wide theme elements, such as your menu & logo size or your body and header text styles.
I finally found the problem myself and I'm sharing it here to help others if they face a same problem.
The simple module in the question doesn't save because its slug, which is missing the et_pb_
prefix. It works fine when I change $this->slug = 'custom_module'
to $this->slug = 'et_pb_custom_module'
.
I didn't see this rule in their documentation but I hope they mentioned it somewhere.
Here is the working code for a simple Divi custom module:
function custom_divi_register_modules()
{
if(class_exists('ET_Builder_Module'))
{
class custom_divi_module extends ET_Builder_Module
{
public function init()
{
$this->name = __( 'Custom Module', 'et_builder' );
$this->slug = 'et_pb_custom_module';
$this->fb_support = true;
}
}
new custom_divi_module;
}
}
add_action('et_builder_ready', 'custom_divi_register_modules');
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With