-
-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #19 from MuluhGodson/custom_padding
Custom Margin and Paddign Settings
- Loading branch information
Showing
5 changed files
with
58 additions
and
142 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
// Enable spacing control on the following blocks | ||
const enableSpacingControlOnBlocks = [ | ||
'core/columns', | ||
'core/column', | ||
'core/group', | ||
]; | ||
|
||
/** | ||
* Add spacing control attribute to block. | ||
* | ||
* @param {object} settings Current block settings. | ||
* @param {string} name Name of block. | ||
* | ||
* @returns {object} Modified block settings. | ||
*/ | ||
const addSpacingControlAttribute = ( settings, name ) => { | ||
// Do nothing if it's another block than our defined ones. | ||
if ( ! enableSpacingControlOnBlocks.includes( name ) ) { | ||
return settings; | ||
} | ||
|
||
// Use Lodash's assign to gracefully handle if attributes are undefined | ||
settings = lodash.assign( settings, { | ||
supports: { | ||
spacing: { | ||
blockGap: true, | ||
margin: true, | ||
padding: true, | ||
} | ||
} | ||
} ); | ||
return settings; | ||
}; | ||
|
||
wp.hooks.addFilter( | ||
'blocks.registerBlockType', | ||
'custom-spacing', | ||
addSpacingControlAttribute | ||
); |
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
This file was deleted.
Oops, something went wrong.
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"version": 1, | ||
"settings": { | ||
"spacing": { | ||
"blockGap": true, | ||
"customPadding": true, | ||
"customMargin": true, | ||
"units": [ "px", "em", "rem", "vh", "vw" ] | ||
} | ||
} | ||
} |