Title: Disable WP REST API
Author: Jeff Starr
Published: <strong>2018 年 6 月 6 日</strong>
Last modified: 2026 年 4 月 22 日

---

搜尋外掛

![](https://ps.w.org/disable-wp-rest-api/assets/icon-256x256.png?rev=1926021)

# Disable WP REST API

 由 [Jeff Starr](https://profiles.wordpress.org/specialk/) 開發

[下載](https://downloads.wordpress.org/plugin/disable-wp-rest-api.2.6.8.zip)

 * [詳細資料](https://tw.wordpress.org/plugins/disable-wp-rest-api/#description)
 * [使用者評論](https://tw.wordpress.org/plugins/disable-wp-rest-api/#reviews)
 *  [安裝方式](https://tw.wordpress.org/plugins/disable-wp-rest-api/#installation)
 * [開發資訊](https://tw.wordpress.org/plugins/disable-wp-rest-api/#developers)

 [技術支援](https://wordpress.org/support/plugin/disable-wp-rest-api/)

## 外掛說明

**這個外掛只有一個功能**，便是針對未登入 WordPress 的訪客完全停用 REST API，而且
不需要任何組態。

**請務必注意**，這個外掛會針對未登入 WordPress 的訪客完全停用 REST API。如果網站
需要將 WP REST API 開放給未登入使用者使用，不建議使用這個外掛。

👉 防止網站的 REST/JSON API 遭到濫用最快、最簡易的方式
 👉 保護網站的 REST 資料免
受未登入的使用者及漫遊器的侵擾 👉 程式碼僅有 4KB，極致的輕量化、快速及效率

🛠️ 現已提供 Pro 版。[進一步了解 REST Pro Tools »](https://plugin-planet.com/rest-pro-tools/)

### 外掛特色

 * 為未登入的使用者停用 REST/JSON
 * 為全部使用者停用 HTTP 回應中的 REST 標頭
 * 為全部使用者停用 HTML 標頭中的 REST 連結
 * 完全隨裝即用，設定後不需後續管理

**外掛運作方式**

**除非**使用者登入 WordPress，否則這個外掛會完全停用 WP REST API。

 * 對已登入/完成驗證的使用者來說，WP REST API 會正常執行
 * 對未登入/已登出/未經驗證的使用者來說，WP REST API 會是停用狀態

至於已登出/未登入的使用者產生 JSON/REST 要求後，他們會收到以下訊息：

    ```
    rest_login_required: REST API restricted to authenticated users.
    ```

這個訊息可透過篩選器勾點 `disable_wp_rest_api_error` 進行自訂，請參考[這篇文章](https://wordpress.org/support/topic/not-entirely-for-non-techies/#post-12014965)
的範例了解如何使用這個篩選器勾點。

### Pro 版

🛠️ 進一步了解 Pro 版，[REST Pro Tools](https://plugin-planet.com/rest-pro-tools/)
包含多項強大的功能：

 * 一鍵停用全部路由
 * 一鍵停用全部/使者用路由
 * 依據使用者角色停用指定使用者路由
 * 將任何使用者新增至允許清單
 * 將任何 IP 位址新增至允許清單
 * 自訂 REST 錯誤訊息
 * 自訂 REST 回應碼
 * 持續要求或強制使用 SSL/TLS
 * 停用全部 JSONP 小技巧
 * 一鍵停用全部 REST API 標頭
 * 新增任何內容中繼資料 (自訂欄位) 至 REST API
 * 新增任何使用者中繼資料 (自訂欄位) 至 REST API
 * 新增網站使用者個人資料及作者個人資料的路由
 * 新增精選圖片及文章分類的路由
 * 新增文章分類法及分類法詞彙的路由
 * REST API 檢查狀況概觀

免費版只有針對未驗證的 WordPress 使用者完全停用 REST API 的功能，Pro 版除了這個功能，
還有更多控制功能，使用 [REST Pro Tools](https://plugin-planet.com/rest-pro-tools/)
便能完整控制 REST API。

### 隱私權

這個外掛不會收集或儲存任何使用者資料。它不會設定任何 Cookie，也不會連線至任何第三
方位置，因此它不會透過任何方式侵犯使用者隱私。相反的，這個外掛可以**改善**使用者
隱私，因為它可以保護潛在的敏感資訊不會透過 TEST API 顯示/存取。

Disable WP REST API 由具備 15 年 [WordPress 開發者](https://plugin-planet.com/)及
[書籍作者](https://books.perishablepress.com/)經驗的 [Jeff Starr](https://x.com/perishable)
開發及維護。

### 支持這個外掛的開發工作

因為喜愛 WordPress 社群，因此我開發並維護這個免費外掛。如果想要支持外掛開發工作，
請[贊助開發工作](https://monzillamedia.com/donate.html)或購買我撰寫的書籍：

 * [The Tao of WordPress](https://wp-tao.com/)
 * [Digging into WordPress](https://digwp.com/)
 * [.htaccess made easy](https://htaccessbook.com/)
 * [WordPress Themes In Depth](https://wp-tao.com/wordpress-themes-book/)
 * [Wizard’s SQL Recipes for WordPress](https://books.perishablepress.com/downloads/wizards-collection-sql-recipes-wordpress/)

也可以透過購買以下付費 WordPress 外掛支持外掛開發：

 * [BBQ Pro](https://plugin-planet.com/bbq-pro/)：效能極佳的 WordPress 防火牆
 * [Blackhole Pro](https://plugin-planet.com/blackhole-pro/)：自動封鎖惡意漫遊器
 * [Banhammer Pro](https://plugin-planet.com/banhammer-pro/)：監控網路流量及封鎖
   惡意存取
 * [GA Google Analytics Pro](https://plugin-planet.com/ga-google-analytics-pro/)：
   將 WordPress 網站連接至 Google Analytics
 * [Head Meta Pro](https://plugin-planet.com/head-meta-pro/)：沒有限制的 WordPress
   中繼資料標籤外掛
 * [REST Pro Tools](https://plugin-planet.com/rest-pro-tools/)：管理 WP REST API
   的絕佳工具
 * [Simple Ajax Chat Pro](https://plugin-planet.com/simple-ajax-chat-pro/)：沒有
   限制的聊天室
 * [USP Pro](https://plugin-planet.com/usp-pro/)：沒有限制的網站前端功能表單

十分歡迎外部連結、轉推及按讚，謝謝大家 🙂

## 安裝方式

**手動安裝**

 1. 上傳外掛檔案至網站並完成啟用。
 2. 大功告成！不需進行任何組態。

進一步了解[安裝 WordPress 外掛](https://wordpress.org/documentation/article/manage-plugins/#installing-plugins-1)

**測試方式**

如需了解這個外掛是否正確執行，請登出 WordPress 並在瀏覽器中對 `https://example.com/
wp-json/` 提出要求。請參考〈常見問題集〉以進一步了解。

**Pro 版**

如果需要對 WP REST API 進行更多控制，請使用 [Pro 版](https://plugin-planet.com/rest-pro-tools/)。

**如果這個外掛對網站有所幫助**

如果 Disable WP REST API 對網站有所幫助，請[給予 5 星評等](https://wordpress.org/support/plugin/disable-wp-rest-api/reviews/?rate=5#new-post)，
這對外掛的持續開發及支援會有正面的幫助，謝謝大家。

**解除安裝**

如需移除外掛，請前往 [外掛] 頁面，先停用外掛，然後刪除外掛。這個外掛不會對原有的
網站資料進行任何變更。

## 常見問題集

### 為什麼會有停用 RSET API 的需求？

這個外掛實際上只會針對**未**登入 WordPress 的使用者停用 REST API。以下是針對未登入
的使用者停用 REST API 的幾個原因：

 * 未登入的使用者可能不需要 REST API
 * 停用 REST API 可以節省伺服器資源
 * 停用 REST API 可以最大程度降低潛在的攻擊途徑
 * 停用 REST API 可以防止內容遭到擷取及抄襲

[這裡](https://digwp.com/2018/08/secure-wp-rest-api/)還有可供大家參考的其他原因。

### 預設的拒絕存取訊息是什麼？

如果是已登入 WordPress 的使用者，便會顯示正常的 REST API 資料；如果使用者**未**登入，
以下便是預設訊息：

    ```
    {"code":"rest_login_required","message":"REST API restricted to authenticated users.","data":{"status":401}}
    ```

### 如何確認 REST 已停用？

測試方式非常簡單：

 1. 登出 WordPress
 2. 使用瀏覽器對 `https://example.com/wp-json/` 提出要求

如果看到以下訊息，代表 REST 已停用：

`rest_login_required: 僅有已驗證的使用者可以使用 REST API。`

如果再次登入 WordPress 並對 `https://example.com/wp-json/` 提出要求，便會看到 REST
以如預期般執行。

### 這個外掛是否能停用由其他外掛新增的 REST 功能？

是。這個外掛會為未登入的使用者停用由 WP REST API 註冊的全部端點，但不會封鎖已登入
使用者使用 WP REST API 的權限。

### 這個外掛是否能與區塊編輯器搭配使用？

可以，無論使用哪一個編輯器 (傳統編輯器或區塊編輯器)，這個外掛的執行方式都一樣。

### 自訂錯誤訊息的方式為何？

依照預設，這個外掛會對未通過身分驗證的使用者顯示「僅有已驗證的使用者可以使用 REST
API」。如需依據需求自訂這個訊息，請在目前使用的佈景主題的 functions.php 中或使用
[自訂外掛](https://digwp.com/2022/12/custom-code-wordpress/)新增以下程式碼：

    ```
    function disable_wp_rest_api_error_custom($message) {

        return 'Customize your message here.'; // change this to whatever you want

    }
    add_filter('disable_wp_rest_api_error', 'disable_wp_rest_api_error_custom');
    ```

### 如何允許存取 Contact Form 7？

依據這篇[討論串](https://wordpress.org/support/topic/contact-forrm-7-bypass-solution/)
的說明，Contact Form 7 需要存取 REST API 才能讓聯絡表單正常執行。如果需要允許 Contact
Form 7 存取 REST API，請參考這篇[文章](https://perishablepress.com/contact-form-7-disable-wp-rest-api/)。

### 如何提問？

請透過這份[聯絡表單](https://plugin-planet.com/support/#contact)提出問題或意見反應。

## 使用者評論

![](https://secure.gravatar.com/avatar/5299e088badf21e6a4a7497b5bb225b1b63b4440db14993cb1102c152054a1a7?
s=60&d=retro&r=g)

### 󠀁[good job](https://wordpress.org/support/topic/good-job-1885/)󠁿

 [pftsoi](https://profiles.wordpress.org/pftsoi/) 2025 年 9 月 8 日

good job

![](https://secure.gravatar.com/avatar/53b876447630c744e5562cd4b3985514b6b317784f4168cf8ca2c954753f6306?
s=60&d=retro&r=g)

### 󠀁[Very simple and effective](https://wordpress.org/support/topic/very-simple-and-effective-29/)󠁿

 [terrymason](https://profiles.wordpress.org/terrymason/) 2024 年 11 月 19 日

just activate the plugin and it works.

![](https://secure.gravatar.com/avatar/7bdeae3e3f899915da10e6e0eb8e58857d8237d099681d86feaa7b8c52115398?
s=60&d=retro&r=g)

### 󠀁[I like it!](https://wordpress.org/support/topic/i-like-it-1043/)󠁿

 [wildstar2022](https://profiles.wordpress.org/wildstar2022/) 2024 年 5 月 6 日

I’ve tried many different solutions using functions.php because I did not want to
install yet another plugin. I’m glad I found this one though. It’s simple, lightweight,
maintains privacy, and functions with the latest version of WordPress. Thanks Jeff!

![](https://secure.gravatar.com/avatar/9c7be41168a828b3275c2a320c1b629708f7a7af499541029a40e662b9320a3e?
s=60&d=retro&r=g)

### 󠀁[Good Stuff – but make many other things more complicate](https://wordpress.org/support/topic/good-stuff-but-make-many-other-things-more-complicate/)󠁿

 [metaeditor](https://profiles.wordpress.org/metaeditor/) 2023 年 3 月 29 日

In generel a Good security concept . But at the other end many plugin developer 
use the Rest API Could be done much easier with a 5 3 line htaccess rule to block
only ^.*wp-json/wp/v2/(users But anyway a good solution if you have a simpel installation.

![](https://secure.gravatar.com/avatar/4c485a16524f42bc4f2f4f13b4f0dc22ee6a42fe669182a6ecdd8d7a1ab96a49?
s=60&d=retro&r=g)

### 󠀁[Blocks Contact Form 7 forms sending](https://wordpress.org/support/topic/blocks-contact-form-7-forms-sending/)󠁿

 [Hendrik57](https://profiles.wordpress.org/hendrik57/) 2023 年 2 月 12 日 6 則留言

As the title says: Blocks Contact Form 7 forms sending after install and activate.

![](https://secure.gravatar.com/avatar/dd8cef4c70bb3a14f5922eb54c92a8166947a303f44eb4a89a954cee4defad6f?
s=60&d=retro&r=g)

### 󠀁[Super simple plugin](https://wordpress.org/support/topic/super-plugin-1132/)󠁿

 [tinaponting](https://profiles.wordpress.org/ponting/) 2024 年 12 月 29 日

Great plugin, takes nopower from the blog:)

 [ 閱讀全部 36 則使用者評論 ](https://wordpress.org/support/plugin/disable-wp-rest-api/reviews/)

## 參與者及開發者

以下人員參與了開源軟體〈Disable WP REST API〉的開發相關工作。

參與者

 *   [ Jeff Starr ](https://profiles.wordpress.org/specialk/)

〈Disable WP REST API〉外掛目前已有 8 個本地化語言版本。 感謝[全部譯者](https://translate.wordpress.org/projects/wp-plugins/disable-wp-rest-api/contributors)
為這個外掛做出的貢獻。

[將〈Disable WP REST API〉外掛本地化為台灣繁體中文版](https://translate.wordpress.org/projects/wp-plugins/disable-wp-rest-api)

### 對開發相關資訊感興趣？

任何人均可[瀏覽程式碼](https://plugins.trac.wordpress.org/browser/disable-wp-rest-api/)、
查看 [SVN 存放庫](https://plugins.svn.wordpress.org/disable-wp-rest-api/)，或透過
[RSS](https://plugins.trac.wordpress.org/log/disable-wp-rest-api/?limit=100&mode=stop_on_copy&format=rss)
訂閱[開發記錄](https://plugins.trac.wordpress.org/log/disable-wp-rest-api/)。

## 變更記錄

如果 Disable WP REST API 對網站有所幫助，請[給予 5 星評等](https://wordpress.org/support/plugin/disable-wp-rest-api/reviews/?rate=5#new-post)，
這對外掛的持續開發及支援會有正面的幫助，謝謝大家。

> 🛠️ Pro version now available! Get granular control over the REST API with [REST Pro Tools »](https://plugin-planet.com/rest-pro-tools/)

#### 2.6.8

 * Improves readme.txt documentation
 * Adds blurb about new pro version
 * Tests on WordPress 7.0

Full changelog @ [https://plugin-planet.com/wp/changelog/disable-wp-rest-api.txt](https://plugin-planet.com/wp/changelog/disable-wp-rest-api.txt)

## 中繼資料

 *  版本 **2.6.8**
 *  最後更新 **1 個月前**
 *  啟用安裝數 **30,000+**
 *  WordPress 版本需求 ** 4.7 或更新版本 **
 *  已測試相容的 WordPress 版本 **7.0**
 *  PHP 版本需求 ** 5.6.20 或更新版本 **
 *  語言
 * [Chinese (China)](https://cn.wordpress.org/plugins/disable-wp-rest-api/)、[Chinese (Taiwan)](https://tw.wordpress.org/plugins/disable-wp-rest-api/)、
   [Dutch](https://nl.wordpress.org/plugins/disable-wp-rest-api/)、[English (US)](https://wordpress.org/plugins/disable-wp-rest-api/)、
   [German](https://de.wordpress.org/plugins/disable-wp-rest-api/)、[Italian](https://it.wordpress.org/plugins/disable-wp-rest-api/)、
   [Russian](https://ru.wordpress.org/plugins/disable-wp-rest-api/)、[Spanish (Chile)](https://cl.wordpress.org/plugins/disable-wp-rest-api/)、
   及 [Ukrainian](https://uk.wordpress.org/plugins/disable-wp-rest-api/).
 *  [將這個外掛本地化為你的母語版本](https://translate.wordpress.org/projects/wp-plugins/disable-wp-rest-api)
 * 標籤:
 * [api](https://tw.wordpress.org/plugins/tags/api/)[disable](https://tw.wordpress.org/plugins/tags/disable/)
   [JSON](https://tw.wordpress.org/plugins/tags/json/)[rest](https://tw.wordpress.org/plugins/tags/rest/)
   [rest-api](https://tw.wordpress.org/plugins/tags/rest-api/)
 *  [進階檢視](https://tw.wordpress.org/plugins/disable-wp-rest-api/advanced/)

## 評分

 4.8 星，滿分為 5 星

 *  [  34 個 5 星使用者評論     ](https://wordpress.org/support/plugin/disable-wp-rest-api/reviews/?filter=5)
 *  [  0 個 4 星使用者評論     ](https://wordpress.org/support/plugin/disable-wp-rest-api/reviews/?filter=4)
 *  [  1 個 3 星使用者評論     ](https://wordpress.org/support/plugin/disable-wp-rest-api/reviews/?filter=3)
 *  [  0 個 2 星使用者評論     ](https://wordpress.org/support/plugin/disable-wp-rest-api/reviews/?filter=2)
 *  [  1 個 1 星使用者評論     ](https://wordpress.org/support/plugin/disable-wp-rest-api/reviews/?filter=1)

[Your review](https://wordpress.org/support/plugin/disable-wp-rest-api/reviews/#new-post)

[查看全部使用者評論](https://wordpress.org/support/plugin/disable-wp-rest-api/reviews/)

## 參與者

 *   [ Jeff Starr ](https://profiles.wordpress.org/specialk/)

## 技術支援

使用者可在技術支援論壇提出意見反應或使用問題。

 [檢視技術支援論壇](https://wordpress.org/support/plugin/disable-wp-rest-api/)

## 贊助

想要支援這個外掛的發展嗎？

 [ 贊助這個外掛 ](https://monzillamedia.com/donate.html)