Skip to content

Instantly share code, notes, and snippets.

@codepuncher
Created April 1, 2021 10:35
Show Gist options
  • Save codepuncher/ab99f07630355d690ffc0cec484eb0b0 to your computer and use it in GitHub Desktop.
Save codepuncher/ab99f07630355d690ffc0cec484eb0b0 to your computer and use it in GitHub Desktop.
Add a "Background Class" select field to Beaver Builder row "Advanced" tab.
<?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