Skip to content

Instantly share code, notes, and snippets.

@codepuncher
Created April 1, 2021 10:35
Show Gist options
  • Select an option

  • Save codepuncher/ab99f07630355d690ffc0cec484eb0b0 to your computer and use it in GitHub Desktop.

Select an option

Save codepuncher/ab99f07630355d690ffc0cec484eb0b0 to your computer and use it in GitHub Desktop.

Revisions

  1. codepuncher created this gist Apr 1, 2021.
    36 changes: 36 additions & 0 deletions bb-row-advanced-bg-class-field.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,36 @@
    <?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);