# extendify/1.17.1/src/Shared/api/wp.js

Extendify, version 1.17.1. 37 lines.

- Page: https://pluginprobe.com/plugins/extendify/1.17.1/code/src/Shared/api/wp.js
- Raw: https://pluginprobe.com/plugins/extendify/1.17.1/raw/src/Shared/api/wp.js
- Modified: 2025-02-03T19:18:34+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/1.17.1/code/src/Shared/api/wp.js#L10-L20`.

```javascript
import apiFetch from '@wordpress/api-fetch';
import { addQueryArgs } from '@wordpress/url';

export const getPlugin = async (slug) => {
	const response = await apiFetch({
		path: addQueryArgs('/wp/v2/plugins', { search: slug }),
	});

	let plugin = response?.[0];

	if (!plugin) throw new Error('Plugin not found');

	return plugin;
};

export const installPlugin = async (slug) => {
	return await apiFetch({
		path: '/wp/v2/plugins',
		method: 'POST',
		data: {
			slug,
		},
	});
};

export const activatePlugin = async (slug) => {
	const plugin = await getPlugin(slug);

	return await apiFetch({
		path: `/wp/v2/plugins/${plugin.plugin}`,
		method: 'POST',
		data: {
			status: 'active',
		},
	});
};

```
