PHP 8.2.31
Preview: logo.js Size: 1.30 KB
/home/nshryvcy/radiantskinclinics.org/wp-content/plugins/extendify_old/src/Launch/lib/logo.js

import { getOption, updateOption } from '@launch/api/WPApi';
import { uploadMedia } from '@wordpress/media-utils';

/**
 * Uploads a logo to WordPress media library.
 * @param {string} url - The image URL (can be a blob or remote link)
 * @param {object} [options={}] - Additional options
 * @param {boolean} [options.forceReplace=false] - Replace existing logo even if one exists
 */
export const uploadLogo = async (url, options = {}) => {
	try {
		const id = await getOption('site_logo');
		if (!Number(id) || options.forceReplace) {
			// Transparent background is required — only these formats support it
			const allowedTypes = ['image/png', 'image/webp', 'image/avif'];

			const blob = await (await fetch(url)).blob();
			if (!allowedTypes.includes(blob.type)) {
				throw new Error(`Unsupported image type: ${blob.type}`);
			}

			const fileExtension = blob.type.replace('image/', '');
			const logoName = `ext-custom-logo-${Date.now()}`;

			await uploadMedia({
				filesList: [
					new File([blob], `${logoName}.${fileExtension}`, {
						type: blob.type,
					}),
				],
				onFileChange: async ([fileObj]) => {
					if (fileObj?.id) {
						await updateOption('site_logo', fileObj.id);
					}
				},
				onError: console.error,
			});
		}
	} catch (error) {
		console.error('Error uploading logo: ', error);
	}
};

Directory Contents

Dirs: 1 × Files: 8

Name Size Perms Modified Actions
__tests__ DIR
- drwxr-xr-x 2026-04-28 02:40:02
Edit Download
154 B lrw-r--r-- 2025-08-27 17:47:28
Edit Download
1.91 KB lrw-r--r-- 2025-08-04 19:41:52
Edit Download
6.71 KB lrw-r--r-- 2026-03-19 23:35:18
Edit Download
1.30 KB lrw-r--r-- 2026-02-19 03:27:14
Edit Download
2.23 KB lrw-r--r-- 2025-07-16 19:39:24
Edit Download
1.60 KB lrw-r--r-- 2025-02-04 00:18:34
Edit Download
1.92 KB lrw-r--r-- 2026-02-19 03:27:14
Edit Download
12.71 KB lrw-r--r-- 2026-02-27 04:48:52
Edit Download

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