Skip to content
This repository has been archived by the owner on Aug 8, 2022. It is now read-only.

Commit

Permalink
优化开启登录安全设置后的登录功能
Browse files Browse the repository at this point in the history
  • Loading branch information
bmqy committed Aug 8, 2020
1 parent c26ec0b commit e33a88e
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 6 deletions.
53 changes: 48 additions & 5 deletions functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -498,6 +498,26 @@ function bmqynext_clear_db_cache_archives_list() {
}
add_action('save_post', 'bmqynext_clear_db_cache_archives_list');

/**
* 判断是否为post请求
*/
if(!function_exists('bmqynext_is_post')){
function bmqynext_is_post()
{
return strtoupper( $_SERVER['REQUEST_METHOD']) === 'POST';
}
}

/**
* 判断是否为get请求
*/
if(!function_exists('bmqynext_is_get')){
function bmqynext_is_get()
{
return strtoupper( $_SERVER['REQUEST_METHOD']) === 'GET';
}
}

/*
* 自定义后台登录地址
* */
Expand All @@ -506,11 +526,34 @@ function bmqynext_clear_db_cache_archives_list() {
function bmqynext_login_security(){
$loginSecurityFalg = (get_option('bmqynext_options_login_security_flag')!='')?get_option('bmqynext_options_login_security_flag'):'flag';
$loginSecurityRedirect = (get_option('bmqynext_options_login_security_redirect')!='')?get_option('bmqynext_options_login_security_redirect'):site_url();
if(empty($_GET['security'])){
header('Location: '. $loginSecurityRedirect);
}else{
if($_GET['security'] != $loginSecurityFalg)header('Location: '. $loginSecurityRedirect);
}
$referer = $_SERVER['HTTP_REFERER'];

//判断是否登录请求
if(bmqynext_is_post()){
if(strpos($referer, '/wp-login.php?security='. $loginSecurityFalg)){
if(!is_user_logged_in()){
header('Location: /wp-login.php?security='. $loginSecurityFalg);
}
}
}
//判断访问登录页
if(bmqynext_is_get()){
$redirectTo = $_GET['redirect_to'];
if(empty($_GET['security'])){
//判断是否有确认邮件地址等操作
if(!strpos($redirectTo, 'wp-admin')){
if($referer && strpos($referer, '/wp-login.php?security='. $loginSecurityFalg)){
header('Location: /wp-login.php?security='. $loginSecurityFalg);
} else {
header('Location: '. $loginSecurityRedirect);
}
}
}else{
if($_GET['security'] != $loginSecurityFalg) {
header('Location: '. $loginSecurityRedirect);
}
}
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion style.css
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Theme URI: https://github.com/bmqy/bmqy-next
Author: bmqy
Author URI: http://www.bmqy.net/
Description: wordpress's theme next for bmqy. Copyright owner: IIssNan, http://theme-next.iissnan.com/.
Version: 1.2
Version: 1.2.1
License: GNU General Public License v2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html
Tags: elegant, one-column, right-sidebar, custom-header, custom-menu, editor-style
Expand Down

0 comments on commit e33a88e

Please sign in to comment.