# extendify/3.1.0/src/AutoLaunch/hooks/useInstallRequiredPlugins.js

Extendify, version 3.1.0. 40 lines.

- Page: https://pluginprobe.com/plugins/extendify/3.1.0/code/src/AutoLaunch/hooks/useInstallRequiredPlugins.js
- Raw: https://pluginprobe.com/plugins/extendify/3.1.0/raw/src/AutoLaunch/hooks/useInstallRequiredPlugins.js
- Modified: 2026-06-11T18:37:12+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/extendify/3.1.0/code/src/AutoLaunch/hooks/useInstallRequiredPlugins.js#L10-L20`.

```javascript
import { handleSitePlugins } from '@auto-launch/fetchers/get-plugins';
import { activatePlugin, installPlugin } from '@auto-launch/functions/plugins';
import { useEffect, useRef } from '@wordpress/element';
import useSWR from 'swr/immutable';

const { installedPluginsSlugs } = window.extSharedData || {};

export const useInstallRequiredPlugins = () => {
	const { data, error } = useSWR('required-plugins', () =>
		handleSitePlugins({ requiredOnly: true }),
	);
	const started = useRef(false);

	useEffect(() => {
		if (started.current || !data?.sitePlugins?.length) return;
		started.current = true;
		const install = async () => {
			for (const { wordpressSlug: slug } of data.sitePlugins) {
				// One plugin failing shouldn't block the rest of the required set.
				try {
					let plugin;
					if (!installedPluginsSlugs?.includes(slug)) {
						plugin = await installPlugin(slug);
					}
					await activatePlugin(plugin?.plugin ?? slug);
				} catch (error) {
					console.error(`Failed to set up required plugin ${slug}`, error);
				}
			}
		};
		install();
	}, [data]);

	return {
		requiredPlugins: data?.selectedPlugins || [],
		isLoading: !error && !data,
		isError: error,
	};
};

```
