我有一个类别(使用插件)是会员专用的。如果一篇文章被赋予了一个仅为成员的类别,并且一个对每个人都可用的类别,会发生什么情况?如果每个人都可以访问它,我该如何防止?
如果一个帖子有两个不同权限的类别,会发生什么?
1 个回复
最合适的回答,由SO网友:NerdOfLinux 整理而成
我对它进行了测试,默认情况下,它将向所有人显示它,即使其中一个类别是仅限成员。如果您需要对此进行修复(像我一样),请在中使用以下内容functions.php
:
function my_filter( $content ) {
$categories = array(
\'news\',
\'opinions\',
\'sports\',
\'other\',
);
if ( in_category( $categories ) ) {
if ( is_logged_in() ) {
return $content;
} else {
$content = \'<p>Sorry, this post is only available to members</p>\';
return $content;
}
} else {
return $content;
}
}
add_filter( \'the_content\', \'my_filter\' );
从我的另一个question.结束