Skip to content

New Background Control should not be able to save a null value as a color. #601

@jamesros161

Description

@jamesros161

Describe the bug
Somehow, the Background Control is able to save a null value as a color. This breaks PPB because it expects each value to be not-null.
Investe the issue, and determine how to prevent null values from being saved, or adjust the code in the builder to accommodate for the possibility of a null value. See the following areas of code to start off when working:

Template uses the colors here:

<li class='panel-selection custom-color'><i class="fa fa-plus" aria-hidden="true"></i></li>
<# _.each( data.customColors, function ( customColor, index ) {
if ( customColor.includes( 'linear-gradient' ) ) {
return;
}
#>
<li data-type="custom" data-index="{{index}}" data-preset="{{customColor}}" style='background-color:{{customColor}}' class="panel-selection"></li>

The option is pulled and added to the editor.js here:

'saved_colors' => Boldgrid_Editor_Option::get( 'custom_colors', array() ),

The option is saved here:

public function save_colors() {
if ( isset( $_REQUEST['boldgrid-custom-colors'] ) ) {
$custom_colors = ! empty( $_REQUEST['boldgrid-custom-colors'] ) ?
sanitize_text_field( wp_unslash( $_REQUEST['boldgrid-custom-colors'] ) ) : '';
$custom_colors = json_decode( $custom_colors, true );
$custom_colors = is_array( $custom_colors ) ? $custom_colors : array();
Boldgrid_Editor_Option::update( 'custom_colors', $custom_colors );
}
}

In the new react control, the following code will be useful

The component is here:
https://github.com/BoldGrid/boldgrid-panel/blob/ea4b7389e45fb741f4fd846f8249ed419f3a6188/src/components/boldgrid-color-picker/components/Presets.tsx#L64-L72

This is where the component actually edits the field that is saved on publish:
https://github.com/BoldGrid/boldgrid-panel/blob/707b80a7b0ca1753990aa8863b81138e6638a0d3/src/contexts/background-content/background.effects.tsx#L310-L314

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions