# extendify/3.0.6/src/PageCreator/util/insert.js

Extendify, version 3.0.6. 22 lines.

- Page: https://pluginprobe.com/plugins/extendify/3.0.6/code/src/PageCreator/util/insert.js
- Raw: https://pluginprobe.com/plugins/extendify/3.0.6/raw/src/PageCreator/util/insert.js
- Modified: 2025-03-13T17:10:44+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/extendify/3.0.6/code/src/PageCreator/util/insert.js#L10-L20`.

```javascript
import { dispatch, select } from '@wordpress/data';

export const insertBlocks = async (blocks) => {
	const { insertBlocks, replaceBlock } = dispatch('core/block-editor');
	const {
		getSelectedBlock,
		getBlockHierarchyRootClientId,
		getBlockIndex,
		getGlobalBlockCount,
	} = select('core/block-editor');

	const { clientId, name, attributes } = getSelectedBlock() || {};
	const rootClientId = clientId ? getBlockHierarchyRootClientId(clientId) : '';
	const insertPointIndex =
		(rootClientId ? getBlockIndex(rootClientId) : getGlobalBlockCount()) + 1;

	if (name === 'core/paragraph' && attributes?.content === '') {
		return await replaceBlock(clientId, blocks);
	}
	return await insertBlocks(blocks, insertPointIndex);
};

```
