WordPress教程:禁用JSON REST API/移除wp-json链接

前端之家收集整理的这篇文章主要介绍了WordPress教程:禁用JSON REST API/移除wp-json链接前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

wordpress4.4版本默认集成了JSON REST API,这个功能是备受关注的,对于开发者来说,是非常有价值的,通过JSON REST API可以在外部程序中很方便地调用wordpress网站内部的数据,比如可以使用wordpress来制作app程序。

对绝大多数的wordpress使用者来说,这个功能是用不到的,JSON REST API采用的是GET请求方式来获取数据,这样会为DDOS攻击提供了新的攻击途径,就像XML-RPC接口一样,为了避免黑客利用此功能来攻击我们的服务器和网站程序,这篇wordpress教程里我们就向大家介绍一下禁用 wordpress中JSON REST API功能或者说移除head里面wp-json链接方法

切换到主题目录,打开functions.PHP文件,加入以下代码

Crayon-5c891d079149c800938549" class="Crayon-Syntax Crayon-theme-classic Crayon-font-monaco Crayon-os-pc print-yes notranslate" data-settings=" minimize scroll-mouSEOver" style=" margin-top: 12px; margin-bottom: 12px; font-size: 12px !important; line-height: 15px !important;">
Crayon-toolbar" data-settings=" mouSEOver overlay hide delay" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">Crayon-title">functions.PHP
Crayon-tools" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">
Crayon-button Crayon-nums-button" title="Toggle Line Numbers">
Crayon-button-icon">
Crayon-button Crayon-plain-button" title="Toggle Plain Code">
Crayon-button-icon">
Crayon-button Crayon-wrap-button" title="Toggle Line Wrap">
Crayon-button-icon">
Crayon-button Crayon-expand-button" title="Expand Code">
Crayon-button-icon">
Crayon-button Crayon-copy-button" title="Copy">
Crayon-button-icon">
Crayon-button Crayon-popup-button" title="Open Code In New Window">
Crayon-button-icon">
Crayon-info" style="min-height: 16.8px !important; line-height: 16.8px !important;">
Crayon-plain-wrap">
Crayon-main" style="">Crayon-table">Crayon-row">
Crayon-nums " data-settings="show">
Crayon-nums-content" style="font-size: 12px !important; line-height: 15px !important;">
Crayon-num" data-line="Crayon-5c891d079149c800938549-1">1
Crayon-num Crayon-striped-num" data-line="Crayon-5c891d079149c800938549-2">2
Crayon-num" data-line="Crayon-5c891d079149c800938549-3">3
Crayon-num Crayon-striped-num" data-line="Crayon-5c891d079149c800938549-4">4
Crayon-num" data-line="Crayon-5c891d079149c800938549-5">5
Crayon-num Crayon-striped-num" data-line="Crayon-5c891d079149c800938549-6">6
Crayon-num" data-line="Crayon-5c891d079149c800938549-7">7
Crayon-num Crayon-striped-num" data-line="Crayon-5c891d079149c800938549-8">8
Crayon-code">
Crayon-pre" style="font-size: 12px !important; line-height: 15px !important; -moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4;">
Crayon-line" id="Crayon-5c891d079149c800938549-1">Crayon-c">/**
Crayon-line Crayon-striped-line" id="Crayon-5c891d079149c800938549-2">Crayon-c">* 禁用 wordpress 的 JSON REST API
Crayon-line" id="Crayon-5c891d079149c800938549-3">Crayon-c">*/
Crayon-line Crayon-striped-line" id="Crayon-5c891d079149c800938549-4">Crayon-e">add_filterCrayon-sy">(Crayon-s">'rest_enabled'Crayon-sy">,Crayon-h"> Crayon-s">'__return_false'Crayon-sy">)Crayon-sy">;
Crayon-line" id="Crayon-5c891d079149c800938549-5">Crayon-e">add_filterCrayon-sy">(Crayon-s">'rest_jsonp_enabled'Crayon-sy">,Crayon-h"> Crayon-s">'__return_false'Crayon-sy">)Crayon-sy">;
Crayon-line Crayon-striped-line" id="Crayon-5c891d079149c800938549-6">
Crayon-line" id="Crayon-5c891d079149c800938549-7">Crayon-e">remove_actionCrayon-sy">(Crayon-h"> Crayon-s">'wp_head'Crayon-sy">,Crayon-h"> Crayon-s">'rest_output_link_wp_head'Crayon-sy">,Crayon-h"> Crayon-cn">10Crayon-h"> Crayon-sy">)Crayon-sy">;
Crayon-line Crayon-striped-line" id="Crayon-5c891d079149c800938549-8">Crayon-e">remove_actionCrayon-sy">(Crayon-h"> Crayon-s">'wp_head'Crayon-sy">,Crayon-h"> Crayon-s">'wp_oembed_add_discovery_links'Crayon-sy">,Crayon-h"> Crayon-cn">10Crayon-h"> Crayon-sy">)Crayon-sy">;

原文链接:https://www.f2er.com/wordpress/238439.html

猜你在找的wordpress相关文章