自定义WordPress评论Cookie功能

ė 65 6 0
本文最近更新于24.08.5 周一请自行判断新内容

https://www.xintheme.com/wpjiaocheng/120166.html

function comment_form_change_cookies_consent( $fields ) {
$commenter = wp_get_current_commenter();
$consent = empty( $commenter['comment_author_email'] ) ? '' : ' checked="checked"';
$fields['cookies'] = '<p class="comment-form-cookies-consent"><input id="wp-comment-cookies-consent" name="wp-comment-cookies-consent" type="checkbox" value="yes"' . $consent . ' />' .
'<label for="wp-comment-cookies-consent">记住我的信息</label></p>';
return $fields;
}
add_filter( 'comment_form_default_fields', 'comment_form_change_cookies_consent' );

默认不勾选文章源自知更鸟-https://zmingcx.com

/custom-wordpress-comment-on-cookies.html

function comment_form_not_checked_cookies_consent( $fields ) {$fields['cookies'] = '<p class="comment-form-cookies-consent"><input id="wp-comment-cookies-consent" name="wp-comment-cookies-consent" type="checkbox" value="yes" />' .'<label for="wp-comment-cookies-consent">记住我的信息</label></p>';
return $fields;
}
add_filter( 'comment_form_default_fields', 'comment_form_not_checked_cookies_consent' );

源代码出自:https://wordpress.org/support/topic/update-4-9-6-checkbox-comments-privacy-approved/文章源自知更鸟-https://zmingcx.com/custom-wordpress-comment-on-cookies.html

如果你的主题使用了自定义评论函数,评论模块中没出现记录评论Cookie的复选框,可以使用下面的代码添加该功能,默认记录Cookie并隐藏难看的复选框:文章源自知更鸟-https://zmingcx.com/custom-wordpress-comment-on-cookies.html


add_action('set_comment_cookies','coffin_set_cookies',10,3);
function coffin_set_cookies( $comment, $user, $cookies_consent){
$cookies_consent = true;
wp_set_comment_cookies($comment, $user, $cookies_consent);
}

源代码出自:https://fatesinger.com/100240文章源自知更鸟-https://zmingcx.com/custom-wordpress-comment-on-cookies.html

如你的主题使用了的AJAX 提交评论,已默认记录Cookie, 无需上面的操作。文章源自知更鸟-https://zmingcx.com/custom-wordpress-comment-on-cookies.html

想完全禁用这个功能,可以用下面的代码:文章源自知更鸟-https://zmingcx.com/custom-wordpress-comment-on-cookies.html

function comment_form_hide_cookies_consent( $fields ) {unset( $fields['cookies'] );return $fields;}
add_filter( 'comment_form_default_fields', 'comment_form_hide_cookies_consent' );

或者文章源自知更鸟-https://zmingcx.com/custom-wordpress-comment-on-cookies.html

来源- - 通过投稿渠道发表
  • 灵魂发问:谁告诉你我国防空洞位置了吗?怕是99%中国人不知道,我也不知道,为什么,因为没告诉咱们啊!怕是很多当官的都不晓得吧!所以别老想着打这个那个,真打起来,你躲都不知道躲哪?最好的位置是到没有军事区,机场等落后位置,因为人家炸这些位置不仅没有利益还会被国际谴责。 --- 2025/03/08
主机推荐
:网友留言区仅供网友表达其个人观点,并不表明栖息邦最终立场。



管理员登录
注册

提示:点击上下面区域关闭

字号调整

View My Stats
空位 空位
本次加载耗时:0.551s