均在function.php中添加
//保护后台登陆,修改后登陆网址变为/wp-login.php?自定义字符串1=自定义字符串2
add_action('login_enqueue_scripts','login_protection');
function login_protection(){
if($_GET['自定义字符串1'] != '自定义字符串2'){
header('Location: https://www.aliyun.com/');
}
}
//WordPress后台登陆随机数学验证码
function add_login_fields_Math_Captcha() {
//获取两个随机数, 范围0~9
$MathCaptchaNum1=rand(0,9);
$MathCaptchaNum2=rand(0,9);
//最终网页中的具体内容
echo "<p><label for='math' class='small'>Math Captcha:$MathCaptchaNum1 + $MathCaptchaNum2 = ? </label><input type='text' name='sum' class='input' value='' size='25'>"
."<input type='hidden' name='MathCaptchaNum1' value='$MathCaptchaNum1'>"
."<input type='hidden' name='MathCaptchaNum2' value='$MathCaptchaNum2'></p>";}
add_action('login_form','add_login_fields_Math_Captcha');
function login_val_Math_Captcha() {
$sum=$_POST['sum'];//用户提交的计算结果
switch($sum){
//得到正确的计算结果则直接跳出
case $_POST['MathCaptchaNum1']+$_POST['MathCaptchaNum2']:break;
//未填写结果时的错误讯息
case null:wp_die('Error: Please enter the verification code!');break;
//计算错误时的错误讯息
default:wp_die('Error: Verification code is wrong, please try again!');}}
add_action('login_form_login','login_val_Math_Captcha');
//no self ping
function no_self_ping( &$links ) {
$home = get_option( 'home' );
foreach ( $links as $l => $link )
if ( 0 === strpos( $link, $home ) ) unset($links[$l]);
}
add_action( 'pre_ping', 'no_self_ping' );
//关闭xmlrpc
add_filter('xmlrpc_enabled', '__return_false');
/**
* 禁用 WordPress 的 JSON REST API
*/
add_filter('json_enabled', '__return_false');
add_filter('json_jsonp_enabled', '__return_false');
//转义评论内容
function aili_code_escape( $incoming_comment ) {
$incoming_comment = htmlspecialchars($incoming_comment, ENT_QUOTES);
return $incoming_comment;
}
add_filter( 'comment_text', 'aili_code_escape' );
add_filter( 'comment_text_rss', 'aili_code_escape' );
修改wp-config.php:
//禁用编辑主题、插件
define('DISALLOW_FILE_EDIT', true);
本文被阅读了:2,276次