Skip to content

Instantly share code, notes, and snippets.

@luistinygod
Created January 9, 2015 17:19
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 luistinygod/2106e24ec24f85997674 to your computer and use it in GitHub Desktop.
Save luistinygod/2106e24ec24f85997674 to your computer and use it in GitHub Desktop.
GravityView Force not logged users to login before seeing the single entry view
<?php
/*
Plugin Name: GravityView - force login before single view
Plugin URI: https://gravityview.co/
Description: Redirect visitors to login page before seeing the single entry view
Author: Katz Web Services, Inc.
Version: 1.0.0
Author URI: http://www.katzwebservices.com
Copyright 2015 Katz Web Services, Inc. (email: info@katzwebservices.com)
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
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, see <http://www.gnu.org/licenses/>.
*/
// tested with GravityView version 1.5.3
/**
* Please adapt the login page to your own needs. Default is to WordPress login screen.
*
* Thanks to http://kovshenin.com/2012/current-url-in-wordpress/
*/
add_action( 'template_redirect', 'my_gv_force_login');
function my_gv_force_login() {
if( class_exists('GravityView_frontend') && GravityView_frontend::is_single_entry() ) {
if( !is_user_logged_in() ) {
global $wp;
$current_url = add_query_arg( $wp->query_string, '', home_url( $wp->request ) );
wp_redirect( wp_login_url( $current_url ), 301 );
exit;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment