(function ( wpI18n, wpHooks, wpElement, wpEditor, wpComponents ) { const { addFilter } = wpHooks; const { __ } = wpI18n; const { Fragment } = wpElement; const { InspectorControls } = wpEditor; const { PanelBody, Button } = wpComponents; // Register extra attributes addFilter( 'blocks.registerBlockType', 'advgb/registerExtraColumnsAttrs', function ( settings ) { if (settings.name === 'core/text-columns' || settings.name === 'core/columns') { settings.attributes = Object.assign( settings.attributes, { colMargin: { type: 'number', }, colPadding: { type: 'number', }, blockID: { type: 'string', }, } ); } return settings; } ); // Add options to edit in backend addFilter( 'editor.BlockEdit', 'advgb/editColumnsAttrs', function ( BlockEdit ) { return ( props ) => { if (props.name === "core/text-columns" || props.name === "core/columns") { const { attributes, clientId } = props; const { colMargin, colPadding } = attributes; return ( props.setAttributes( { colMargin: undefined, colPadding: undefined, blockID: undefined, } ) }> { __( 'Clear custom styles' ) } { __( 'We recommend to clear all custom styles as soon as possible to avoid block error validation,' + ' because we will remove this feature in very next version.' ) } {props.name === 'core/columns' && (!!colMargin || !!colPadding) && } ) } return ; } } ); // Save options to show in frontend addFilter( 'blocks.getSaveContent.extraProps', 'advgb/saveColumnsAttrs', function ( extraProps, blockType, attributes ) { const { colMargin, colPadding, blockID } = attributes; if (blockType.name === 'core/text-columns' || blockType.name === 'core/columns') { extraProps = Object.assign( extraProps, { id: (colMargin || colPadding || blockID) ? blockID : extraProps.id, } ) } return extraProps; } ); // Save option to show in frontend addFilter( 'blocks.getSaveElement', 'advgb/saveTextColumnsElm', function ( SaveElm, blockType, attributes ) { if (blockType.name === 'core/text-columns' || blockType.name === 'core/columns') { const { colMargin, colPadding, blockID } = attributes; return ( {SaveElm} {blockID && (!!colMargin || !!colPadding) && } ) } return SaveElm; } ); })( wp.i18n, wp.hooks, wp.element, wp.editor, wp.components );
{ __( 'We recommend to clear all custom styles as soon as possible to avoid block error validation,' + ' because we will remove this feature in very next version.' ) }