Advertisement
Guest User

Wordpress bug?

a guest
Mar 30th, 2020
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.48 KB | None | 0 0
  1. import assign from 'lodash.assign';
  2.  
  3. const { __ } = wp.i18n;
  4. const { registerBlockType } = wp.blocks;
  5. const { InspectorControls } = wp.blockEditor;
  6. const { Component, Fragment } = wp.element;
  7. const { RangeControl } = wp.components;
  8.  
  9. wp.hooks.addFilter(
  10. 'blocks.registerBlockType',
  11. 'elder/thicknessAttribute',
  12. settings => {
  13. if(settings.name === 'core/separator') {
  14. settings.attributes = {
  15. ...settings.attributes,
  16. elderThickness: {
  17. type: 'number',
  18. default: 1,
  19. },
  20. };
  21. }
  22. return settings;
  23. }
  24. );
  25.  
  26. wp.hooks.addFilter(
  27. 'editor.BlockEdit',
  28. 'elder/thicknessInput',
  29. wp.compose.createHigherOrderComponent(
  30. BlockEdit => props => {
  31. if(props.name === 'core/separator') {
  32. return (
  33. <Fragment>
  34. <BlockEdit {...props} />
  35.  
  36. <InspectorControls>
  37. <RangeControl
  38. label="Thickness"
  39. min={ 1 }
  40. max={ 10 }
  41. value={props.attributes.elderThickness}
  42. onChange={nextRel => props.setAttributes({elderThickness: nextRel})}
  43. />
  44. </InspectorControls>
  45.  
  46. </Fragment>
  47. );
  48. }
  49. return <BlockEdit {...props} />;
  50. },
  51. 'withelderThicknessInput'
  52. )
  53. );
  54.  
  55. wp.hooks.addFilter( 'blocks.getSaveContent.extraProps', 'elder/rel', ( element, block, attributes ) => {
  56.  
  57. if(block.name === 'core/separator') {
  58. if(attributes.elderThickness) {
  59. assign( element, { style: { 'borderTopWidth': attributes.elderThickness } } );
  60. }
  61. }
  62.  
  63. return element;
  64. } )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement