Changeset 848798
- Timestamp:
- 01/31/2014 12:32:49 PM (12 years ago)
- Location:
- redirect-to-login-if-not-logged-in/trunk
- Files:
-
- 2 edited
-
dmk-redirect-if-not-logged-in.php (modified) (2 diffs)
-
readme.txt (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
redirect-to-login-if-not-logged-in/trunk/dmk-redirect-if-not-logged-in.php
r724668 r848798 2 2 /** 3 3 * @package Redirect to login if not logged in 4 * @version 1. 34 * @version 1.4 5 5 */ 6 6 /* … … 9 9 Description: Redirect to wp-login.php if user is not logged in. 10 10 Author: Daan Kortenbach 11 Version: 1. 311 Version: 1.4 12 12 Author URI: http://daan.kortenba.ch/ 13 13 */ 14 14 15 add_action( ' wp', 'dmk_not_loggedin_redirect' );15 add_action( 'init', 'dmk_not_loggedin_redirect' ); 16 16 17 17 /** 18 * Redirect to wp-login.php if user is not logged in.18 * Conditional: if user is not logged in and is not on wp-login.php, call redirect on hook 'wp'. 19 19 * 20 20 * @author Daan Kortenbach 21 21 * 22 22 * @global string $pagenow 23 * @return void redirect23 * @return void 24 24 */ 25 25 function dmk_not_loggedin_redirect() { 26 26 global $pagenow; 27 27 28 if ( ! is_user_logged_in() && $pagenow != 'wp-login.php' ) 29 wp_redirect( wp_login_url(), 302 ); 28 if ( ! is_user_logged_in() && $pagenow != 'wp-login.php' ) { 29 add_action( 'wp', 'dmk_not_loggedin_do_redirect' ); 30 } 30 31 } 32 33 /** 34 * Redirect to wp-login.php. 35 * 36 * @author Daan Kortenbach 37 * 38 * @return void redirect 39 */ 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
r724668 r848798 4 4 Tags: redirect, login 5 5 Requires at least: 3.0.1 6 Tested up to: 3. 67 Stable tag: 1. 36 Tested up to: 3.8.1 7 Stable tag: 1.4 8 8 License: GPLv2 or later 9 9 License URI: http://www.gnu.org/licenses/gpl-2.0.html … … 22 22 == Changelog == 23 23 24 = 1.4 = 25 * Moved the conditionals to the init hook due to some edge cases not redirecting. 26 24 27 = 1.3 = 25 28 * Plugin naming.
Note: See TracChangeset
for help on using the changeset viewer.