这个the_content
过滤器将用于此。此过滤器允许您更改the_content()
和get_the_content()
:
add_filter( \'the_content\', \'wpse_members_only\', 20 );
function wpse_members_only( $content ) {
// If user is not logged in, show restricted content message.
// Change this conditional statement based on how you want to check for
// membership status. I\'d suggest using capabilites, e.g. current_user_can( $capability , $object_id );
if ( ! is_user_logged_in() ) {
$content = __( \'Sorry, this content is reserved for members only.\', \'text-domain\' );
}
return $content;
}