1
0
Fork 0
mirror of https://github.com/yunluo/gdk.git synced 2024-05-24 17:32:23 +02:00

优化各种代码,调整位置

This commit is contained in:
云落 2021-05-04 13:08:19 +08:00
parent 7f5da81fff
commit 07042529eb
4 changed files with 34 additions and 87 deletions

View file

@ -1,5 +1,5 @@
<?php <?php
if (!defined('ABSPATH')) exit;
function gdk_rand_color() { function gdk_rand_color() {
$arr=array("red","green","blue","yellow"); $arr=array("red","green","blue","yellow");
@ -1157,6 +1157,11 @@ function gdk_weauth_qr()
return $qr64; return $qr64;
} }
//微信登陆页面按钮
function weixin_login_button(){
echo '<p><a class="button button-large" href="' . get_permalink(gdk_page_id('weauth')) . '">微信登录</a></p><br>';
}
/** /**
* 微信登陆按钮 * 微信登陆按钮
*/ */

View file

@ -1,5 +1,5 @@
<?php <?php
if (!defined('ABSPATH')) {exit;} if (!defined('ABSPATH')) exit;
if (gdk_option('gdk_cdn')) { if (gdk_option('gdk_cdn')) {
add_action('wp_loaded', 'gdk_cdn_start'); add_action('wp_loaded', 'gdk_cdn_start');
@ -18,6 +18,10 @@ if (gdk_option('gdk_cdn_water')) {
} }
//CDN水印 //CDN水印
//在登录框添加额外的微信登录
if (gdk_option('gdk_weauth_oauth')) {
add_action('login_form', 'weixin_login_button');
}
//文章首尾添加自定义内容 //文章首尾添加自定义内容
function gdk_add_content($content) { function gdk_add_content($content) {
if(is_single()) { if(is_single()) {
@ -39,28 +43,6 @@ function gdk_add_content($content) {
} }
add_filter('the_content', 'gdk_add_content'); add_filter('the_content', 'gdk_add_content');
//接受奶子微信的账号信息
function get_weauth_oauth()
{
if (in_string($_SERVER['REQUEST_URI'], 'weauth')) {
$weauth_user = isset($_GET['user']) ? sanitize_text_field($_GET['user']) : false; //weauth发来用户信息
$weauth_sk = isset($_GET['sk']) ? sanitize_text_field($_GET['sk']) : false; //weauth返回的12位sk信息
$weauth_res = get_transient($weauth_sk . '-OK');
if (empty($weauth_res) && $weauth_res !== 1) {
return;
}
$weauth_user = stripslashes($weauth_user);
$weauth_user = json_decode($weauth_user, true);
$oauth_result = implode('|', $weauth_user);
set_transient($weauth_sk . '-info', $oauth_result, 60); //1分钟缓存
header('goauth: ok');
echo 'success'; //给对方服务器打个招呼
exit;
}
}
add_action('parse_request', 'get_weauth_oauth');
//社交头像 //社交头像
function gdk_wx_avatar($avatar, $id_or_email, $size, $default, $alt) function gdk_wx_avatar($avatar, $id_or_email, $size, $default, $alt)
{ {
@ -339,7 +321,8 @@ if (gdk_option('gdk_article_list')) {
add_filter('the_content', 'article_index'); add_filter('the_content', 'article_index');
} }
function weauth_page_activate() //插件安装自动激活页面
function gdk_page_activate()
{ {
$awesome_page_id = get_option('weixin_page_id'); $awesome_page_id = get_option('weixin_page_id');
if (!$awesome_page_id) { if (!$awesome_page_id) {
@ -356,7 +339,7 @@ function weauth_page_activate()
} }
} }
add_action('admin_init', 'weauth_page_activate'); add_action('admin_init', 'gdk_page_activate');
//强制微信登录 //强制微信登录
function force_weauth_login_url($login_url, $redirect, $force_reauth) function force_weauth_login_url($login_url, $redirect, $force_reauth)
@ -371,6 +354,7 @@ function force_weauth_login_url($login_url, $redirect, $force_reauth)
return $login_url; return $login_url;
} }
//修改注册页面
function change_my_register_url($url) function change_my_register_url($url)
{ {
if (is_admin()) { if (is_admin()) {

View file

@ -1,4 +1,5 @@
<?php <?php
if (!defined('ABSPATH')) exit;
/** /**
* 各页面重写规则 * 各页面重写规则
*/ */

View file

@ -1,4 +1,5 @@
<?php <?php
if (!defined('ABSPATH')) exit;
//百度收录提示 //百度收录提示
if (gdk_option('gdk_baidurecord_b') && function_exists('curl_init')) { if (gdk_option('gdk_baidurecord_b') && function_exists('curl_init')) {
@ -76,14 +77,6 @@ function force_weauth_login_url($login_url, $redirect, $force_reauth)
add_filter('login_url', 'force_weauth_login_url', 10, 3); add_filter('login_url', 'force_weauth_login_url', 10, 3);
} }
//在登录框添加额外的微信登录
function weixin_login_button()
{
echo '<p><a class="button button-large" href="' . get_permalink(gdk_page_id('weauth')) . '">微信登录</a></p><br>';
}if (gdk_option('gdk_weauth_oauth')) {
add_action('login_form', 'weixin_login_button');
}
//评论微信推送 //评论微信推送
if (gdk_option('gdk_Server') && !is_admin()) { if (gdk_option('gdk_Server') && !is_admin()) {
function sc_send($comment_id) function sc_send($comment_id)
@ -164,60 +157,24 @@ wp_embed_register_handler('youku_iframe', '#http://v.youku.com/v_show/id_(.*?).h
wp_embed_unregister_handler('youku'); wp_embed_unregister_handler('youku');
////////////////weauth////////////// ////////////////weauth//////////////
function weauth_oauth_redirect() //接受奶子微信的账号信息
function get_weauth_oauth()
{ {
wp_redirect(home_url()); if (in_string($_SERVER['REQUEST_URI'], 'weauth')) {
exit; $weauth_user = isset($_GET['user']) ? sanitize_text_field($_GET['user']) : false; //weauth发来用户信息
} $weauth_sk = isset($_GET['sk']) ? sanitize_text_field($_GET['sk']) : false; //weauth返回的12位sk信息
$weauth_res = get_transient($weauth_sk . '-OK');
if (empty($weauth_res) && $weauth_res !== 1) {
function weauth_oauth() return;
{
$weauth_user = $_GET['user'];
$weauth_sk = esc_attr($_GET['sk']);
$weauth_res = get_transient($weauth_sk);
if (empty($weauth_res)) {
return;
}
$weauth_user = stripslashes($weauth_user);
$weauth_user = json_decode($weauth_user, true);
$nickname = $weauth_user['nickName'];
$wxavatar = $weauth_user['avatarUrl'];
$openid = $weauth_user['openid'];
$login_name = 'wx_' . wp_create_nonce($openid);
if (is_user_logged_in()) {
$user_id = get_current_user_id();
update_user_meta($user_id, 'wx_openid', $openid);
update_user_meta($user_id, 'simple_local_avatar', $wxavatar);
} else {
$weauth_user = get_users(array(
'meta_key ' => 'wx_openid',
'meta_value' => $openid,
)
);
if (is_wp_error($weauth_user) || !count($weauth_user)) {
$random_password = wp_generate_password(12, false);
$userdata = array(
'user_login' => $login_name,
'display_name' => $nickname,
'user_pass' => $random_password,
'nickname' => $nickname,
);
$user_id = wp_insert_user($userdata);
update_user_meta($user_id, 'wx_openid', $openid);
update_user_meta($user_id, 'simple_local_avatar', $wxavatar);
} else {
$user_id = $weauth_user[0]->ID;
} }
}
set_transient($weauth_sk . 'ok', $user_id, 60); //用于登录的随机数,有效期为一分钟 $weauth_user = stripslashes($weauth_user);
weauth_oauth_redirect(); $weauth_user = json_decode($weauth_user, true);
} $oauth_result = implode('|', $weauth_user);
//初始化 set_transient($weauth_sk . '-info', $oauth_result, 60); //1分钟缓存
function weauth_oauth_init() header('goauth: ok');
{ echo 'success'; //给对方服务器打个招呼
if (isset($_GET['user']) && isset($_GET['sk'])) { exit;
weauth_oauth();
} }
} }
add_action('init', 'weauth_oauth_init'); add_action('parse_request', 'get_weauth_oauth');