easyiit_urlogin.php
3.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
<?php
/**
* Plugin Name: URL来路识别
* Plugin URI: #
* Description: URL来路识别
* Version: 2.0.00
* Author: Goodao
* Author URI: #
*/
if (!defined('IMPORT_PATH')) define('IMPORT_PATH', plugin_dir_path(__FILE__));
add_action('admin_menu', 'easyiit_init');
function easyiit_init() {
add_submenu_page('easyiit_urlogin', '设置', '设置', 7, 'easyiit_urlogin', 'login_setting');
}
function login_setting() {
if(isset($_POST['dosubmit'])){
$login_setting = $_POST['setting'];
update_option( "_login_setting", $login_setting );
echo '<div id="setting-error-settings_updated" class="updated settings-error"><p><strong>保存成功。</strong></p></div>';
}
$login_setting = get_option("_login_setting");
?>
<div class="wrap">
<form id="logins-filter" method="post">
<h2 class="title">来路设置</h2>
<table class="form-table permalink-structure">
<tbody>
<tr>
<th>
<label>来路URL:</label>
</th>
<td>
<textarea name="setting[refer_url]" rows="6" cols="50"><?php echo $login_setting['refer_url']?></textarea>
<p style="color:red">每行一个,只填写域名,如:www.goodao.cn</p>
</td>
</tr>
</tbody>
</table>
<p class="submit"><input type="submit" name="dosubmit" id="submit" class="button button-primary" value="保存更改"></p>
</form>
</div>
<div class="clear"></div>
<?php
}
add_action( 'wp_loaded', 'autologin' );
function autologin() {
$login_setting = get_option("_login_setting");
$login_setting_urls = explode("\n",$login_setting['refer_url']);
foreach($login_setting_urls as $v){
$login_setting_url_arr[]=trim($v);
}
$login_setting_url_arr[] = 'admin.globalso.com';
$login_setting_url_arr[] = 'dev123.globalso.com';
$host = parse_url($_SERVER['HTTP_REFERER']);
if(in_array($host['host'],$login_setting_url_arr)){
if (!is_user_logged_in()) {
#账号信息及账号类别---------------------------------------------------------------
$user_level = intval($_GET['user_level']);
$user_phone = $_GET['user_phone'];
if (FALSE == empty($user_level) || empty($user_phone)){
$user_name = isset($_GET['role']) && $_GET['role'] ? 'visitor' : 'gd-admin';
$user = get_user_by('login', $user_name);
}else{
if (empty($user = get_user_by('login', $user_phone))){
wp_create_user($user_phone, md5($user_phone), '');
$user = get_user_by('login', $user_phone);
$user->set_role('editor');
}
}
#--------------------------------------------------------------------------------
$credentials['remember'] = true;
$res = wp_set_auth_cookie($user->ID, $credentials['remember'], "");
do_action('wp_login', $user->user_login, $user);
$redirect = $_GET['redirect'];
if($redirect){
echo "<script>window.location.href='".$redirect."';</script> ";
}else{
if($_GET['action']==''&&$_POST['action']==''){
echo "<script>window.location.href='/admin--globalso/';</script> ";
}
}
}else{
if(isset($_GET['redirect']) && $_GET['redirect']){
echo "<script>window.location.href='".$_GET['redirect']."';</script> ";
}
}
}
}
function easyiit_plugin_settings_link($links) {
$settings_link = '<a href="' . esc_url( admin_url( 'admin.php?page=easyiit_urlogin' ) ) . '">' . __( 'Settings' ) . '</a>';
array_unshift($links, $settings_link);
return $links;
}
$plugin = plugin_basename(__FILE__);
add_filter("plugin_action_links_$plugin", 'easyiit_plugin_settings_link' );