[WordPress] 外掛分享: Disable WP REST API

前言介紹

  • 這款 WordPress 外掛「Disable WP REST API」是 2018-06-05 上架。
  • 目前有 20000 個安裝啟用數。
  • 上一次更新是 2025-03-20,距離現在已有 48 天。
  • 外掛最低要求 WordPress 4.7 以上版本才可以安裝。
  • 外掛要求網站主機運作至少需要 PHP 版本 5.6.20 以上。
  • 有 35 人給過評分。
  • 論壇上目前有 1 個提問,問題解答率 100% ,不低,算是個很有心解決問題的開發者團隊了!

外掛協作開發者

specialk |

外掛標籤

api | JSON | rest | disable | rest-api |

內容簡介

這個外掛只有一個功能:禁用沒有登入 WordPress 的訪客使用 WP REST API。不需要任何設定。

這個外掛只有 22 行短小的程式碼(少於 2KB)。因此它非常輕量、快速和有效。

功能

只有訪客(非登入者)使用 REST/JSON 時會被禁用
關閉所有使用者的 REST header
關閉所有使用者的 REST links
100% 即插即用,安裝好後不用管它。

這個外掛是防止網站 REST / JSON API 被濫用的快速方法。

這是怎麼運作的?這個取決於你使用的 WordPress 版本。

WordPress v4.7 及之後的版本

對於 WordPress 4.7 和更高版本,此外掛完全禁用 WP REST API,除非使用者已登入 WordPress。

對於已登入的使用者,WP REST API 將正常運作
對於未登入者,WP REST API 會被禁用

如果未登入的訪客發送 JSON / REST 請求會發生什麼?他們就只會看到一個簡單的訊息:

“rest_login_required: REST API restricted to authenticated users.”

可以透過過濾器鉤子 disable_wp_rest_api_error 自定義此訊息。參考這裡的例子。

較舊的 WordPress 版本

對於版本低於 4.7 的 WordPress,此外掛只會禁用所有使用者的 REST API 功能。

詳細資料可參見 FAQ 部分的說明。

隱私

這個外掛不會收集或儲存任何使用者資料,不會設置任何 cookies,也不會連接到任何第三方位置。因此,這個外掛不會以任何方式影響使用者隱私,如果說有的話,它也會保護潛在敏感資訊不被顯示或經由 REST API 使用。

Disable WP REST API 是由 15 年 WordPress 開發者和書籍作者 Jeff Starr 開發和維護。

支援這個外掛的開發

我用心開發和維護這個免費的外掛,為 WordPress 社群做貢獻。如果你想表達支援,可以捐款或購買我的書:

WordPress 的道
挖掘 WordPress
.htaccess製作指南
深入解析WordPress主題
巫師的 WordPress SQL 食譜

或購買我的高階 WordPress 外掛:

BBQ Pro – 超快的 WordPress 防火牆
Blackhole Pro – 自動攔截壞的機器人
Banhammer Pro – 監控流量並封鎖壞人
GA Google Analytics Pro – 把 WordPress 與 Google Analytics 連接起來

原文外掛簡介

This plugin does one thing: disables the WP REST API for visitors who are not logged into WordPress. No configuration required.
This plugin works with only 22 short lines of code (less than 2KB). So it is super lightweight, fast, and effective.
Features

Disable REST/JSON for visitors (not logged in)
Disables REST header in HTTP response for all users
Disables REST links in HTML head for all users
100% plug-and-play, set-it-and-forget solution

The fast, simple way to prevent abuse of your site’s REST/JSON API
How does it work? That depends on which version of WordPress you are using..
WordPress v4.7 and beyond
For WordPress 4.7 and better, this plugin completely disables the WP REST API unless the user is logged into WordPress.

For logged-in users, WP REST API works normally
For logged-out users, WP REST API is disabled

What happens if logged-out visitor makes a JSON/REST request? They will get only a simple message:
“rest_login_required: REST API restricted to authenticated users.”
This message may customized via the filter hook, disable_wp_rest_api_error. Check out this post for an example of how to do it.
Older versions of WordPress
For WordPress versions less than 4.7, this plugin simply disables all REST API functionality for all users.
More information available below in the FAQs section.
Privacy
This plugin does not collect or store any user data. It does not set any cookies, and it does not connect to any third-party locations. Thus, this plugin does not affect user privacy in any way. If anything it improves user privacy, as it protects potentially sensitive information from being displayed/accessed via REST API.
Disable WP REST API is developed and maintained by Jeff Starr, 15-year WordPress developer and book author.
Support development of this plugin
I develop and maintain this free plugin with love for the WordPress community. To show support, you can make a donation or purchase one of my books:

The Tao of WordPress
Digging into WordPress
.htaccess made easy
WordPress Themes In Depth
Wizard’s SQL Recipes for WordPress

And/or purchase one of my premium WordPress plugins:

BBQ Pro – Super fast WordPress firewall
Blackhole Pro – Automatically block bad bots
Banhammer Pro – Monitor traffic and ban the bad guys
GA Google Analytics Pro – Connect WordPress to Google Analytics
Head Meta Pro – Ultimate Meta Tags for WordPress
Simple Ajax Chat Pro – Unlimited chat rooms
USP Pro – Unlimited front-end forms

Links, tweets and likes also appreciated. Thank you! 🙂

各版本下載點

  • 方法一:點下方版本號的連結下載 ZIP 檔案後,登入網站後台左側選單「外掛」的「安裝外掛」,然後選擇上方的「上傳外掛」,把下載回去的 ZIP 外掛打包檔案上傳上去安裝與啟用。
  • 方法二:透過「安裝外掛」的畫面右方搜尋功能,搜尋外掛名稱「Disable WP REST API」來進行安裝。

(建議使用方法二,確保安裝的版本符合當前運作的 WordPress 環境。


1.0 | 1.1 | 1.2 | 1.3 | 1.4 | 1.5 | 1.6 | 1.7 | 1.8 | 1.9 | 2.0 | 2.1 | 2.2 | 2.3 | 2.4 | 2.5 | 2.6 | 2.4.1 | 2.5.1 | 2.6.1 | 2.6.2 | 2.6.3 | 2.6.4 | 2.6.5 | trunk |

延伸相關外掛(你可能也想知道)

  • Disable REST API 》這是最全面的 WordPress REST API 存取控制外掛!, 輕鬆安裝,安裝後不需要額外設定即可使用。只需上傳並啟用,整個 REST API 將無法被一般訪客存取。, 但如...。
  • Make Connector 》Make 是一個視覺化平台,讓你可以在幾分鐘內設計、建立和自動化任何事情 - 從簡單的任務到複雜的工作流程。使用 Make,你可以在 WordPress 和數千個應用程式...。
  • ACF to REST API 》此 WordPress 外掛在WordPress REST API中提供了Advanced Custom Fields的端點, 詳細資訊請參閱GitHub:https://github.com/airesvsg/acf-to-rest-api/。
  • WPGet API – Connect to any external REST API 》簡單地連接WordPress至外部API的最簡單方式。, , WPGetAPI 可輕鬆地從無限量的第三方 REST API 發送和接收資料,然後使用「Shortcode」或「Template Tag」格...。
  • WP REST Cache 》如果您在使用 WordPress REST API 時遇到速度問題,這個外掛將允許 WordPress 快取 REST API 的回應,使其更快。, 此外掛提供以下功能:, , 快取所有預設的 W...。
  • WP REST API Controller 》WP REST API Controller 外掛提供使用者易用的圖形化介面,使管理員可以切換 WordPress 核心和自訂文章類型以及分類法的可見性和端點,同時也可以自訂 API 回...。
  • Transbank Webpay REST 》透過 Webpay Plus 和 Webpay Oneclick 在你的 WooCommerce 上使用信用卡、借記卡和預付卡進行在線付款。
  • WordPress REST API (Version 2) 》WordPress 正轉變成一個完整的應用程式框架,因此需要新的 API。這個專案的目的是創建一個易於使用、易於理解且經過良好測試的框架,用於創建這些 API,以及...。
  • WP REST API – OAuth 1.0a Server 》使用這個外掛,您可以將應用程式連接至您的 WordPress 網站,而不必透露您的密碼。, 此外掛使用 OAuth 1.0a 協議,允許委派授權,即允許應用程式使用一組次要...。
  • REST API Meta Support 》此外掛可以自動將 WordPress REST API 的文章(/wp-json/wp/v2/posts)或頁面(/wp-json/wp/v2/pages) POST 中的 meta 欄位所包含的元數據自動存儲於建立的...。
  • Better REST API Featured Images 》注意:您可能不需要此外掛。 REST API 已經支援在 URL 中添加查詢參數 ?_embed,並且回應將包括所有“嵌入式媒體”,包括特色圖片,在那裡獲得的數據正是此外掛...。
  • REST API Toolbox 》此外掛允許調整多個 REST API 設定, , 停用 REST API, 移除 WordPress 核心端點, 需要核心端點驗證, 強制使用 SSL, WP-CLI 命令: wp rest-api-toolbox, , 在 ...。
  • Disable Gutenberg Autosave 》啟用此外掛後,Gutenberg 編輯器的自動儲存功能將被停用。您也可以在編輯器中選擇不同的自動儲存間隔時間(預設為 60 秒)。, 區塊編輯器仍會使用本地自動儲...。
  • WP-CORS 》來自其他網站的 AJAX 請求(其中包含 Origin 標頭)將被允許,並且會允許在外掛程式的「設定」頁面中列出的任何網域。。
  • REST XML-RPC Data Checker 》JSON REST API 和 XML-RPC API 是與 WordPress 遠程交互的強大方式。, 如果您沒有需要使用 JSON REST API 或 XML-RPC API 與外部應用程序通信的需求,您應禁...。

文章
Filter
Apply Filters
Mastodon