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

Disable REST API

外掛說明

The most comprehensive plugin for controlling access to the WordPress REST API!

Works as a “set it and forget it” install. Just upload and activate, and the entire REST API will be inaccessible to your general site visitors.

But if you do need to grant access to some endpoints, you can do that too. Go to the Settings page and you can quickly whitelist individual endpoints (or entire branches of endpoints) in the REST API.

You can even do this on a per-user-role basis, so your unauthenticated users have one set of rules while WooCommerce customers have another while Subscribers and Editors and Admins all have their own. NOTE: Out of the box, all defined user roles will still be granted full access to the REST API until you choose to manage those settings.

For most versions of WordPress, this plugin will return an authentication error if a user is not allowed to access an endpoint. For legacy support, WordPress 4.4, 4.5, and 4.6 use the provided rest_enabled filter to disable the entire REST API.

螢幕擷圖

  • The JSON returned by a website with the API disabled via filters (WP versions 4.4, 4.5, 4.6)
  • The JSON returned by a website with the API disabled via authentication methods (WP versions 4.7+)
  • The Settings page lets you selectively whitelist endpoints registered with the REST API, on a per-user-role basis.

安裝方式

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

常見問題集

How do I know if this plugin is working?

While logged into WordPress as any user, the REST API will function as intended. Because of this, you must use a new browser – or Chrome’s incognito mode – to test your website with a clean session. Go to yourdomain.com/wp-json/ (or yourdomain.com/?rest_route=/ if you have pretty permalinks disabled) while NOT LOGGED IN to test the results. You will see an authentication error returned if the plugin is active. “DRA: Only authenticated users can access the REST API.”

Does this plugin disable every REST API that is installed on my site?

This plugin is ONLY meant to disable endpoints accessible via the core REST API that is part of WordPress itself. If a plugin or theme has implemented their own REST API (not to be confused with implementing their own endpoints within the WordPress API) this plugin will have no effect.

使用者評論

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.
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.
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.
2023 年 1 月 10 日
It has not been tested with current Wordpress 6.1 and it seems to be compatible up to 5.8.6. Last update that we had was over 1 year ago. This was/is a very good plugin with the options, and it could still work now, but we can not verify compliance.
2022 年 12 月 27 日
I installed this but following install I couldn't view any webpages. The main page give exception Notice: Trying to get property 'name' of non-object in /home/customer/www/XXXXXX/public_html/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php on line 60 I prompted renamed plugin folder using FTP in the folder wp-content\plugins\disable-json-api.disable so I could login then deleted it Good idea but didn't work for my site
閱讀全部 35 則使用者評論

參與者及開發者

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

參與者

〈Disable REST API〉外掛目前已有 13 個本地化語言版本。 感謝全部譯者為這個外掛做出的貢獻。

將〈Disable REST API〉外掛本地化為台灣繁體中文版

對開發相關資訊感興趣?

任何人均可瀏覽程式碼、查看 SVN 存放庫,或透過 RSS 訂閱開發記錄

變更記錄

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