WordPress根据最后一次评论时间隐藏评论者链接
本文最后更新于 660 天前,文中的信息可能已经有所变化。如有误,请留言反馈。

本文将介绍依据评论者最后一次评论时间来决议能否显现评论者链接的实现方法,比如评论者的最后一次评论时间离现在超过30天,就制止显现评论者网站链接,此方法可用于加强对评论的控制。

  • 将以下代码添加到正在使用主题的 functions.php 文件内:
/**
* wordpress根据评论者最后一次评论时间来决定是否显示评论者链接
*/
function lxtx_show_comment_author_link( $return , $author, $comment_ID ){
if ( !is_user_logged_in() ) { // 登录用户无鸭梨
date_default_timezone_set('PRC');
$limit_days = 10; // 天数,代表最后一次评论时间距离今天超过10天的话,则隐藏评论链接
$comment = get_comment( $comment_ID );
if ( !empty($comment->comment_author_email) ) {
$last_comment = get_comments(array(
'author_email' => $comment->comment_author_email,
'number' => '1',
'orderby' => 'comment_date',
'order' => 'DESC',
'status' => 'approve',
'type' => 'comment'
));
if ( (time() - strtotime($last_comment->comment_date)) > $limit_days*24*3600 ) {
$return = $author;
}
}else{
$return = $author;
}
}
return $return;
}
add_filter('get_comment_author_link','lxtx_show_comment_author_link', 10, 3);

*仅适用于 the_author_link()来输出评论者昵称的主题。

*$limit_days = 10;的参数按需修改,这里的10为距离当天多少天。

  • 第二种:
// 评论链接跳转内链
function commentauthor($comment_ID = 0) {
$comment_temp = get_comment( $comment_ID );
$author = $comment_temp->comment_author;
$url = $comment_temp->comment_author_url ;
$email = $comment_temp->comment_author_email;
$cmuserid = $comment_temp->user_id;
$limit_days = 30; // 天数,最后一次评论时间距离今天超过 $limit_days 天则隐藏评论链接
if ( $cmuserid > 0 ) {
echo "$author";
} else if ( empty( $url ) || 'http://' == $url ) {
echo $author;
} else if ( !empty( $email ) && !is_user_logged_in() ) {
date_default_timezone_set('PRC'); //时区
$last_comment = get_comments(array(
'author_email' => $email,
'number' => '1',
'orderby' => 'comment_date',
'order' => 'DESC',
'status' => 'approve',
'type' => 'comment'
));

if ( ( current_time('timestamp') - strtotime( $last_comment['0']->comment_date ) ) > $limit_days*24*3600 ) {
echo "$author";
} else {
echo "$author";
}
} else {
echo "$author";
}
}

需配合主题修改。

暂无评论

发送评论 编辑评论


				
|´・ω・)ノ
ヾ(≧∇≦*)ゝ
(☆ω☆)
(╯‵□′)╯︵┴─┴
 ̄﹃ ̄
(/ω\)
∠( ᐛ 」∠)_
(๑•̀ㅁ•́ฅ)
→_→
୧(๑•̀⌄•́๑)૭
٩(ˊᗜˋ*)و
(ノ°ο°)ノ
(´இ皿இ`)
⌇●﹏●⌇
(ฅ´ω`ฅ)
(╯°A°)╯︵○○○
φ( ̄∇ ̄o)
ヾ(´・ ・`。)ノ"
( ง ᵒ̌皿ᵒ̌)ง⁼³₌₃
(ó﹏ò。)
Σ(っ °Д °;)っ
( ,,´・ω・)ノ"(´っω・`。)
╮(╯▽╰)╭
o(*////▽////*)q
>﹏<
( ๑´•ω•) "(ㆆᴗㆆ)
😂
😀
😅
😊
🙂
🙃
😌
😍
😘
😜
😝
😏
😒
🙄
😳
😡
😔
😫
😱
😭
💩
👻
🙌
🖕
👍
👫
👬
👭
🌚
🌝
🙈
💊
😶
🙏
🍦
🍉
😣
Source: github.com/k4yt3x/flowerhd
颜文字
Emoji
小恐龙
花!
上一篇
下一篇