![]() Server : Apache System : Linux server2.corals.io 4.18.0-348.2.1.el8_5.x86_64 #1 SMP Mon Nov 15 09:17:08 EST 2021 x86_64 User : corals ( 1002) PHP Version : 7.4.33 Disable Function : exec,passthru,shell_exec,system Directory : /home/corals/mets.corals.io/wp-content/plugins/block-options/src/blocks/import/utils/ |
/** * WordPress dependencies */ const { select, dispatch } = wp.data; const { parse, createBlock } = wp.blocks; export default function insertImportedBlocks( clientId, blocks, onClose ) { blocks = parse( blocks ); const toSelect = []; const blockIndex = select( 'core/block-editor' ).getBlockInsertionPoint(); if ( blocks.length > 0 ) { for ( const block in blocks ) { const created = createBlock( blocks[ block ].name, blocks[ block ].attributes, blocks[ block ].innerBlocks ); dispatch( 'core/block-editor' ).insertBlocks( created, parseInt( blockIndex.index ) + parseInt( block ) ); if ( typeof created !== 'undefined' ) { toSelect.push( created.clientId ); } } //remove insertion point if empty dispatch( 'core/block-editor' ).removeBlock( clientId ); //select inserted blocks if ( toSelect.length > 0 ) { dispatch( 'core/block-editor' ).multiSelect( toSelect[ 0 ], toSelect.reverse()[ 0 ] ); } } onClose(); }