此代码过滤自定义帖子类型的内容“;新闻“;,你说;“特定页面”;因此,这可以根据您的需要进行调整。然后它检查用户是否是订阅者,如果是,则显示内容,否则,它只会说;不允许;。
function filter_content($content) {
global $post;
if ( $post->post_type == \'news\' ) { //Specify your pages here
$currentuser = wp_get_current_user();
if ( in_array( \'subscriber\', (array) $currentuser->roles ) ) {
return $content;
} else {
echo \'Not allowed\';
}
}
}
add_filter(\'the_content\', \'filter_content\');`