PHP 8.2.31
Preview: WPApi.js Size: 1.00 KB
/home/nshryvcy/radiantskinclinics.org/wp-content/plugins/extendify_old/src/Draft/api/WPApi.js

import { createBlock, insertBlock } from '@wordpress/blocks';

export const addImageToBlock = (
	selectedBlock,
	image,
	updateBlockAttributes,
) => {
	if (selectedBlock.name === 'core/image') {
		updateBlockAttributes(selectedBlock.clientId, {
			id: image.id,
			caption: image.caption.raw,
			url: image.source_url,
			alt: image.alt_text,
		});
	}

	if (selectedBlock.name === 'core/media-text') {
		updateBlockAttributes(selectedBlock.clientId, {
			mediaId: image.id,
			caption: image.caption.raw,
			mediaUrl: image.source_url,
			mediaAlt: image.alt_text,
			mediaType: 'image',
		});
	}

	if (selectedBlock.name === 'core/gallery') {
		const newBlock = createBlock('core/image', {
			id: image.id,
			caption: image.caption.raw,
			url: image.source_url,
			alt: image.alt_text,
		});

		insertBlock(newBlock, null, selectedBlock.clientId);
	}

	if (selectedBlock.name === 'core/cover') {
		updateBlockAttributes(selectedBlock.clientId, {
			id: image.id,
			url: image.source_url,
			alt: image.alt_text,
		});
	}
};

Directory Contents

Dirs: 0 × Files: 2

Name Size Perms Modified Actions
1.13 KB lrw-r--r-- 2026-02-19 03:27:14
Edit Download
1.00 KB lrw-r--r-- 2025-10-23 20:20:58
Edit Download

If ZipArchive is unavailable, a .tar will be created (no compression).