PluginProbe
Extendify / 2.2.0
Extendify v2.2.0
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 / workflows / theme / tools / get-menu-items.js

get-menu-items.js in Extendify 2.2.0, at src/Agent/workflows/theme/tools/get-menu-items.js

31 lines 782 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
3 const postTypes = { page: 'pages', post: 'posts' };
4
5 export default async ({ postId, postType }) => {
6 // Get all nav menus that are presented in the post/page.
7 const postNavigations = Array.from(
8 window.document?.querySelectorAll('nav[data-extendify-menu-id]') ?? [],
9 )
10 .map((nav) => nav.dataset.extendifyMenuId)
11 .filter(Boolean);
12
13 // get the data about those nav menus
14 const navigations =
15 (await apiFetch({
16 method: 'POST',
17 path: '/extendify/v1/agent/site-navigation',
18 data: { only: postNavigations.join(',') },
19 })) ?? [];
20
21 const postInfo = await apiFetch({
22 path: `/wp/v2/${postTypes[postType]}/${postId}`,
23 });
24
25 return {
26 navigations,
27 postTitle: postInfo.title.rendered,
28 postURL: postInfo.link,
29 };
30 };
31