Created
January 21, 2021 11:52
-
-
Save awah95/2d471f049eb3b7024003109d550eebb2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Add custom field option on all modules. | |
* | |
* @param array $modules | |
* | |
* @return array | |
*/ | |
function smpl_extend_modules( $modules ) { | |
// Ensure we run this code only once because it's expensive. | |
static $is_applied = false; | |
if ( $is_applied ) { | |
return $modules; | |
} | |
// Bail early if the modules list empty. | |
if ( empty( $modules ) ) { | |
return $modules; | |
} | |
foreach ( $modules as $module_slug => $module ) { | |
// Ensure fields list exist. | |
if ( ! isset( $module->fields_unprocessed ) ) { | |
continue; | |
} | |
/** | |
* Fields list on the module. | |
* | |
* @var array | |
* | |
* The structures: | |
* array( | |
* 'field_slug' => array( | |
* 'label' => '', | |
* 'description' => '', | |
* 'type' => '', | |
* 'toggle_slug' => '', | |
* 'tab_slug' => '', | |
* ), | |
* ... Other fields. | |
* ) | |
*/ | |
$fields_list = $module->fields_unprocessed; | |
// Add 'Member Field' option on 'Member Toggle' options group. | |
if ( ! empty( $fields_list ) ) { | |
$fields_list['member_field'] = array( | |
'label' => 'Member Field', | |
'description' => 'Member field option here.', | |
'type' => 'text', | |
'toggle_slug' => 'member_toggle', | |
'tab_slug' => 'custom_css', | |
); | |
$modules[ $module_slug ]->fields_unprocessed = $fields_list; | |
} | |
} | |
$is_applied = true; | |
return $modules; | |
} | |
add_filter( 'et_builder_get_parent_modules', 'smpl_extend_modules' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment