Created
April 1, 2021 10:35
-
-
Save codepuncher/ab99f07630355d690ffc0cec484eb0b0 to your computer and use it in GitHub Desktop.
Add a "Background Class" select field to Beaver Builder row "Advanced" tab.
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 a "Background Class" setting to the row, advanced, CSS selectors section. | |
*/ | |
add_filter('fl_builder_register_settings_form', function (array $form, string $id): array { | |
if ('row' !== $id) { | |
return $form; | |
} | |
$form['tabs']['advanced']['sections']['css_selectors']['fields']['background_class'] = [ | |
'type' => 'select', | |
'label' => __('Background Class', 'avado'), | |
'default' => 'bg-color-default', | |
'options' => get_background_colours(), | |
]; | |
return $form; | |
}, 10, 2); | |
/** | |
* Adds the chosen "Background class" to the row. | |
*/ | |
add_filter('fl_builder_row_attributes', function (array $attrs, object $row): array { | |
if ('row' !== $row->type) { | |
return $attrs; | |
} | |
if ('bg-color-default' === $row->settings->background_class) { | |
return $attrs; | |
} | |
$attrs['class'][] = $row->settings->background_class; | |
return $attrs; | |
}, 10, 2); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment