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

Come disattivare l’API JSON REST in WordPress

Nota editoriale: guadagniamo una commissione dai link dei partner su WPBeginner. Le commissioni non influenzano le opinioni o le valutazioni dei nostri redattori. Per saperne di più su Processo editoriale.

Recentemente uno dei nostri lettori ci ha chiesto: come posso disabilitare l’API REST sul mio sito WordPress?

Quando è stata rilasciata la versione 4.4 di WordPress, è stata introdotta la tanto attesa API JSON REST. Sebbene sia ottima per gli sviluppatori di plugin, molti proprietari di siti potrebbero non trovarla affatto utile.

In questo articolo vi mostreremo come disabilitare facilmente l’API JSON REST in WordPress.

Disable JSON REST API in WordPress

Perché disabilitare l’API JSON REST in WordPress?

È innegabile che l’API offra molti vantaggi agli sviluppatori di WordPress. L’API rende estremamente semplice il recupero dei dati tramite richieste GET, il che è utile per chi costruisce applicazioni con WordPress.

Detto questo, questo potrebbe potenzialmente aprire il vostro sito web a un nuovo fronte di attacchi DDoS. Inoltre, può richiedere un notevole dispendio di risorse e rallentare il vostro sito WordPress.

La disabilitazione di JSON REST API è simile alla disabilitazione di XML-RPC, che molti amministratori di siti disabilitano sui loro siti WordPress per sicurezza.

Vi mostriamo due metodi per disabilitare facilmente JSON REST API in WordPress. Utilizzate semplicemente i collegamenti rapidi qui sotto per passare al metodo che desiderate utilizzare.

Metodo 1. Disabilitare l’API JSON REST in WordPress con il codice (consigliato)

Si consiglia di utilizzare il plugin WPCode per disabilitare JSON REST API in WordPress.

WPCode

WPCode rende sicura e facile l’aggiunta di codice personalizzato in WordPress, senza modificare il file functions.php del vostro tema. In questo modo, non c’è il rischio di commettere un errore e di danneggiare il sito.

Inoltre, è dotato di una libreria di codice integrata che include frammenti di codice verificati per le richieste di funzionalità più diffuse, come la disabilitazione dell’API REST, la disabilitazione di XML-RPC e molto altro. In questo modo si evita di dover installare una serie di plugin monouso.

Per iniziare, è necessario installare e attivare il plugin gratuito WPCode. Per istruzioni dettagliate, leggete la nostra guida su come installare un plugin di WordPress.

Nota: la versione gratuita di WPCode ha tutto ciò che serve per aggiungere facilmente codice personalizzato in WordPress. Ma se desiderate funzioni avanzate come una libreria di snippet cloud privata, snippet specifici per pagina e dispositivo, revisioni del codice e altro ancora, potete passare a WPCode Pro.

Una volta attivato il plugin, andare su Code Snippets ” Library dalla dashboard di WordPress.

Quindi, cercate lo snippet “Disable WordPress REST API” e fate clic sul pulsante “Use snippet”.

Select the Disable WordPress REST API in WPCode

Il plugin aggiungerà quindi automaticamente il codice e selezionerà il metodo di inserimento corretto.

WPCode automatically adds the Disable JSON REST API snippet

È sufficiente spostare l’interruttore da “Inattivo” ad “Attivo”.

Quindi, fare clic sul pulsante “Aggiorna”.

Switch the code snippet to Active and click Update in WPCode

Ecco fatto. Ora JSON REST API è disabilitato sul vostro sito WordPress.

Metodo 2. Disabilitazione dell’API JSON REST in WordPress con un plugin

La prima cosa da fare è installare e attivare il plugin Disable REST API. Per maggiori dettagli, consultate la nostra guida passo passo su come installare un plugin di WordPress.

Il plugin funziona subito e non ci sono impostazioni da configurare.

Ora restituirà forzatamente un errore di autenticazione a qualsiasi richiesta API proveniente da fonti che non hanno effettuato l’accesso al vostro sito web.

In questo modo si impedisce efficacemente alle richieste non autorizzate di utilizzare l’API REST per ottenere informazioni dal vostro sito web.

È possibile verificarlo visitando la pagina http://example.com/wp-json. Assicuratevi di uscire prima dall’area di amministrazione di WordPress o di passare il browser alla modalità in incognito.

Non dimenticare di sostituire example.com con il proprio nome di dominio. Verrà visualizzato questo messaggio, che indica che le richieste dell’API REST sono bloccate.

REST API Disabled

È tutto, avete disabilitato con successo le richieste API REST non autorizzate sul vostro sito WordPress.

Speriamo che questo articolo vi abbia aiutato a capire come disattivare l’API JSON in WordPress. Gli utenti attenti alla sicurezza potrebbero anche voler dare un’occhiata a questi consigli sulla protezione dell’area di amministrazione di WordPress o vedere le nostre scelte dei migliori plugin di backup per WordPress.

Se questo articolo vi è piaciuto, iscrivetevi al nostro canale YouTube per le esercitazioni video su WordPress. Potete trovarci anche su Twitter e Facebook.

Divulgazione: I nostri contenuti sono sostenuti dai lettori. Ciò significa che se cliccate su alcuni dei nostri link, potremmo guadagnare una commissione. Vedi come WPBeginner è finanziato , perché è importante e come puoi sostenerci. Ecco il nostro processo editoriale .

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.

Il kit di strumenti WordPress definitivo

Ottenete l'accesso gratuito al nostro kit di strumenti - una raccolta di prodotti e risorse relative a WordPress che ogni professionista dovrebbe avere!

Reader Interactions

37 commentiLascia una risposta

  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.

      Admin

  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

      Admin

  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.

      Admin

  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.

Lascia una risposta

Grazie per aver scelto di lasciare un commento. Tenga presente che tutti i commenti sono moderati in base alle nostre politica dei commenti e il suo indirizzo e-mail NON sarà pubblicato. Si prega di NON utilizzare parole chiave nel campo del nome. Avremo una conversazione personale e significativa.