WordPress代码-好玩的内容警告代码

WordPress代码-好玩的内容警告代码

每天十分钟,get一个新技能。让学习成为习惯,让分享传递价值。

“老司机”站长请继续浏览,未成年人请略过,谢谢!

[warning]  有时候我们的博客需要分享一些羞羞的内容,按惯例及服务器所在国家法律要求,是必须要在浏览前显示“成人内容警告”的,以提示方可内容可能不适宜未成年人或引起不适。对于wordpress来说就很简单,简单的一段代码就能实现。[/warning]

[danger]要实现这样的功能,我们需要wordpress在wp_loaded的时候判断指定cookie是否存在,以确定是否是该浏览者是否已经浏览警告页面。如果该cookie不存在则显示警告页面,并且在浏览者点击确认后写入cookie。[/danger]

[warning]

<?php
if(class_exists('AdultContentsWarning')) return;
class AdultContentsWarning{
var $path;
function __construct(){
add_action('wp_loaded',array($this,'isAdult'));
$path= parse_url(untrailingslashit(home_url()))['path'] === NULL ? parse_url($_SERVER['REQUEST_URI'] )['path'] :
explode(parse_url(untrailingslashit(home_url()))['path'],parse_url($_SERVER['REQUEST_URI'] )['path'])[0];
}
function isAdult(){
if(is_user_logged_in() === true) return;
if(!isset($_COOKIE['isAdult']) || $_COOKIE['isAdult'] != 'yes'){
if($_POST['isAdult'] == 'yes'){
if(setcookie('isAdult','yes',time()+3600*24) === true){
echo 'success';
die;
}
}
else{
$this->show_warning();
die();
}
}
return;
}
private function show_warning(){
?>
<html>
<head>
<title>成人内容警告 - <?php bloginfo('name');?></title>
<meta name="description" content="">
<meta name="keywords" content="">
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<script type="text/javascript" src="<?php echo home_url('/wp-includes/js/jquery/jquery.js'); ?>"></script>
</head>
<style type="text/css">
a{text-decoration:none;color:#0000FF}
a:hover{text-decoration:underline;}
</style>
<body bgcolor="#FFFFFF" text="#000000">
<p align="center"><font color="#FF0000"><b>警告 / WARNING </b><br>
</font><br>
本物品內容可能令人反感;不可將本物品內容派發,傳閱,出售,出租,交給<br>
或出借予年齡未滿 18 歲的人士出示,播放或播映。<br>
<br>
<font size="1" face="Verdana">This article contains material which may offernd and may not be
distributed, circulated, sold, hired, given, lent, shown, <br>
played or projected to a person under the age of 18 years. All models are 18 or
older. </font><br>
</p>
<p align="center">
<b>
<font size="7" face="Verdana">
<a href="javascript::" id="confirm">__ 滿 18 歲,
請按此 __</a></font></b><BR><BR>
<a href="javascript::" id="close">退出浏览</a>
</p>
<script>
jQuery(document).ready(function($) {
$("#confirm").click(function(){
$.post("",{isAdult:'yes'},function(result){
if(result == 'success'){
if (getCookie('isAdult') != false){
location.reload(true);
}else{
alert('Cookie写入失败!');
location.reload(false);
}
}
});
});
$("#close").click(function(){
if(window.history.go(-1) == undefined){
window.location.href="about:blank";
}
else{
window.history.go(-1);
}
});
});
function getCookie(c_name)
{
if (document.cookie.length>0)
{
c_start=document.cookie.indexOf(c_name + "=")
if (c_start!=-1)
{
c_start=c_start + c_name.length+1
c_end=document.cookie.indexOf(";",c_start)
if (c_end==-1) c_end=document.cookie.length
return unescape(document.cookie.substring(c_start,c_end))
}
}
return false
}
</script>
</body></html>
<?php
}
}
new AdultContentsWarning();
?>

[/warning]

人气调教大神【沧桑S】TG付费完整版 各种虐调妹子【27v/7.36g】
人气调教大神【沧桑S】TG付费完整版 各种虐调妹子【27v/7.36g】
8分钟前 有人购买 去瞅瞅看
充值活动:即日起,充20送20元,充50送50元,充100送100元,点此前往充值
显示验证码
没有账号?注册  忘记密码?

社交账号快速登录