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

import blockStyleVariations from '@launch/_data/block-style-variations.json';
import apiFetch from '@wordpress/api-fetch';
import useSWRImmutable from 'swr/immutable';

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

const fetcher = async () => {
	const stylesResponse = await apiFetch({
		path: '/wp/v2/global-styles/themes/extendable?context=edit',
	});

	const styles = stylesResponse?.styles;
	if (!styles?.blocks) return null;

	const optionsResponse = await apiFetch({
		path: '/extendify/v1/launch/options?option=extendify_siteStyle',
	});

	const currentVibe = optionsResponse?.data?.vibe;

	return {
		vibes: extractVibesFromTheme(styles),
		css: { ...blockStyleVariations },
		currentVibe: currentVibe || 'natural-1',
	};
};

const extractVibesFromTheme = (themeStyles) => {
	if (!themeStyles?.blocks) return [];

	const vibeSet = new Set();
	const { blocks } = themeStyles;

	// Scan all blocks for vibe variations
	for (const blockObj of Object.values(blocks)) {
		if (!blockObj?.variations) continue;

		for (const styleName of Object.keys(blockObj.variations)) {
			if (!styleName.startsWith('ext-preset--')) continue;

			// Split the slug: ext-preset--group--gradient-1--item-card-1--align-center
			const parts = styleName.split('--');

			if (parts.length >= 4) {
				const vibe = parts[2]; // 'gradient-1' ← This is what we want!
				if (vibe) vibeSet.add(vibe);
			}
		}
	}

	return Array.from(vibeSet).map((slug) => ({
		name: slugToDisplayName(slug), // "gradient-1" → "Gradient 1"
		slug,
	}));
};

const slugToDisplayName = (slug) =>
	slug
		.split('-')
		.map((word) => word.charAt(0).toUpperCase() + word.slice(1))
		.join(' ');

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).