Changeset 848912
- Timestamp:
- 01/31/2014 05:10:52 PM (12 years ago)
- Location:
- redirect-to-login-if-not-logged-in/trunk
- Files:
-
- 2 edited
-
dmk-redirect-if-not-logged-in.php (modified) (1 diff)
-
readme.txt (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
redirect-to-login-if-not-logged-in/trunk/dmk-redirect-if-not-logged-in.php
r848798 r848912 2 2 /** 3 3 * @package Redirect to login if not logged in 4 * @version 1. 44 * @version 1.5 5 5 */ 6 6 /* 7 7 Plugin Name: Redirect to login if not logged in 8 8 Plugin URI: http://wordpress.org/plugins/redirect-to-login-if-not-logged-in/ 9 Description: Redirect to wp-login.php if user is not logged in.9 Description: Redirects a user to the login page if the user is not logged in. After login the user gets redirected to the original entry page. 10 10 Author: Daan Kortenbach 11 Version: 1. 411 Version: 1.5 12 12 Author URI: http://daan.kortenba.ch/ 13 13 */ 14 14 15 add_action( 'init', 'dmk_not_loggedin_redirect' ); 15 add_action( 'parse_request', 'dmk_redirect_to_login_if_not_logged_in', 1 ); 16 /** 17 * Redirects a user to the login page if not logged in. 18 * 19 * @author Daan Kortenbach 20 */ 21 function dmk_redirect_to_login_if_not_logged_in() { 22 is_user_logged_in() || auth_redirect(); 23 } 16 24 25 26 add_filter( 'login_url', 'dmk_strip_loggedout', 1, 1 ); 17 27 /** 18 * Conditional: if user is not logged in and is not on wp-login.php, call redirect on hook 'wp'.28 * Strips '?loggedout=true' from redirect url after login. 19 29 * 20 30 * @author Daan Kortenbach 21 31 * 22 * @ global string $pagenow23 * @return void32 * @param string $login_url 33 * @return string $login_url 24 34 */ 25 function dmk_not_loggedin_redirect() { 26 global $pagenow; 27 28 if ( ! is_user_logged_in() && $pagenow != 'wp-login.php' ) { 29 add_action( 'wp', 'dmk_not_loggedin_do_redirect' ); 30 } 35 function dmk_strip_loggedout( $login_url ) { 36 return str_replace( '%3Floggedout%3Dtrue', '', $login_url ); 31 37 } 32 33 /**34 * Redirect to wp-login.php.35 *36 * @author Daan Kortenbach37 *38 * @return void redirect39 */40 function dmk_not_loggedin_do_redirect() {41 wp_redirect( wp_login_url(), 302 );42 exit;43 } -
redirect-to-login-if-not-logged-in/trunk/readme.txt
r848798 r848912 5 5 Requires at least: 3.0.1 6 6 Tested up to: 3.8.1 7 Stable tag: 1. 47 Stable tag: 1.5 8 8 License: GPLv2 or later 9 9 License URI: http://www.gnu.org/licenses/gpl-2.0.html … … 13 13 == Description == 14 14 15 Redirects site visitors to the login page if the visitor is not logged in. This plugin is used fairly often for sites in development or sites only available for registered users.15 Redirects a user to the login page if the user is not logged in. After login the user gets redirected to the original entry page. This plugin is used fairly often for sites in development or sites only available for registered users. 16 16 17 17 == Installation == … … 21 21 22 22 == Changelog == 23 24 = 1.5 = 25 * Complete rewrite to use the already existing auth_redirect hook. 26 * Strips '?loggedout=true' from redirect url after login. 23 27 24 28 = 1.4 =
Note: See TracChangeset
for help on using the changeset viewer.