PluginProbe
Extendify / 3.1.5
Extendify v3.1.5
3.2.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 All 127 releases
extendify / src / Agent / abilities / site-info.js

site-info.js in Extendify 3.1.5, at src/Agent/abilities/site-info.js

76 lines 2.1 KB
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 { decodeEntities } from '@wordpress/html-entities';
3 import { __ } from '@wordpress/i18n';
4
5 const paths = {
6 settings: '/wp/v2/settings?context=edit',
7 themes: '/wp/v2/themes?status=active',
8 plugins: '/wp/v2/plugins',
9 };
10
11 const facts = {
12 title: { from: 'settings', read: (settings) => settings.title },
13 tagline: { from: 'settings', read: (settings) => settings.description },
14 url: { from: 'settings', read: (settings) => settings.url },
15 language: { from: 'settings', read: (settings) => settings.language },
16 timezone: { from: 'settings', read: (settings) => settings.timezone },
17 frontPage: {
18 from: 'settings',
19 read: (settings) =>
20 settings.show_on_front === 'page'
21 ? { shows: 'page', pageId: settings.page_on_front }
22 : { shows: 'posts' },
23 },
24 theme: {
25 from: 'themes',
26 read: (themes) => decodeEntities(themes[0]?.name?.rendered ?? ''),
27 },
28 plugins: {
29 from: 'plugins',
30 read: (plugins) =>
31 plugins.map(({ name, status }) => ({
32 name: decodeEntities(name),
33 status,
34 })),
35 },
36 wpVersion: { read: () => window.extSharedData.wpVersion },
37 };
38
39 export const siteInfo = {
40 name: 'extendify/site-info',
41 label: __('Site details', 'extendify-local'),
42 description:
43 'What this WordPress site is: its title, tagline, address, language, timezone, active theme, installed plugins, WordPress version, and what its front page shows.',
44 inputSchema: {
45 type: 'object',
46 properties: {
47 include: {
48 type: 'array',
49 items: { type: 'string', enum: Object.keys(facts) },
50 description: 'Which of these to return. Omit it for all of them.',
51 },
52 },
53 },
54 annotations: { readonly: true },
55 execute: async ({ include } = {}) => {
56 const wanted = include?.length
57 ? include.filter((key) => facts[key])
58 : Object.keys(facts);
59 const sources = [
60 ...new Set(wanted.map((key) => facts[key].from).filter(Boolean)),
61 ];
62 const read = Object.fromEntries(
63 await Promise.all(
64 sources.map(async (source) => [
65 source,
66 await apiFetch({ path: paths[source] }),
67 ]),
68 ),
69 );
70
71 return Object.fromEntries(
72 wanted.map((key) => [key, facts[key].read(read[facts[key].from])]),
73 );
74 },
75 };
76