已收录'; } else { echo '未收录'; } } } //百度主动推送 if (gdk_option('gdk_sitemap_api')) { function gdk_Baidu_Submit($post_ID) { if (1 == get_post_meta($post_ID, 'gdk_baidu_submit', true)) { return; } $url = get_permalink($post_ID); $api = gdk_option('gdk_sitemap_api'); $request = new WP_Http(); $result = $request->request($api, [ 'method' => 'POST', 'body' => $url, 'headers' => 'Content-Type: text/plain', ]); if (is_array($result) && !is_wp_error($result) && '200' == $result['response']['code']) { error_log('baidu_submit_result:'.$result['body']); $result = json_decode($result['body'], true); } if (array_key_exists('success', $result)) { add_post_meta($post_ID, 'gdk_baidu_submit', 1, true); } } add_action('publish_post', 'gdk_Baidu_Submit', 0); } //强制微信登录 function force_weauth_login_url($login_url, $redirect, $force_reauth) { $login_url = get_permalink(gdk_page_id('weauth')); if (!empty($redirect)) { $login_url = add_query_arg('redirect_to', urlencode($redirect), $login_url); } if ($force_reauth) { $login_url = add_query_arg('reauth', '1', $login_url); } return $login_url; } if (gdk_option('gdk_weauth_oauth') && gdk_option('gdk_weauth_oauth_force')) { add_filter('login_url', 'force_weauth_login_url', 10, 3); } //在登录框添加额外的微信登录 function weixin_login_button() { echo '

微信登录


'; } if (gdk_option('gdk_weauth_oauth')) { add_action('login_form', 'weixin_login_button'); } //评论微信推送 if (gdk_option('gdk_Server') && !is_admin()) { function sc_send($comment_id) { $text = '网站上有新的评论,请及时查看'; //微信推送信息标题 $comment = get_comment($comment_id); $desp = ''.$comment->comment_content.' ***
* 评论人 :'.get_comment_author($comment_id).' * 文章标题 :'.get_the_title().' * 文章链接 :'.get_the_permalink($comment->comment_post_ID).' '; //微信推送内容正文 $key = gdk_option('gdk_Server_key'); $postdata = http_build_query([ 'text' => $text, 'desp' => $desp, ]); $opts = [ 'http' => [ 'method' => 'POST', 'header' => 'Content-type: application/x-www-form-urlencoded', 'content' => $postdata, ], ]; $context = stream_context_create($opts); return $result = file_get_contents('http://sc.ftqq.com/'.$key.'.send', false, $context); } add_action('comment_post', 'sc_send', 19, 2); } //增加B站视频 wp_embed_unregister_handler('bili'); function wp_bili($matches, $attr, $url, $rawattr) { if (gdk_is_mobile()) { $height = 200; } else { $height = 480; } $iframe = ''; return apply_filters('iframe_bili', $iframe, $matches, $attr, $url, $ramattr); } wp_embed_register_handler('bili_iframe', '#https://www.bilibili.com/video/av(.*?)/#i', 'wp_bili'); //bing美图自定义登录页面背景 function gdk_custom_login_head() { if (gdk_option('gdk_loginbg')) { $imgurl = gdk_get_bing_img(); } echo ''; } add_action('login_head', 'gdk_custom_login_head'); // add youku using iframe function wp_iframe_handler_youku($matches, $attr, $url, $rawattr) { if (gdk_is_mobile()) { $height = 200; } else { $height = 485; } $iframe = ''; return apply_filters('iframe_youku', $iframe, $matches, $attr, $url, $ramattr); } wp_embed_register_handler('youku_iframe', '#http://v.youku.com/v_show/id_(.*?).html#i', 'wp_iframe_handler_youku'); wp_embed_unregister_handler('youku'); ////////////////weauth////////////// /* function weauth_oauth_redirect() { wp_redirect(home_url()); exit; } function get_weauth_token() { $sk = date("YmdHis") . mt_rand(10, 99); set_transient($sk, 1, 60 * 6); $key = $_SERVER['HTTP_HOST'] . '@' . $sk; return $key; } function get_weauth_qr() { $qr64 = []; $qr64['key'] = get_weauth_token(); $qr64['qrcode'] = json_decode(file_get_contents('https://wa.isdot.net/qrcode?str=' . $qr64['key']), true)['qrcode']; return $qr64; } function weauth_rewrite_rules($wp_rewrite) { if ($ps = get_option('permalink_structure')) { $new_rules['^weauth'] = 'index.php?user=$matches[1]&sk=$matches[2]'; $wp_rewrite->rules = $new_rules + $wp_rewrite->rules; } } add_action('generate_rewrite_rules', 'weauth_rewrite_rules'); function weauth_oauth() { $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_oauth_redirect(); } //初始化 /* function weauth_oauth_init() { if (isset($_GET['user']) && isset($_GET['sk'])) { weauth_oauth(); } } add_action('init', 'weauth_oauth_init'); /* //GET自动登录 function gdk_weauth_oauth_login() { $key = isset($_GET['spam']) ? $_GET['spam'] : false; if ($key) { $user_id = get_transient($key . 'ok'); if ($user_id != 0) { wp_set_auth_cookie($user_id); } } } add_action('init', 'gdk_weauth_oauth_login');