Title: Disable REST API
Author: Dave McHale
Published: <strong>2014 年 10 月 3 日</strong>
Last modified: 2023 年 9 月 14 日

---

搜尋外掛

![](https://ps.w.org/disable-json-api/assets/banner-772x250.png?rev=1001011)

這個外掛**並未在最新的 3 個 WordPress 主要版本上進行測試**。開發者可能不再對這個
外掛進行維護或提供技術支援，並可能會與更新版本的 WordPress 產生使用上的相容性問題。

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

# Disable REST API

 由 [Dave McHale](https://profiles.wordpress.org/dmchale/) 開發

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

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

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

## 外掛說明

控制存取 WordPress REST API 最全方位的外掛。

設定後便可不再需要管理。僅需上傳外掛並啟用，網站上的一般使用者便無法存取整個 REST
API。

如果需要存取某些端點，這個外掛也可以辦到。前往外掛設定頁面，網站管理員可以快速設定
REST API 個別端點 (或端點的整個分支) 的允許清單。

網站管理員可以依據使用者角色進行設定，因此可以達成未經驗證的使用者 (例如沒有網站
帳號及密碼的使用者) 有一組規則，WooCommerce 客戶另有一組規則，而訂閱者、編輯及網站
管理員也有各自的一組規則。請注意，在隨裝即用的原則下，仍會授予全部已定義的使用者
角色完整存取 REST API 的權限，直至完成相關設定才會限制存取。

對於大多數的 WordPress 核心程式版本來說，如果不允許使用者存取端點，這個外掛會傳回
身分驗證錯誤。這個外掛對於舊版 WordPress 4.4、4.5 及 4.6 提供支援，會以 `rest_enabled`
篩選器停用整個 REST API。

## 螢幕擷圖

 * [[
 * 透過篩選器停用網站 API 後，JSON 傳回的資料 (WordPress 4.4、4.5 及 4.6)
 * [[
 * 透過身分驗證方法停用網站 API 後，JSON 傳回的資料 (WordPress 4.7 或更新版本)
 * [[
 * 外掛設定頁面讓網站管理員可以依據使用者角色選取要允許存取的 REST API 端點

## 安裝方式

 1. 透過 FTP 上傳解壓縮所得的 `disable-json-api` 資料夾及其全部檔案至 `/wp-content/
    plugins/` 目錄。
 2. 或是前往 WordPress 網站管理後台的 [外掛]→[安裝外掛] 頁面，上傳 `disable-json-api_v#.#.
    zip` 檔案。
 3. 在 WordPress 管理後台的 [外掛] 選單中啟用外掛。

## 常見問題集

### 如何確認這個外掛的執行是否有效？

外掛啟用後，以有帳號的 WordPress 使用者登入，REST API 會如預期般執行；如果使用者
以另一個瀏覽器 (或 Chrome 的 [無痕式視窗]) 登入網站，會以乾淨的工作階段測試網站。
在沒有登入的狀況下前往 yourdomain.com/wp-json/ (或 yourdomain.com/?rest_route=/，
如果網站停用易於辨識的永久連結)，便不會取得任何結果，並會傳回身分驗證錯誤 (Disable
REST API: 僅有已驗證的使用者能存取 REST API)。

### 這個外掛可以停用 WordPress 網站中的全部 REST API 嗎？

這個外掛**僅能**停用 WordPress 核心程式本身提供的 REST API。如果外掛或佈景主題提供
他們專屬的 REST API (不要與 WordPress API 本身提供的專屬端點混淆)，這個外掛對這些
第三方程式提供的 REST API 無效。

## 使用者評論

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

### 󠀁[Excellent](https://wordpress.org/support/topic/excellent-13544/)󠁿

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

What else can I say, this plugin does exactly what its supposed to do. It’s easy
to understand and works perfectly. So well done!

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

### 󠀁[Fantastic](https://wordpress.org/support/topic/fantastic-3276/)󠁿

 [Wombat Plugins](https://profiles.wordpress.org/maartenbelmans/) 2023 年 12 月 
29 日

The plugin does what it says on the tin, without being pretentious. Absolutely fantastic!

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

### 󠀁[One of the must have plugins.](https://wordpress.org/support/topic/one-of-the-must-have-plugins-4/)󠁿

 [ucsendre](https://profiles.wordpress.org/ucsendre/) 2023 年 9 月 14 日

I always start my WordPress installations with this plugin (among a few other ones).
A must have on all sites. Thank you.

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

### 󠀁[Still works on WP 6.2](https://wordpress.org/support/topic/still-works-on-wp-6-2/)󠁿

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

The plugin still works for me on WordPress 6.2. It’s great to have the option to
allow API access where I need it and block everything else.

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

### 󠀁[Just what I was looking for](https://wordpress.org/support/topic/just-what-i-was-looking-for-535/)󠁿

 [Ronny Adsetts](https://profiles.wordpress.org/ronnyadsetts/) 2023 年 1 月 26 日

Allows locking the WP API behind auth and selectively allowing it where needed. 
Despite the lack of plugin updates, the author does have an active github repo so
don’t let that put you off.

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

### 󠀁[Excellent solution](https://wordpress.org/support/topic/excellent-solution-67/)󠁿

 [Ben Sibley](https://profiles.wordpress.org/bensibley/) 2023 年 1 月 20 日

Blocking the REST API entirely breaks plugins that require this functionality, so
being able to selectively enable routes is perfect. I recommend this plugin to everyone
who uses Independent Analytics to secure their site while still enabling analytics
to be recorded.

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

## 參與者及開發者

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

參與者

 *   [ Dave McHale ](https://profiles.wordpress.org/dmchale/)
 *   [ Tang Rufus ](https://profiles.wordpress.org/tangrufus/)

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

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

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

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

## 變更記錄

#### 1.8

 * Tested up to WP v6.3
 * Added `dra_error_message` filter so devs can customize the access error message
 * Fixed bug that caused fatal errors if activating plugin on installations running
   the LearnPress plugin
 * Changed minimum requirements to PHP 5.6 (up from 5.3) and WordPress 4.9 (up from
   4.4). Adding docblock comments to support minimums.

#### 1.7

 * Tested up to WP v5.8
 * Replace use of filemtime() with plugin version number for static file enqueues.
   Props @tangrufus for bringing this up!
 * Fixed logic bug for role-based default_allow rules. Props @msp1974 for the report!
 * Few small code-style updates

#### 1.6

 * Tested up to WP v5.6
 * Added support for managing endpoint access on a per-user-role basis
 * Soooooooo many small changes behind the scenes to support the above

#### 1.5.1

 * Tested up to WP v5.5

#### 1.5

 * Tested up to WP v5.3
 * Added enforcement for WordPress and PHP minimum version requirements
 * Fixed minor bug to prevent unintended empty routes
 * Minor text updates and adding textdomain to translation functions that didn’t
   have them

#### 1.4.3

 * Added `load_plugin_textdomain()` for i18n

#### 1.4.2

 * Fixed issue causing unintentional unlocking of endpoints when another WP_Error
   existed before this plugin did its job

#### 1.4.1

 * Fixed echo of text URL to primary Plugins page in WP Dashboard

#### 1.4

 * Tested for WP v4.8
 * Tested for PHP 5.3+
 * Added settings screen
 * Site Admins may now whitelist routes that they wish to allow unauthenticated 
   access to
 * Added `dra_allow_rest_api` filter to the is_logged_in() check, so developers 
   can get more granular with permissions
 * Props to @tangrufus for all of the help that went into this release

#### 1.3

 * Tested for WP v4.7
 * Adding new functionality to raise authentication errors in 4.7+ for non-logged-
   in users

#### 1.2

 * Tested for WP v4.5
 * Removal of actions which publish REST info to the head and header

#### 1.1

 * Updated to support the new filters created in the 2.0 beta API

#### 1.0

 * Initial Release

## 中繼資料

 *  版本 **1.8**
 *  最後更新 **3 年前**
 *  啟用安裝數 **90,000+**
 *  WordPress 版本需求 ** 4.9 或更新版本 **
 *  已測試相容的 WordPress 版本 **6.3.8**
 *  PHP 版本需求 ** 5.6 或更新版本 **
 *  語言
 * [Asturian](https://ast.wordpress.org/plugins/disable-json-api/)、[Chinese (Taiwan)](https://tw.wordpress.org/plugins/disable-json-api/)、
   [Dutch](https://nl.wordpress.org/plugins/disable-json-api/)、[Dutch (Belgium)](https://nl-be.wordpress.org/plugins/disable-json-api/)、
   [English (US)](https://wordpress.org/plugins/disable-json-api/)、[French (France)](https://fr.wordpress.org/plugins/disable-json-api/)、
   [German](https://de.wordpress.org/plugins/disable-json-api/)、[Portuguese (Portugal)](https://pt.wordpress.org/plugins/disable-json-api/)、
   [Russian](https://ru.wordpress.org/plugins/disable-json-api/)、[Spanish (Colombia)](https://es-co.wordpress.org/plugins/disable-json-api/)、
   [Spanish (Ecuador)](https://es-ec.wordpress.org/plugins/disable-json-api/)、[Spanish (Mexico)](https://es-mx.wordpress.org/plugins/disable-json-api/)、
   [Spanish (Spain)](https://es.wordpress.org/plugins/disable-json-api/)、[Spanish (Venezuela)](https://ve.wordpress.org/plugins/disable-json-api/)、
   及 [Swedish](https://sv.wordpress.org/plugins/disable-json-api/).
 *  [將這個外掛本地化為你的母語版本](https://translate.wordpress.org/projects/wp-plugins/disable-json-api)
 * 標籤:
 * [admin](https://tw.wordpress.org/plugins/tags/admin/)[api](https://tw.wordpress.org/plugins/tags/api/)
   [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-json-api/advanced/)

## 評分

 4.8 星，滿分為 5 星

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

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

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

## 參與者

 *   [ Dave McHale ](https://profiles.wordpress.org/dmchale/)
 *   [ Tang Rufus ](https://profiles.wordpress.org/tangrufus/)

## 技術支援

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

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