Skip to content

Instantly share code, notes, and snippets.

@evansolomon
Created December 30, 2011 05:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save evansolomon/1538036 to your computer and use it in GitHub Desktop.
Save evansolomon/1538036 to your computer and use it in GitHub Desktop.
A more private way to use WordPress without the hassle of passwords and such. Logged out users can only single posts, and only if they know the exact URL.
<?php
/*
Plugin Name: Privacy Please
Description: A more private way to use WordPress without the hassle of passwords and such. Logged out users can only access single posts, and only if they know the exact URL.
Author: Evan Solomon
*/
/* Only allow singe page views */
function only_singular_requests_for_you() {
if( ! is_user_logged_in() && ! is_singular() )
wp_die( 'We can haz privacy' );
}
add_action( 'pre_get_posts', 'only_singular_requests_for_you' );
/* Don't let anyone guess URL's */
function no_redirects_for_you( $redirect_url) {
if( is_user_logged_in() )
return $redirect_url;
wp_die( 'We can haz privacy' );
}
add_filter( 'redirect_canonical', 'no_redirects_for_you' );
/* Don't give away other URL's with adjacent post links */
function no_adjacent_posts_for_you( $format ) {
if( is_user_logged_in() )
return $format;
return false;
}
add_filter( 'previous_post_link', 'no_adjacent_posts_for_you' );
add_filter( 'next_post_link', 'no_adjacent_posts_for_you' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment