前言介紹
- 這款 WordPress 外掛「WP REST Menus」是 2018-07-03 上架。
- 目前有 100 個安裝啟用數。
- 上一次更新是 2022-02-17,距離現在已有 1171 天。超過一年沒更新,安裝要確認版本是否可用。以及後續維護問題!
- 外掛最低要求 WordPress 5.0 以上版本才可以安裝。
- 外掛要求網站主機運作至少需要 PHP 版本 5.6 以上。
- 有 4 人給過評分。
- 還沒有人在論壇上發問,可能目前使用數不多,還沒有什麼大問題。
外掛協作開發者
skapator |
外掛標籤
v2 | api | wp-rest-api | wp-rest-menus |
內容簡介
此外掛為 WordPress 註冊選單新增端點。
建置 Vuejs、React 或任何前端框架 SPA 時相當有用。
與 Advacned Custom Fields、WPML、Polylang 相容。
新增的端點如下:
取得所有選單
GET /menus/v1/menus
// 回應範例
{
term_id: 2,
name: "主選單",
slug: "main-menu",
term_group: 0,
term_taxonomy_id: 2,
taxonomy: "nav_menu",
description: "",
parent: 0,
count: 8,
filter: "raw"
},
...
藉由編號 (term_id) 取得選單項目
GET /menus/v1/menus/
// 回應範例
{
ID: 5,
post_author: "1",
post_date: "2018-07-03 06:42:18",
post_date_gmt: "2018-07-03 06:42:18",
filter: "raw",
db_id:5,
menu_item_parent: "0",
object_id: "5",
object: "custom",
type: "custom",
type_label: "Custom Link",
title: "首頁",
url: "https:\/\/wp-rest-menu.local\/",
target: "",
attr_title: "",
description: "",
classes: [
""
],
xfn: "",
meta: null
},
...
取得所有選單位置
顯示在 /wp-admin/nav-menus.php?action=locations 分派的所有選單位置
GET /menus/v1/menus/locations 已被廢棄,請使用以下端點:
GET /menus/v1/locations
// 回應範例
{
slug: "top",
description: "頂部選單"
},
{
slug: "social",
description: "社交欄目"
}
...
取得所有選單位置項目
在 /wp-admin/nav-menus.php?action=locations 中分派的所有選單位置
GET /menus/v1/menus/locations/
GET /menus/v1/locations/
// 回應範例
{
ID: 5,
post_author: "1",
post_date: "2018-07-03 06:42:18",
post_date_gmt: "2018-07-03 06:42:18",
filter: "raw",
db_id:5,
menu_item_parent: "0",
object_id: "5",
object: "custom",
type: "custom",
type_label: "Custom Link",
title: "首頁",
url: "https:\/\/wp-rest-menu.local\/",
target: "",
attr_title: "",
description: "",
classes: [
""
],
xfn: "",
meta: null
},
...
兩種篩選器皆可用:
依欄位篩選器
// 回傳只有指定欄位
GET /menus/v1/menus/
// 回應範例
// Response sample
{
ID: 5,
title: "首頁",
meta: null
},
...
巢狀項目篩選器
// 回傳選單項目之父項目和巢狀兒子在 'children' 欄位中
// 目前只支援一層
GET /menus/v1/menus/
// 回應範例
{
ID: 1716,
menu_item_parent: "0",
object_id: "174",
object: "page",
title: "第 1 層",
meta: {
vue_component: "LevelComponent",
menu-item-field-01: "Field 1 value",
menu-item-field-02: "Field 2 value"
},
children:[
{
ID: 1717,
menu_item_parent: "1716",
object_id: "744",
object: "page",
title: "第 2 層 b",
meta : {
vue_components: "Level 1 Component"
}
}
]
},
...
原文外掛簡介
This plugin adds new endpoints for WordPress registered menus.
Usefull when building SPAs with Vuejs, React or any front-end framework.
Works with Advacned Custom Fields, WPML, Polylang
The new endpoints available:
Get all menus
GET /menus/v1/menus
// Response sample
{
term_id: 2,
name: "Main Menu",
slug: "main-menu",
term_group: 0,
term_taxonomy_id: 2,
taxonomy: "nav_menu",
description: "",
parent: 0,
count: 8,
filter: "raw"
},
...
Get a menus items by id (term_id)
GET /menus/v1/menus/
// Response sample
{
ID: 5,
post_author: "1",
post_date: "2018-07-03 06:42:18",
post_date_gmt: "2018-07-03 06:42:18",
filter: "raw",
db_id:5,
menu_item_parent: "0",
object_id: "5",
object: "custom",
type: "custom",
type_label: "Custom Link",
title: "Home",
url: "https:\/\/wp-rest-menu.local\/",
target: "",
attr_title: "",
description: "",
classes: [
""
],
xfn: "",
meta: null
},
...
Get all menu locations
All menu locations assigned in /wp-admin/nav-menus.php?action=locations
GET /menus/v1/menus/locations is deprecated and will be removed in newer versions use:
GET /menus/v1/locations
// Response example
{
slug: "top",
description: "Top Menu"
},
{
slug: "social",
description: "Social Links Menu"
}
...
Get all menu location items
All menu locations assigned in /wp-admin/nav-menus.php?action=locations
GET /menus/v1/menus/locations/
GET /menus/v1/locations/
// Response samexampleple
{
ID: 5,
post_author: "1",
post_date: "2018-07-03 06:42:18",
post_date_gmt: "2018-07-03 06:42:18",
filter: "raw",
db_id:5,
menu_item_parent: "0",
object_id: "5",
object: "custom",
type: "custom",
type_label: "Custom Link",
title: "Home",
url: "https:\/\/wp-rest-menu.local\/",
target: "",
attr_title: "",
description: "",
classes: [
""
],
xfn: "",
meta: null
},
...
There are two filters availiable:
Fields Filter
// it will return only the fields specified
GET /menus/v1/menus/
// Response sample
// Response sample
{
ID: 5,
title: "Home",
meta: null
},
...
Nested Items Filter
// it will return menu items parents and nested children in a 'children' field
// Currently only one level deep is supported
GET /menus/v1/menus/
// Response sample
{
ID: 1716,
menu_item_parent: "0",
object_id: "174",
object: "page",
title: "Level 1",
meta: {
vue_component: "LevelComponent",
menu-item-field-01: "Field 1 value",
menu-item-field-02: "Field 2 value"
},
children:[
{
ID: 1717,
menu_item_parent: "1716",
object_id: "744",
object: "page",
title: "Level 2b",
meta : {
vue_component: null
}
},
...
]
},
...
WP filter hooks
This plugin is quite configurable and provides lots of wp filter hooks from returned data in responses for each endpoint to params validation and endpoint permissions.
add_filter( 'wprm/get_menus/wp_get_nav_menus/args', 'my_wp_get_nav_menus', 10, 1 );
(used in GET /menus/v1/menus)
function my_wp_get_nav_menus( $args ) {
// do something with wp_get_nav_menus $args array
return $args;
}
add_filter( 'wprm/get_menus', 'my_get_menus', 10, 1 );
(used in GET /menus/v1/menus)
function my_get_menus( $menus ) {
// do something with $menus array
return $menus; // WP_Error|WP_HTTP_Response|WP_REST_Response|mixed
}
add_filter( 'wprm/get_menu_locations', 'my_get_menu_locations', 10, 1 );
(used in GET /menus/v1/locations)
function my_get_menu_locations( $locations ) {
// You can modify the $locations array response (get_registered_nav_menus())
return $locations; // WP_Error|WP_HTTP_Response|WP_REST_Response|mixed
}
add_filter( 'wprm/get_menu_items', 'my_get_menu_items', 10, 1 );
(used in GET /menus/v1/menus/
function my_rest_menu_item_fields( $menu ) {
// You can modify the $menu items
return $menu;
}
add_filter( 'wprm/get_location_menu_items', 'my_get_location_menu_items', 10, 1 );
(used in GET /menus/v1/menus/
function my_get_location_menu_items( $menu ) {
// You can modify the locations $menu items
return $menu;
}
add_filter( 'wprm/get_item_fields/filter_fields', 'my_filter_fields', 10, 1 );
(used to filter return field -node edges-)
function my_filter_fields( $fields ) {
// You can modify the $fields array so
// you can filter the return fields for all endpoints
// without using the url param ?fields
$fields = array( 'ID', 'title' );
return $fields;
}
More filters
apply_filters('wprm/get_menus/permissions', '__return_true', $request );
apply_filters('wprm/get_menu_locations/permissions', '__return_true', $request );
apply_filters('wprm/get_menu_items/permissions', '__return_true', $request );
apply_filters('wprm/get_menu_items/validate/args/id', is_numeric( $param ), $param, $request, $key );
apply_filters('wprm/get_menu_items/validate/args/fields', is_string( $param ), $param, $request, $key );
apply_filters('wprm/get_menu_items/validate/args/nested', absint( $param ), $param, $request, $key );
apply_filters('wprm/get_location_menu_items/permissions', '__return_true', $request );
apply_filters('wprm/get_location_menu_items/validate/args/slug', is_string( $param ), $param, $request, $key );
apply_filters('wprm/get_location_menu_items/validate/args/fields', is_string( $param ), $param, $request, $key );
apply_filters('wprm/get_location_menu_items/validate/args/nested', absint( $param ), $param, $request, $key );
apply_filters('wprm/get_location_menu_items/permissions', '__return_true', $request );
apply_filters('wprm/get_location_menu_items/validate/args/slug', is_string( $param ), $param, $request, $key );
apply_filters('wprm/get_location_menu_items/validate/args/fields', is_string( $param ), $param, $request, $key );
apply_filters('wprm/get_location_menu_items/validate/args/nested', absint( $param ), $param, $request, $key );
Supports custom fields and Advanced Custom Fields
If ACF is installed the response node edge is acf else meta
In newer version these two edges will co exist and the plugin will separate natively registered custom fields ad acf registered ones.
各版本下載點
- 方法一:點下方版本號的連結下載 ZIP 檔案後,登入網站後台左側選單「外掛」的「安裝外掛」,然後選擇上方的「上傳外掛」,把下載回去的 ZIP 外掛打包檔案上傳上去安裝與啟用。
- 方法二:透過「安裝外掛」的畫面右方搜尋功能,搜尋外掛名稱「WP REST Menus」來進行安裝。
(建議使用方法二,確保安裝的版本符合當前運作的 WordPress 環境。
1.0 | 1.0.1 | 1.0.2 | 1.0.3 | 1.0.4 | trunk |
延伸相關外掛(你可能也想知道)
ACF to REST API 》此 WordPress 外掛在WordPress REST API中提供了Advanced Custom Fields的端點, 詳細資訊請參閱GitHub:https://github.com/airesvsg/acf-to-rest-api/。
WP REST Cache 》如果您在使用 WordPress REST API 時遇到速度問題,這個外掛將允許 WordPress 快取 REST API 的回應,使其更快。, 此外掛提供以下功能:, , 快取所有預設的 W...。
REST API Log 》這是一款針對 WordPress REST API v2 的外掛程式,可記錄 REST API 的請求和回應紀錄。, 功能包括:, , WordPress 管理頁面,用於查看和搜尋日誌條目, API 端...。
WP API SwaggerUI 》SwaggerUI 可以讓 WordPress REST API 端點擁有互動式的使用者介面,因此我們可以直接從網站上檢查 API 端點。, 功能特色:, , 支援 GET、POST、PUT、PATCH ...。
WP API Menus 》此外掛擴充了 WordPress JSON REST API,並提供 WordPress 註冊選單的新路徑。, 現在提供的新路徑如下:, , /menus 所有已註冊選單的清單。, /menus/
REST API Toolbox 》此外掛允許調整多個 REST API 設定, , 停用 REST API, 移除 WordPress 核心端點, 需要核心端點驗證, 強制使用 SSL, WP-CLI 命令: wp rest-api-toolbox, , 在 ...。
WP REST Yoast Meta 》您是否使用 WordPress 進行無頭設置,使用 WP REST API?您是否也想像其他項目一樣使用 Yoast SEO 外掛程式?此外掛會將 Yoast SEO 外掛所生成的元標記新增至...。
WP REST API Cache 》啟用 WordPress REST API 快取並提升應用程式的速度。, 詳情請參閱 GitHub:http://github.com/airesvsg/wp-rest-api-cache。
WPML to WP API 》這個外掛可以讓你使用「lang」變數從 WP-API (WP-JSON-API) 取得正確語言版本的 WP 內容,前提是 WPML 和 WP-API 已經安裝好了。以下是我測試過的最新版本:,...。
Advanced WP REST API 》Advanced WP REST API 是提供 WordPress REST API 自訂端點的外掛。您可以透過方便的設定面板啟用 API 路徑,並管理 API 請求和回應。, 主要功能:, , , 驗證...。
WP-REST-API Menus 》此外掛新增了「路徑」或「終點」至 WP REST API,以 JSON 格式檢索選單資料。, 此為 Claudio La Barbera (http://www.claudiolabarbera.com) 的 WP-REST-API ...。
API Log Pro 》這個外掛程式可以記錄所有呼叫 WordPress REST API 的紀錄,您可以在 WordPress 管理介面下的 API Log Pro 檢視所有紀錄。, 支援 WP-CLI, 此外掛提供基本的 W...。
WP API (V2) isFront 》此外掛擴充了WordPress JSON REST API,提供了新的端點以支援 WordPress 的 isFront 頁面屬性。。
WP API Options 》這個外掛擴展了 WordPress JSON REST API,為 WordPress 選項新增了新的路由。。
WP REST API multilanguage (over WMPL) 》 此外掛允許您使用 "lang" 變數來提取 WP REST API 呼叫。 , 它將檢索來自 WPML 的正確內容。, 此外掛已通過以下的最新版本測試:, , WPML 3.2.7, WP REST API...。