PluginProbe
Extendify / 1.17.1
Extendify v1.17.1
3.2.0 3.1.6 3.1.5 3.1.4 3.1.3 3.1.2 3.1.1 3.1.0 3.0.6 3.0.5 3.0.4 trunk 0.1.0 0.10.0 0.10.1 0.10.2 0.11.0 0.11.1 0.2.0 0.3.0 0.3.1 0.4.0 0.5.0 0.6.0 0.7.0 All 126 releases
extendify / src / Shared / api / wp.js

wp.js in Extendify 1.17.1, at src/Shared/api/wp.js

37 lines 704 B
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 import apiFetch from '@wordpress/api-fetch';
2 import { addQueryArgs } from '@wordpress/url';
3
4 export const getPlugin = async (slug) => {
5 const response = await apiFetch({
6 path: addQueryArgs('/wp/v2/plugins', { search: slug }),
7 });
8
9 let plugin = response?.[0];
10
11 if (!plugin) throw new Error('Plugin not found');
12
13 return plugin;
14 };
15
16 export const installPlugin = async (slug) => {
17 return await apiFetch({
18 path: '/wp/v2/plugins',
19 method: 'POST',
20 data: {
21 slug,
22 },
23 });
24 };
25
26 export const activatePlugin = async (slug) => {
27 const plugin = await getPlugin(slug);
28
29 return await apiFetch({
30 path: `/wp/v2/plugins/${plugin.plugin}`,
31 method: 'POST',
32 data: {
33 status: 'active',
34 },
35 });
36 };
37