Created
February 4, 2014 12:25
-
-
Save nikolov-tmw/8802700 to your computer and use it in GitHub Desktop.
Simple plugin that requires users to be logged-in to see any posts from a "projects" custom post type.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Plugin Name: Project Access Control | |
* Description: When a post of post type "project" is displayed and the current user is not logged-in, they are redirected to the login form. | |
* Version: 1 | |
* Author: nikolov.tmw | |
* Author URI: http://paiyakdev.com/ | |
* License: GPL2 | |
*/ | |
/* | |
Copyright 2013 Nikola Nikolov (email: nikolov.tmw@gmail.com) | |
This program is free software; you can redistribute it and/or modify | |
it under the terms of the GNU General Public License, version 2, as | |
published by the Free Software Foundation. | |
This program is distributed in the hope that it will be useful, | |
but WITHOUT ANY WARRANTY; without even the implied warranty of | |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
GNU General Public License for more details. | |
You should have received a copy of the GNU General Public License | |
along with this program; if not, write to the Free Software | |
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | |
*/ | |
function proj_restr_check_auth() { | |
// If we're viewing a "project" and the current user is not logged in | |
if ( 'project' == get_post_type() && ! is_user_logged_in() ) { | |
// Redirect the user to the login page. | |
// They will come back to the current page on successful login | |
auth_redirect(); | |
} | |
} | |
add_action( 'template_redirect', 'proj_restr_check_auth' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment