Skip to content
This repository has been archived by the owner on Sep 30, 2021. It is now read-only.

Feature/410 button block #29

Merged
merged 5 commits into from
Jun 4, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion themes/wds_headless/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ function wds_theme_setup() {
);

// Disable background color gradient presets.
// See note above re: 'editor-color-palette'.
add_theme_support( 'editor-gradient-presets', [] );

// Reset available font size presets to only "normal" (16px).
Expand Down
19 changes: 15 additions & 4 deletions themes/wds_headless/js/blocks.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const { validateThemeColors } = wp.blockEditor;
const { useEffect } = wp.element;
const { addFilter } = wp.hooks;
const { addFilter, applyFilters } = wp.hooks;

/**
* Additional Gutenberg block functionality.
Expand All @@ -21,12 +21,12 @@ wp.domReady(() => {

addFilter(
"blocks.registerBlockType",
"wds/filterParagraphBlockAttrs1",
"wds/filterBlockColorAttrs",
wdsAddColorPaletteHexValues
);

/**
* Filter block registration to add custom color attributes to paragraph block.
* Filter block registration to add custom color attributes to specified blocks.
*
* TODO: Extend this to apply to other blocks that use the color palette.
*
Expand All @@ -35,7 +35,18 @@ addFilter(
* @return {object} Block settings config.
*/
function wdsAddColorPaletteHexValues(settings, name) {
if ("core/paragraph" !== name) {
/**
* Filter the array of blocks to receive hex color values.
*
* @author WebDevStudios
* @param {array} allowedBlocks Array of blocks.
*/
const allowedBlocks = applyFilters(
"wds/colorPaletteHexValuesAllowedBlocks",
["core/button", "core/paragraph"]
);

if (!allowedBlocks.includes(name)) {
return settings;
}

Expand Down