PluginProbe
Extendify / 3.0.4
Extendify v3.0.4
3.2.1 3.2.0 3.1.6 3.1.5 3.1.4 3.1.3 3.1.2 3.1.1 3.1.0 3.0.6 3.0.5 3.0.4 trunk 0.1.0 0.10.0 0.10.1 0.10.2 0.11.0 0.11.1 0.2.0 0.3.0 0.3.1 0.4.0 0.5.0 0.6.0 All 127 releases
extendify / src / Draft / api / WPApi.js

WPApi.js in Extendify 3.0.4, at src/Draft/api/WPApi.js

46 lines 1.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 import { createBlock, insertBlock } from '@wordpress/blocks';
2
3 export const addImageToBlock = (
4 selectedBlock,
5 image,
6 updateBlockAttributes,
7 ) => {
8 if (selectedBlock.name === 'core/image') {
9 updateBlockAttributes(selectedBlock.clientId, {
10 id: image.id,
11 caption: image.caption.raw,
12 url: image.source_url,
13 alt: image.alt_text,
14 });
15 }
16
17 if (selectedBlock.name === 'core/media-text') {
18 updateBlockAttributes(selectedBlock.clientId, {
19 mediaId: image.id,
20 caption: image.caption.raw,
21 mediaUrl: image.source_url,
22 mediaAlt: image.alt_text,
23 mediaType: 'image',
24 });
25 }
26
27 if (selectedBlock.name === 'core/gallery') {
28 const newBlock = createBlock('core/image', {
29 id: image.id,
30 caption: image.caption.raw,
31 url: image.source_url,
32 alt: image.alt_text,
33 });
34
35 insertBlock(newBlock, null, selectedBlock.clientId);
36 }
37
38 if (selectedBlock.name === 'core/cover') {
39 updateBlockAttributes(selectedBlock.clientId, {
40 id: image.id,
41 url: image.source_url,
42 alt: image.alt_text,
43 });
44 }
45 };
46