PHP 8.2.31
Preview: useThemeVariations.js Size: 1.14 KB
/home/nshryvcy/radiantskinclinics.org/wp-content/plugins/extendify_old/src/Agent/hooks/useThemeVariations.js

import apiFetch from '@wordpress/api-fetch';
import { __ } from '@wordpress/i18n';
import useSWRImmutable from 'swr/immutable';

const fetcher = async () => {
	const path = window.location.pathname;
	const s = new URLSearchParams(window.location.search);
	const onEditor =
		path.includes('/wp-admin/post.php') && s.get('action') === 'edit';

	const variations = await apiFetch({
		method: 'GET',
		// On the frontend we need to include layout styles
		path: `/extendify/v1/agent/theme-variations${onEditor ? '' : '?includeLayoutStyles'}`,
	});
	if (!variations || !Array.isArray(variations)) {
		throw new Error(__('Failed to fetch theme variations.', 'extendify-local'));
	}
	return {
		// remove duplicate variations by title
		variations: variations.reduce((acc, variation) => {
			if (!acc.some((v) => v.title === variation.title)) {
				acc.push(variation);
			}
			return acc;
		}, []),
	};
};

export const useThemeVariations = () => {
	const { data, error, isLoading } = useSWRImmutable(
		{
			key: 'theme-variations',
			themeSlug: window.extAgentData.context.themeSlug,
		},
		fetcher,
	);
	return { variations: data?.variations, error, isLoading };
};

Directory Contents

Dirs: 0 × Files: 12

Name Size Perms Modified Actions
3.77 KB lrw-r--r-- 2026-02-19 03:27:14
Edit Download
3.92 KB lrw-r--r-- 2026-03-19 23:35:18
Edit Download
1.11 KB lrw-r--r-- 2026-04-16 23:02:08
Edit Download
607 B lrw-r--r-- 2026-03-24 18:55:54
Edit Download
478 B lrw-r--r-- 2026-03-19 23:35:18
Edit Download
3.17 KB lrw-r--r-- 2026-02-19 03:27:14
Edit Download
2.39 KB lrw-r--r-- 2026-03-19 23:35:18
Edit Download
1.82 KB lrw-r--r-- 2026-02-19 03:27:14
Edit Download
1.17 KB lrw-r--r-- 2026-02-19 03:27:14
Edit Download
1.14 KB lrw-r--r-- 2025-09-09 19:55:14
Edit Download
3.14 KB lrw-r--r-- 2026-03-19 23:35:18
Edit Download
2.20 KB lrw-r--r-- 2026-03-05 22:57:38
Edit Download

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