Trusted WordPress tutorials, when you need them most.
Beginner’s Guide to WordPress
WPBカップ
25 Million+
Websites using our plugins
16+
Years of WordPress experience
3000+
WordPress tutorials
by experts

WordPressでJSON REST APIを無効化する方法

編集メモ: WPBeginner のパートナーリンクから手数料を得ています。手数料は編集者の意見や評価に影響を与えません。編集プロセスについて詳しく知る。

最近、ある読者から「WordPressサイトのREST APIを無効化するにはどうすればいいですか?

WordPressバージョン4.4がリリースされたとき、待望のJSON REST APIが搭載された。プラグイン開発者にとっては素晴らしいものですが、多くのサイトオーナーはまったく便利だとは思わないかもしれません。

この投稿では、WordPressのJSON REST APIを簡単に無効化する方法を紹介します。

Disable JSON REST API in WordPress

WordPressでJSON REST APIを無効化する理由とは?

APIがWordPress開発者にとって多くのメリットがあることは否定できない。APIを使えば、GETリクエストを使ってデータを取得するのがとても簡単になるので、WordPressでアプリを作る人には便利だ。

とはいえ、これはあなたのサイトをDDoS攻撃の新たな脅威にさらす可能性があります。また、リソースを消費し、WordPressサイトの速度を低下させる可能性もあります。

JSON REST APIを無効化することは、XML-RPCを無効化することに似ており、多くのサイト管理者が安全のためにWordPressサイトで無効化している。

WordPressでJSON REST APIを簡単に無効化する2つの方法を紹介します。以下のクイックリンクから、使いたい方法にジャンプしてください。

方法1.WordPressのJSON REST APIをコードで無効化する(推奨)

WordPressのJSON REST APIを無効化するには、WPCodeプラグインを使用することをお勧めします。

WPCode

WPCodeは、テーマのfunctions.phpファイルを編集することなく、WordPressでカスタムコードを安全かつ簡単に追加することができます。そのため、エラーを起こしてサイトを壊してしまうリスクはありません。

さらに、REST APIの無効化、XML-RPCの無効化など、一般的な機能要求に対する検証済みのコード・スニペットを含むビルトイン・コード・ライブラリが付属しています。これにより、個別プラグインを何個もインストールする必要がなくなります。

開始するには、無料のWPCodeプラグインをインストールし、有効化する必要があります。ステップバイステップの手順については、WordPressプラグインのインストール方法のガイドをお読みください。

注: WPCodeの無料版には、WordPressで簡単にカスタマイザーコードを追加するために必要なすべてがあります。しかし、プライベートクラウドスニペットライブラリ、ページや端末固有のスニペット、コードリビジョンなどの高度な機能が必要な場合は、WPCode Proにアップグレードすることができます。

プラグインを有効化したら、WordPressダッシュボードからCode Snippets ” Libraryに移動します。

次に、「Disable WordPress REST API」スニペットを検索し、「Use snippet」ボタンをクリックします。

Select the Disable WordPress REST API in WPCode

プラグインは自動的にコードを追加し、適切な挿入方法を選択します。

WPCode automatically adds the Disable JSON REST API snippet

必要なのは、スイッチを「非アクティブ」から「有効化」に切り替えることだけだ。

そして「更新」ボタンをクリックする。

Switch the code snippet to Active and click Update in WPCode

これで完了です。これで、WordPressサイトでJSON REST APIが無効化されました。

方法2.WordPressのJSON REST APIをプラグインで無効化する。

最初に行う必要があるのは、Disable REST APIプラグインをインストールして有効化することです。詳しくは、WordPressプラグインのインストール方法のステップバイステップガイドをご覧ください。

プラグインは箱から出してすぐに使えるし、設定することもない。

あなたのサイトにログインしていないソースからのAPIリクエストに対して、強制的に認証エラーを返すようになりました。

これにより、REST APIを使用してサイトから情報を取得する不正なリクエストを効果的に防ぐことができます。

http://example.com/wp-json。WordPressの管理エリアからログアウトするか、ブラウザーをシークレットモードに切り替えてください。

example.comを自分のドメイン名に置き換えることをお忘れなく。このメッセージが表示され、REST APIリクエストがブロックされていることがわかります。

REST API Disabled

以上で、WordPressサイトで不正なREST APIリクエストを無効化することができました。

WordPress で JSON API を無効化する方法について、この投稿がお役に立てば幸いです。セキュリティに敏感なユーザーは、WordPress の管理エリアを保護するためのヒントをチェックしたり、WordPress のバックアップに最適なプラグインを選んだりすることもできます。

If you liked this article, then please subscribe to our YouTube Channel for WordPress video tutorials. You can also find us on Twitter and Facebook.

情報開示 私たちのコンテンツは読者支援型です。これは、あなたが私たちのリンクの一部をクリックした場合、私たちはコミッションを得ることができることを意味します。 WPBeginnerの資金源 をご覧ください。3$編集プロセスをご覧ください。

Avatar

Editorial Staff at WPBeginner is a team of WordPress experts led by Syed Balkhi with over 16 years of experience in WordPress, Web Hosting, eCommerce, SEO, and Marketing. Started in 2009, WPBeginner is now the largest free WordPress resource site in the industry and is often referred to as the Wikipedia for WordPress.

究極のWordPressツールキット

ツールキットへの無料アクセス - すべてのプロフェッショナルが持つべきWordPress関連製品とリソースのコレクション!

Reader Interactions

37件のコメント返信を残す

  1. Syed Balkhi says

    Hey WPBeginner readers,
    Did you know you can win exciting prizes by commenting on WPBeginner?
    Every month, our top blog commenters will win HUGE rewards, including premium WordPress plugin licenses and cash prizes.
    You can get more details about the contest from here.
    Start sharing your thoughts below to stand a chance to win!

  2. RJW says

    I’d try the disable plugin in Dev environment before production, I found installing it broke some features

    • WPBeginner Support says

      If you have many different plugins and tools and have a testing environment then it would definitely be good to test new plugins and how they interact with your site.

      管理者

  3. Ricky says

    Similar to an above commenter, I’ve noticed the “wp-json” request when using Pingdom and other testing sites. Unfortunately, mine takes over 10 seconds (Yes really!!) to load it. This pushes my overall website load time and I can’t figure out how to fix this. The plugin doesn’t change it at all. Any suggestions?

  4. Janice says

    How do I know if I actually have JSON API on my website?
    This article about removing it is good – if I need it – but I have often been alarmed by certain warnings only to find that they’ve not even applicable to me.

  5. Logan Cale says

    I hate adding yet another plugin to do a simple tasks, and I found that we can disable this functionality by adding the following code snippet to the functions.php file.

    add_filter(‘rest_enabled’, ‘_return_false’);
    add_filter(‘rest_jsonp_enabled’, ‘_return_false’);

  6. J.L. says

    Is this just for self hosted blogs or including free blog sites? Per mostly all plug ins…etc are done for you when you’re not self hosted

    PS I’m not subscribing…just want a response

  7. Elaine says

    How can I check if my site has Rest API. I turned off a lot of extras when I first set it up but now don’t know where to look to see if it’s there. Not keen to download a plugin unnecessarily.

    • WPBeginner Support says

      Hey Elaine,

      You can check if rest is api is enabled on your site by visiting the url like this example.com/wp-json. Make sure you are signed out of WordPress before doing that. If you see lots of information in plain text, then this means REST API is enabled on your site. Follow the above instructions to turn it off

      管理者

  8. Ken Dowling says

    Is disabling REST API suitable for e-commerce sites such as WooCommerce? My understanding is that WooCommerce uses REST-API quite a bit.

    Further, my buyers do not have to login to buy, so what happens to the transaction when a REST API call is rejected?

    Regards, Ken

  9. D. Joe Chaffin says

    Plug-in makes no difference for me in WP 4.7.2. With the plugin activated or disabled, the example.com/wp-json (with my domain replacing “example”) pages gives a massive list of settings for my site.

    • D. Joe Chaffin says

      Hmmmm. Now that I look at it, I only see the list in Safari, while Chrome and Firefox for Mac show the expected message specified in this post.

    • WPBeginner Support says

      Hi,

      Make sure you are logged out of WordPress admin area or use incognito mode before testing the example.com/wp-json page. The plugin disables access to the page only for unauthorized users. As an administrator you will still be able to see it.

      管理者

  10. Audra Carpenter says

    Hey Guys,

    First off thanks so much for what you do! I’ve learned so much about WordPress from you and sent a ton of folks your way!!

    Ok, I installed the plugin, but I am not seeing what you suggest above? I have a full screen of information…?

    Thoughts?

    Thanks!

  11. Treasure says

    I followed these steps, but when I went to check it with the example etc., I got 2 pages of code, not the response showed above. Hmmm, don’t know what to do.

  12. Doug Nix says

    When I ran the test I think it failed, as I got a boatload of data on screen. Any idea what might have not worked? I installed the plugin as described…

    • Doug Nix says

      Works perfectly when I check using an incognito window. Thanks for the explanation regarding authorised vs unauthorised or anonymous users.

  13. Karl says

    Thanks for the tip as well as for the hook to disable XMLRPC.
    Is there a chance for a filter hook for the REST API as well?

  14. Andrew says

    When I check the speed of my site using pingdom.com, the first html entry that tried to load shows the link as mydomain.com/wp-json and it has over 2 seconds of “wait” time. Is this the same as what this article is talking about? I’m hesitant to simply disable it since I would assume it will be used in the future. Any idea why it would add a 2+ second delay to loading anything on the page?

  15. Stephen Cronin says

    Hmm, the REST API is going to become the standard way for plugins and themes to make Ajax calls back to the server from the front end, replacing admin-ajax, so I wouldn’t be disabling it… Hopefully they will fail gracefully, but you will almost end up missing some functionality.

    Also, if you really want to protect against DDoS attacks, you better disable html as well! ;)

    • reza says

      ver 50,000 WordPress websites have been hacked due to a major security vulnerability that was discovered in the WordPress REST API.

      • Jim S Smith says

        OUCH!

        That’s disturbing to know. I have noticed a LOT of access attempts in my site’s logs.

        What’s more,

        I think the folks at WordPress could have done a little better in letting the users decide how much, if at all, they want the REST API exposed.

        Again,

        More of this, “The developers know MORE about the user’s needs than the user does!” – I also was not too happy about being forced to support EMOJI and remote-loaded fonts from fonts.google.com, even though my sites do not use them!

        The REST API may be a boon for (some) actual web-application developers, but what about the rest of us who will not very likely use this? ? ?

  16. Kasey says

    How likely is it that a plugin will be using this functionality. Just for example would contact forms be utilizing this? Not keen on turning it off in case it breaks anything.

返信を残す

コメントありがとうございます。すべてのコメントは私たちのコメントポリシーに従ってモデレートされ、あなたのメールアドレスが公開されることはありませんのでご留意ください。名前欄にキーワードを使用しないでください。個人的で有意義な会話をしましょう。