Quantcast
Channel: Topic Tag: plugin | WordPress.org
Viewing all articles
Browse latest Browse all 26892

Micah Wood on "problems with WP_Query and my plugin"

$
0
0

It appears as though you want to alter the content only if you are on a post in the 'private' category and the user is not logged in. Here is what I would recommend:

add_action( 'init', 'my_init' );
function my_init() {
    if( in_category( 'private' ) && ! is_user_logged_in() ) {
        add_filter( 'the_content', 'post_restrictor' );
    }
}
function post_restrictor( $content ) {
    $content = "Sorry, you don't have access to this post.  Please login.";
    return $content;
}

Viewing all articles
Browse latest Browse all 26892

Trending Articles