前言介紹
- 這款 WordPress 外掛「Simple Posts API」是 2014-11-17 上架。
- 目前有 10 個安裝啟用數。
- 上一次更新是 2014-11-18,距離現在已有 3820 天。超過一年沒更新,安裝要確認版本是否可用。以及後續維護問題!
- 外掛最低要求 WordPress 3.5 以上版本才可以安裝。
- 尚未有人給過這款外掛評分。
- 還沒有人在論壇上發問,可能目前使用數不多,還沒有什麼大問題。
外掛協作開發者
外掛標籤
api | ajax | rest | posts | RESTful |
內容簡介
隨著越來越多的開發人員轉向前端應用程序和數據解決方案,一個堅實的 AJAX API 對於開發具有響應性、可用性的查詢和修改文章系統至關重要。儘管許多解決方案和插件可以幫助設置端點,但它們通常很冗長或過於固執己見。Simple Posts API 為您的網站提供了一個易於使用的、有結構的 RESTful API,用於查詢、更新和刪除文章。它相對不具有固定的觀點,因此您可以隨意存儲和檢索文章元數據,而不必擔心事先設置字段。此外,它採用原生的 WordPress Nonces,為更新文章數據提供了一個安全的結構。
API 端點
使用
此插件具有以下四個主要的操作:
Get
Put
Delete
Post
每個操作可以通過訪問 http://yoururl.com/postsapi/OPERATION/POST_TYPE||ID 進行訪問。您可以傳遞帖子類型或 ID 作為第二個 URL 參數,具體取決於您正在執行的操作。
每個調用都必須有一個包含 nonce 值的變量 (nonce) 的 POST 體,WordPress 將對其進行驗證。提供一個本地化的 JS 變量名為 secure 可供使用。一些調用還允許向調用發送其他 POST 字段。
對於包含字段數據的調用,插件將自動確定哪些是自定義字段,哪些不是。
有關每個操作的具體信息,請參閱以下內容。
GET
基於提供的帖子類型或帖子 ID 檢索文章列表。
URL 路徑
http://yoururl.com/postsapi/get/POST_TYPE
或
http://yoururl.com/postapi/get/ID
POST 體
必需:
nonce (安全的 nonce 值)
可選:
arguments (一個包含要在調用中使用的 get_post 參數的數組)
示例 POST 體:
jQuery.post( '/postsapi/get/post', { nonce: secure, arguments : {'posts_per_page': '-1'} })
.done(function( data ) {
console.log(data);
});
其他注意事項:
GET 函數返回每篇文章的作者信息。如果用戶已經登錄並具有管理員權限,那麼作者信息是詳盡的。如果用户不是管理员,那麼為了安全起见,返回對象中會剝離任何私人信息。
PUT
基於提供的 ID 和 POST 字段更新文章
URL 路徑
http://yoururl.com/postapi/put/ID
POST 體
必需:
nonce (安全的 nonce 值)
fields (一個以key:value對形式傳遞的數組,用於確定要更新哪些字段)
可選:
force (布爾值;如果設置為false,則如果傳遞了任何無效字段名,調用會返回一個錯誤,否則它將更新所有有效字段。默認值為 "false")
示例 POST 體:
jQuery.post( '/postsapi/put/1', { nonce: secure, force: false, fields: { 'post_title': 'Updated Title', 'custom_text': 'Updated custom text' } } )
.done(function( data ) {
console.log( data );
});
DELETE
基於提供的 ID 刪除文章
URL 路徑
http://yoururl.com/postapi/delete/ID
POST 體
必需:
nonce (安全的 nonce 值)
原文外掛簡介
As more and more developers turn towards front-end apps and data solutions, a solid AJAX API is key to developing
a responsive, usable system of querying and modifying posts. While many solutions and plugins exist to help set up
endpoints, often times they are cumbersome or overly opinionated. Simple Posts API provides your site with an easy-to-use,
structure RESTful API with which to query, update, and delete posts. It is relatively unopinionated, so you can store and retrieve
post metadata at will without worrying about setting up fields beforehand. Additionally, it employs native WordPress Nonces
to provide a secure structure for updating your post data.
API Endpoints
Usage
There are four main operations you can use with this plugin:
Get
Put
Delete
Post
Each operation can be accessed by visiting http://yoururl.com/postsapi/OPERATION/POST_TYPE||ID You may pass a Post Type or ID as the second URL parameter depending on the operation you’re performing.
Each call must have a POST body containing a variable (nonce) containing a nonce value which WordPress will verify. There is a localized JS variable provided named secure which should be used. Some calls also allow other POST fields to be sent along with the call.
For calls which include Field data, the plugin will automatically determine which are Custom Fields and which are not.
See below for specifics on each operation.
GET
Retrieve a list of posts based on a provided Post Type or Post ID.
URL Path
http://yoururl.com/postsapi/get/POST_TYPE
OR
http://yoururl.com/postapi/get/ID
POST Body
Required:
nonce (nonce value for security)
Optional:
arguments (an array of get_post arguments to use in the call)
Example POST body:
jQuery.post( '/postsapi/get/post', { nonce: secure, arguments : {'posts_per_page': '-1'} })
.done(function( data ) {
console.log(data);
});
Additional Notes:
The GET function returns author information for each post. If a user is logged in and has admin capabilities, the author information is extensive. If the user is not an admin, then any private information is stripped from the returned object for security purposes.
PUT
Update a post based on the provided ID and POSTed fields
URL Path
http://yoururl.com/postapi/put/ID
POST Body
Required:
nonce (nonce value for security)
fields (an array of key:value pairs to determine which fields to update)
Optional:
force (boolean; if set to false, the call will return an error if any invalid field names are passed, otherwise it will update all valid fields regardless. Default is ‘false’)
Example POST body:
jQuery.post( '/postsapi/put/1', { nonce: secure, force: false, fields: { 'post_title': 'Updated Title', 'custom_text': 'Updated custom text' } } )
.done(function( data ) {
console.log( data );
});
DELETE
Delete a post based on the provided ID
URL Path
http://yoururl.com/postapi/delete/ID
POST Body
Required:
nonce (nonce value for security)
Optional:
force (boolean; if set to false, the post will be sent to the trash, otherwise it will skip the trash and be permanently deleted. Default is ‘false’)
Example POST body:
jQuery.post( '/postsapi/delete/7', { nonce: secure, force: false } )
.done(function( data ) {
console.log( data );
});
POST
Create a post of the given post type, including the provided fields
URL Path
http://yoururl.com/postapi/post/POST_TYPE
POST Body
Required:
nonce (nonce value for security)
fields (an array of key:value pairs to determine which fields to include when creating the post)
Optional:
none
Example POST body:
jQuery.post( '/postsapi/post/post', { nonce: secure, fields: { 'post_title': 'New Title', 'custom_text': 'New custom text', 'post_status': 'publish' } } )
.done(function( data ) {
console.log( data );
});
Errors and Status Messages
Each call will return a JSON object. Within the JSON object is a key named status. This contains a status code and status message. You can check against this in your scripts in order to see if the call was successful or not. Any status code other than 200 is an error.
Status Codes
200: Success
400: No posts found
401: Permission Denied (either failed the nonce verification or user not logged in)
410: Invalid Post ID or Post Type provided
420: Post ID not found
430: Fields not found (status message lists fields)
450: Post delete failed (WordPress could not delete the post, see the status message for details)
460: Post type does not exist
470: Could not create new post; see status message for error details
Actions
Each operation has its own unique _before and _after actions that can be hooked into. See below for a complete list.
GET
postsapi_before_get
postsapi_after_get
PUT
postsapi_before_put
postsapi_after_put
DELETE
postsapi_before_delete
postsapi_after_delete
POST
postsapi_before_post
postsapi_after_post
各版本下載點
- 方法一:點下方版本號的連結下載 ZIP 檔案後,登入網站後台左側選單「外掛」的「安裝外掛」,然後選擇上方的「上傳外掛」,把下載回去的 ZIP 外掛打包檔案上傳上去安裝與啟用。
- 方法二:透過「安裝外掛」的畫面右方搜尋功能,搜尋外掛名稱「Simple Posts API」來進行安裝。
(建議使用方法二,確保安裝的版本符合當前運作的 WordPress 環境。
延伸相關外掛(你可能也想知道)
API Endpoints 》選擇您的網站數據以透過 WordPress API 提供,, 並選擇要以哪種格式提供。, 功能, , 自定義 API URL:可以在外掛設定中更改 my-api 和 name1:http://mywordp...。
Restful UI 》使用 UI 介面來測試 WP-JSON 友善度。, 請確保您的自訂路徑已經註冊了命名空間!, 在外掛頁面底部有整個 WP-JSON 的 JSON 內容,以防您找不到需要的路徑端點...。
Moby Blog 》MOBY BLOG – 您的部落格也能變成行動裝置友善!, ****你是一位部落客嗎?您有自己的 WordPress 部落格嗎?****, 現在您可以免費地把您的部落格轉換成行...。
JSONPress 》JSONPress – 讓你透過標準 WordPress 查詢取得 JSON/JSONP 輸出的 WordPress 網站 , 功能 , , 透過子網域訪問 JSON,例如 api.example.com(子網域必...。
CW World News 》透過 Feedzilla(http://feedzilla.com)取得最新的新聞資訊。, 文章是從多個新聞來源的網絡中取得。, 允許網站訪客選擇各種語言、類別和子類別。, 允許網站...。
CAFEHAUS API 》這是一款可兼容小程序、APP和H5的多端API插件,提供更優雅的路由、輸入和輸出參數。它為前端提供了零依賴和零設置的方便使用功能。, 接口的特點包括:, * 可...。
eduTrac Authentication 》eduTrac SIS是一個開放源碼的學生資訊系統(SIS),可供中等和高等教育機構使用,以幫助管理教師、職員、學生、課程、課程註冊等。如果您使用WordPress網站與...。