lundi 5 octobre 2015

Hide Author page from others

I am using author.php as an Author page. I have changed the author base slug to "profile" so a post author can view their author page at http://ift.tt/1iYB1e2

As these are basically personal profile pages, I dont want the public to see them so if you visit http://ift.tt/1iYB1e2 and are not logged in it should ask you to login. And if you are logged in and visit the url of someone else profile page it should redirect you back to your profile. Im sort of stuck on this. I came across this on another post and I think its a start:

<?php 
add_action( 'template_redirect', 'wpse14047_template_redirect' );
function wpse14047_template_redirect()
{
if ( is_author() ) {
    $id = get_query_var( 'author' );
    // get_usernumposts() is deprecated since 3.0
    $post_count = count_user_posts( $id );
    if ( $post_count <= 0 ) { 
        //include( STYLESHEETPATH .'/author-redirect.php' );
        wp_redirect( home_url() );
        exit;
    }
}
}

If anyone can help with this it would be appreciated.

Thanks



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire