����JFIF���������
__ __ __ __ _____ _ _ _____ _ _ _ | \/ | \ \ / / | __ \ (_) | | / ____| | | | | | \ / |_ __\ V / | |__) | __ ___ ____ _| |_ ___ | (___ | |__ ___| | | | |\/| | '__|> < | ___/ '__| \ \ / / _` | __/ _ \ \___ \| '_ \ / _ \ | | | | | | |_ / . \ | | | | | |\ V / (_| | || __/ ____) | | | | __/ | | |_| |_|_(_)_/ \_\ |_| |_| |_| \_/ \__,_|\__\___| |_____/|_| |_|\___V 2.1 if you need WebShell for Seo everyday contact me on Telegram Telegram Address : @jackleetFor_More_Tools:
import { rawHandler, serialize } from '@wordpress/blocks';
export const walkAndUpdateImageDetails = (inputs, newImage) => {
const blocks = rawHandler({ HTML: inputs.previousContent });
const parser = new DOMParser();
const walk = (blocks) =>
blocks.map((block) => {
if (['core/image', 'core/cover'].includes(block.name)) {
const attrs = { ...block.attributes };
const url = inputs.url.includes('unsplash.com')
? inputs.url.split('?')[0] // For unsplash just match the base URL
: inputs.url;
const isMatchingId = attrs.id === inputs.imageId;
const isMatchingUrl = attrs.url.startsWith(url);
if (!isMatchingId && !isMatchingUrl) {
// Not our image, return as is
return { ...block, attributes: attrs };
}
attrs.url = newImage.source_url || newImage.url;
attrs.id = newImage.id;
// Remove import class if present
if (attrs.className) {
attrs.className = attrs.className
.split(' ')
.filter((cn) => cn !== 'extendify-image-import')
.join(' ');
}
// originalContent needs wp-image-{id} to match the new ID
const originalContentDoc = parser.parseFromString(
attrs.originalContent || block.originalContent || '',
'text/html',
);
const img = originalContentDoc.querySelector('img');
if (!img) return { ...block, attributes: attrs };
// cover block wont have an image here
img.setAttribute('src', newImage.source_url || newImage.url);
const classList = img.className
.split(' ')
.filter((cn) => cn !== `wp-image-${inputs.imageId}`);
classList.push(`wp-image-${newImage.id}`);
img.className = classList.join(' ');
attrs.originalContent = originalContentDoc.body.innerHTML;
return { ...block, attributes: attrs };
}
if (['core/media-text'].includes(block.name)) {
const attrs = { ...block.attributes };
const url = inputs.url.includes('unsplash.com')
? inputs.url.split('?')[0] // For unsplash just match the base URL
: inputs.url;
// media-text block may not have all the attributes if the image was external.
const isMatchingId = attrs?.mediaId === inputs.imageId;
const isMatchingMediaLink = attrs?.mediaLink?.startsWith(url);
const isMatchingMediaUrl = attrs?.mediaUrl?.startsWith(url);
if (!isMatchingId && !isMatchingMediaLink && !isMatchingMediaUrl) {
// Not our image, return as is
return { ...block, attributes: attrs };
}
attrs.mediaLink = newImage.source_url || newImage.url;
attrs.mediaUrl = newImage.source_url || newImage.url;
attrs.mediaId = newImage.id;
// Remove import class if present
if (attrs.className) {
attrs.className = attrs.className
.split(' ')
.filter((cn) => cn !== 'extendify-image-import')
.join(' ');
}
return { ...block, attributes: attrs };
}
if (block.innerBlocks && block.innerBlocks.length > 0) {
return {
...block,
innerBlocks: walk(block.innerBlocks),
};
}
return block;
});
const updatedBlocks = walk(blocks);
return serialize(updatedBlocks);
};
| Name | Type | Size | Permission | Actions |
|---|---|---|---|---|
| abilities.js | File | 663 B | 0644 |
|
| blocks.js | File | 3.01 KB | 0644 |
|
| confetti.js | File | 1.46 KB | 0644 |
|
| domain-suggestion.js | File | 2.5 KB | 0644 |
|
| editor.js | File | 746 B | 0644 |
|
| markdown.js | File | 670 B | 0644 |
|
| media.js | File | 1.48 KB | 0644 |
|
| page-tours.js | File | 723 B | 0644 |
|
| redirects.js | File | 640 B | 0644 |
|
| svg-blocks-scanner.js | File | 2.07 KB | 0644 |
|
| svg-helpers.js | File | 4.91 KB | 0644 |
|
| tool-messages.js | File | 830 B | 0644 |
|
| tour-helpers.js | File | 461 B | 0644 |
|
| util.js | File | 537 B | 0644 |
|
| wp.js | File | 420 B | 0644 |
|