[WordPress] 外掛分享: REST API Enabler

首頁外掛目錄 › REST API Enabler
200+
安裝啟用
★★★★★
5/5 分(3 則評價)
3544 天前
最後更新
問題解決
WordPress 3.5+ v1.1.0 上架:2015-10-08

內容簡介

喜歡這個外掛嗎? 請考慮給予 五星評價。

預設情況下,自訂文章類型和自訂欄位無法透過 WordPress REST API 存取。REST API Enabler 可讓您:

啟用 WP REST API 以存取自訂文章類型,並指定 WP REST API 自訂端點。
為文章、頁面和自訂文章類型選擇要包含在 WP REST API 回應中的自訂欄位。

在 REST API 回應中,所有啟用的自訂欄位資料都會以 rest_api_enabler 金鑰嵌套,如下所示:

[
{
"id": 179,
"date": "2016-07-03T18:06:50",
"title": {
"rendered": "Test Job"
},
.
.
.
"rest_api_enabler": {
"custom_meta_1": "Value 1",
"custom_meta_2": "Value 2",
"custom_meta_3": [
"Array value 1",
"Array value 2"
]
}
}
]

注意:在版本 1.1.0 之前,所有元資料鍵名都會被包含在 API 回應的頂層金鑰中。此外,無論原始值是否為陣列,所有值都將返回為陣列。這個功能現在已被標記為過時,因為它會造成鍵名衝突的風險。請改參考 rest_api_enabler 的頂層金鑰。

用法

啟用外掛,然後前往管理後台的「設定」→「REST API Enabler」。
按一下「文章類型」選項卡,以啟用/停用文章類型並自訂其端點。
按一下「文章屬性」選項卡,以啟用/停用文章屬性(自訂欄位)。

注意:預設情況下,此外掛不會顯示保護的文章屬性(以底線開頭且僅用於內部使用的文章屬性)的設定。如果您希望在外掛設定中包含保護的文章屬性,可以使用 rae_include_protected_meta 過濾器來實現。以下的代碼可以放置在你的佈景主題的 functions.php 檔案中,或者在自訂外掛中使用(在 init 優先級為 10 或更早之前):

add_filter( 'rae_include_protected_meta', '__return_true' );

外掛標籤

開發者團隊

⬇ 下載最新版 (v1.1.0) 或搜尋安裝

① 下載 ZIP → 後台「外掛 › 安裝外掛 › 上傳外掛」
② 後台搜尋「REST API Enabler」→ 直接安裝(推薦)
📦 歷史版本下載

原文外掛簡介

Like this plugin? Please consider leaving a 5-star review.
By default, custom post types and custom fields are not accessible via the WordPress REST API. REST API Enabler allows you to:

Enable the WP REST API for custom post types and specify WP REST API custom endpoints.
Choose which custom fields to include in WP REST API responses for posts, pages, and custom post types.

All enabled custom field data is included in the REST API response, nested under the rest_api_enabler key, like so:
[
{
"id": 179,
"date": "2016-07-03T18:06:50",
"title": {
"rendered": "Test Job"
},
.
.
.
"rest_api_enabler": {
"custom_meta_1": "Value 1",
"custom_meta_2": "Value 2",
"custom_meta_3": [
"Array value 1",
"Array value 2"
]
}
}
]

Note: prior to verion 1.1.0, all meta keys were included as top-level keys in the API response. Additionally, all values were returned as arrays, regardless of whether the original value was actually an array. This functionality is now deprecated as it risks key-name collisions. Please reference the rest_api_enabler top-level key instead.
Usage

Activate the plugin, then go to Settings → REST API Enabler in the admin.
Click the Post Types tab to enable/disable post types and customize their endpoints.
Click the Post Meta tab to enable/disable post meta (custom fields).

NOTE: by default, the plugin does not display settings for protected post meta (post meta that begins with an underscore and is intended for internal use only). If you wish to include protected post meta in the plugin settings, you can use the rae_include_protected_meta filter to do so. The following code can be placed in your theme’s functions.php file, or in a custom plugin (on init priority 10 or earlier):
add_filter( 'rae_include_protected_meta', '__return_true' );

延伸相關外掛

文章
Filter
Apply Filters
Mastodon