因为近期博主更换主题,添加了WordPress用户中心,然而发现新的用户中心中不自带第三方绑定插件,然而QQWorld中也不自带页面函数。于是手工写了一个QQWorld插件函数,并完美支持用户中心。接下来分享给大家。
具体代码
/** * 个人中心的绑定账号页面 */ function user_bind_account() { if (is_user_logged_in() == False) { return '<font size="3">该资源<a href="https://'.$_SERVER['HTTP_HOST'].'/wp-login.php?redirect_to='.urlencode('https://'.$_SERVER['HTTP_HOST'].'/user/bind').'" target="_blank"><span style="color: #3366ff;">登录</span></a>后才可访问,如果您没有账号,可以先进行<a href="https://'.$_SERVER['HTTP_HOST'].'/wp-login.php?action=register" target="_blank"><span style="color: #3366ff;">注册</span></a>。</font>'; }//判断用户如果没有登录则让用户登录 $current_bind_user = wp_get_current_user();//获取当前用户信息 $user_bind_qq_appid = '101440114'; $user_bind_weibo_appid = '2147856132'; $user_bind_baidu_appid = 'KrreBj9nroKmFGaEvlV6QyZ6'; //处理QQ相关信息 $user_bind_qq_openid = get_the_author_meta( 'QQWorld Passport QQ Openid',$current_bind_user->ID); $user_bind_qq_url = 'https://graph.qq.com/oauth2.0/authorize?response_type=code&client_id='.$user_bind_qq_appid.'&redirect_uri=https%3A%2F%2Fwww.svlik.com%2Fwp-json%2Fqqworld-passport%2Fv1%2Fmodule%2Fqq%2F&scope=get_user_info,list_album,upload_pic,do_like&state='.md5(uniqid(rand(), TRUE)); if ($user_bind_qq_openid) { //有数据 $user_bind_qq_css = "padding: 8px 10px; -webkit-border-radius: 2px; -moz-border-radius: 2px; border-radius: 2px; background: #a74747; color: #fff;";//红色 $user_bind_qq_zhuangtai = "重新绑定"; } else { //无数据 $user_bind_qq_css = "padding: 8px 10px; -webkit-border-radius: 2px; -moz-border-radius: 2px; border-radius: 2px; background: #09B1B9; color: #fff;";//蓝色 $user_bind_qq_zhuangtai = "立即绑定"; } //处理微博相关信息 $user_bind_weibo_openid = get_the_author_meta( 'QQWorld Passport Weibo Uid',$current_bind_user->ID); $user_bind_weibo_url = 'https://api.weibo.com/oauth2/authorize?client_id='.$user_bind_weibo_appid.'&response_type=code&redirect_uri=https%3A%2F%2Fwww.svlik.com%2Fwp-json%2Fqqworld-passport%2Fv1%2Fmodule%2Fweibo%2F'; if ($user_bind_weibo_openid) { //有数据 $user_bind_weibo_css = "padding: 8px 10px; -webkit-border-radius: 2px; -moz-border-radius: 2px; border-radius: 2px; background: #a74747; color: #fff;";//红色 $user_bind_weibo_zhuangtai = "重新绑定"; } else { //无数据 $user_bind_weibo_css = "padding: 8px 10px; -webkit-border-radius: 2px; -moz-border-radius: 2px; border-radius: 2px; background: #09B1B9; color: #fff;";//蓝色 $user_bind_weibo_zhuangtai = "立即绑定"; } //处理百度相关信息 $user_bind_baidu_openid = get_the_author_meta( 'QQWorld Passport Baidu Openid',$current_bind_user->ID); $user_bind_baidu_url = 'https://openapi.baidu.com/oauth/2.0/authorize?response_type=code&client_id='.$user_bind_baidu_appid.'&redirect_uri=https%3A%2F%2Fwww.svlik.com%2Fwp-json%2Fqqworld-passport%2Fv1%2Fmodule%2Fbaidu%2F&scope=basic&display=page'; if ($user_bind_baidu_openid) { //有数据 $user_bind_baidu_css = "padding: 8px 10px; -webkit-border-radius: 2px; -moz-border-radius: 2px; border-radius: 2px; background: #a74747; color: #fff;";//红色 $user_bind_baidu_zhuangtai = "重新绑定"; } else { //无数据 $user_bind_baidu_css = "padding: 8px 10px; -webkit-border-radius: 2px; -moz-border-radius: 2px; border-radius: 2px; background: #09B1B9; color: #fff;";//蓝色 $user_bind_baidu_zhuangtai = "立即绑定"; } //输出总体数据 return ' <p><strong>腾讯账号:</strong><a class="button" style="'.$user_bind_qq_css.'" href="'.$user_bind_qq_url.'">'.$user_bind_qq_zhuangtai.'</a></p> <p><strong>新浪微博:</strong><a class="button" style="'.$user_bind_weibo_css.'" href="'.$user_bind_weibo_url.'">'.$user_bind_weibo_zhuangtai.'</a></p> <p><strong>百度账号:</strong><a class="button" style="'.$user_bind_baidu_css.'" href="'.$user_bind_baidu_url.'">'.$user_bind_baidu_zhuangtai.'</a></p> '; } add_shortcode('bind_account','user_bind_account');
使用方法
将上述PHP代码放到当前主题 functions.php 文件中,然后在页面中新建页面,内容输入【bind_account】(请将【】替换成小写的[])即可。
qqworld-passport.zip (下载212 )
有那种免备案不用申请QQ互联,代理登录的那种插件有吗
2019-03-04 20:47