给WordPress加上公众号获取密码

给WordPress加上公众号获取密码

上次爱游分享了begin加公众号获取密码的文章,[ WordPress关注微信公众号获取密码 ]有很多不是用begin主题的来咨询其它主题如何实现,今天有空就分享下如何在其它主题也加上这个功能。这里爱游建议先看看这篇文章[ WordPress短代码使用教程 ] 当然你不看也没...

上次爱游分享了begin加公众号获取密码的文章,[ WordPress关注微信公众号获取密码 ]有很多不是用begin主题的来咨询其它主题如何实现,今天有空就分享下如何在其它主题也加上这个功能。

这里爱游建议先看看这篇文章[ WordPress短代码使用教程 ] 当然你不看也没关系,本文会写的很直白,按照操作就能实现,不过爱游建议还是自己懂比什么都好。

首先我们需要以下代码放入functions.php文件

<!–wechatcard start–>

// 加密内容 
function secret($atts, $content=null){
extract(shortcode_atts(array('key'=>null), $atts));
if ( current_user_can('level_10') ) {
	return '<p class="secret-password"><i class="fa fa-clipboard"></i>加密的内容:<br />'.do_shortcode( $content ).'</p>';
}
if(isset($_POST['secret_key']) && $_POST['secret_key']==$key){
	return '<p class="secret-password"><i class="fa fa-clipboard"></i>加密的内容:<br />'.do_shortcode( $content ).'</p>';
	} else {
		return '
		<form class="post-password-form" action="'.get_permalink().'" method="post">
<div class="s-weixin-one">
	<div class="weimg-one">
		<img src="https://www.vipiu.net/wp-content/uploads/2018/10/15395760631.png" alt="weinxin" />
		<div class="weixin-h"><span style="font-size:12px;"><span style="color:#E53333;"><strong>请输入密码查看文章</span></strong></span></div>
		<div class="weixin-h-w"><span style="font-size:12px;">扫一扫左侧二维码关注微信公众号<br/>微信搜索"爱游博客"及"vipiu-net"<br/>关注公众号并发送:<span style="color:#E53333;"><b>'.get_the_ID().'</b></span>&nbsp;获取密码.</span></span></div>
		<div class="clear"></div>
				<input id="pwbox" type="password" size="20" name="secret_key">
				<input type="submit" value="' . sprintf(__( '提交', 'begin' )) . '" name="Submit">
</div></div>
		</form>	';
	}
}
add_shortcode('password','secret');

里面的图片链接和一些文字自己手动修改下。

然后把以下css放入style.css即可。

.clear {
	clear:both;
	display:block
}
.secret-password .fa {
	font-size:16px!important;
	color:#c40000;
	margin:0 5px 0 0
}
.post-password-form {
	margin:15px 0;
	padding:15px 5px;
	border-radius:2px;
}
.post-password-form p {
	margin:0 0 0 12px
}
.post-password-form input[type="password"] {
	width:40%;
	height:38px;
	line-height:30px;
	background:#fff;
	padding:5px;
	border-radius:2px;
	border:1px solid #ddd;
	-webkit-appearance:none
}
.post-password-form input[type="submit"] {
	width:80px;
	line-height:25px;
	background:#ddd;
	padding:5px;
	cursor:pointer;
	border-radius:2px;
	border:1px solid #ddd;
	-webkit-appearance:none
}
.post-password-form input[type="submit"]:hover {
	background:#3690cf;
	color:#fff!important;
	border:1px solid #3690cf
}
.s-weixin-one {
	width:400px;
	margin:10px auto 20px
}
@media screen and (max-width:480px) {
	.s-weixin-one {
	width:100%
}
}.weimg-one {
	padding:5px;
	border:1px dashed #ccc
}
.weimg-one img {
	float:left;
	width:30%;
	height:auto;
	margin:0 10px 0 0
}
.weimg-one .weixin-h,.weimg-one .weixin-h-w {
	float:left;
	width:65%
}
.weimg-one .weixin-h-w {
	color:#999
}

<!–wechatcard end–>

效果图如下:

原文链接:https://www.vipiu.net/archives/2020/02/02/6410.html,转载请注明出处。
0

评论0

请先

会员低至49元,开通享海量VIP资源免费下载 自助开通
显示验证码
没有账号?注册  忘记密码?