# extendify/3.2.1/src/Agent/lib/block-code.js

Extendify, version 3.2.1. 23 lines.

- Page: https://pluginprobe.com/plugins/extendify/3.2.1/code/src/Agent/lib/block-code.js
- Raw: https://pluginprobe.com/plugins/extendify/3.2.1/raw/src/Agent/lib/block-code.js
- Modified: 2026-08-12T16:23:58+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.2.1/code/src/Agent/lib/block-code.js#L10-L20`.

```javascript
import apiFetch from '@wordpress/api-fetch';
import { addQueryArgs } from '@wordpress/url';

// Shared so the tool and DOMHighlighter build the same query args and can't drift.
export const blockCodeQueryArgs = (block, postId) => {
	if (!block?.id) return null;
	if (block.source?.kind === 'template-part') {
		const { partSlug } = block.source;
		return partSlug ? { blockId: String(block.id), partSlug } : null;
	}
	return postId ? { blockId: String(block.id), postId: String(postId) } : null;
};

// One block's current serialized code by TagBlocks id, scoped to the container's source.
export const fetchBlockCodeById = async (blockId, source, postId) => {
	const args = blockCodeQueryArgs({ id: blockId, source }, postId);
	if (!args) return '';
	const response = await apiFetch({
		path: addQueryArgs('/extendify/v1/agent/get-block-code', args),
	});
	return response?.block ?? '';
};

```
