我很难找到解决方案:
我有一堆限制内容的帖子,要访问这些页面的内容,用户必须提交一个重力表单。我想最好的方法是在gform_after_submission
发生。然后,函数将检查该cookie并根据结果显示这个或那个。问题是:我需要每个帖子都有一个cookie,而不是整个网站都有一个cookie。这就是我现在拥有的:
Creating cookie after submission. 我的想法是使用post id来命名cookie并使其唯一。在这之后,但我不会离开这里。
add_action( \'gform_after_submission_1\', \'create_cookie\' );
function create_cookie() {
setcookie( \'cookie\'.get_the_ID(), 1, strtotime( \'+30 days\' ), COOKIEPATH, COOKIE_DOMAIN, false, false);
}
Checking if that cookie exists. 因此,提交后,页面将重新加载并设置cookie,浏览器将检测到它,一切都会发生。add_filter( \'the_content\', \'checkingCookie\' );
function checkingCookie($content) {
if( !isset( $_COOKIE[\'cookie\'.get_the_ID()] ) ) {
return \'no cookies!\';
}
else {
return \'cookies!\';
}
}
问题是,在给定页面中创建的这个特定cookie应该只能在其原始帖子中检测到,这样,如果我转到另一篇帖子,那里的内容仍然会受到限制,并等待自己的提交来释放内容。那么,有什么想法吗?