Plugin Directory

Changeset 848798


Ignore:
Timestamp:
01/31/2014 12:32:49 PM (12 years ago)
Author:
daankortenbach
Message:

Moved the conditionals to the init hook due to some edge cases not redirecting.

Location:
redirect-to-login-if-not-logged-in/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • redirect-to-login-if-not-logged-in/trunk/dmk-redirect-if-not-logged-in.php

    r724668 r848798  
    22/**
    33 * @package Redirect to login if not logged in
    4  * @version 1.3
     4 * @version 1.4
    55 */
    66/*
     
    99Description: Redirect to wp-login.php if user is not logged in.
    1010Author: Daan Kortenbach
    11 Version: 1.3
     11Version: 1.4
    1212Author URI: http://daan.kortenba.ch/
    1313*/
    1414
    15 add_action( 'wp', 'dmk_not_loggedin_redirect' );
     15add_action( 'init', 'dmk_not_loggedin_redirect' );
    1616
    1717/**
    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'.
    1919 *
    2020 * @author Daan Kortenbach
    2121 *
    2222 * @global string $pagenow
    23  * @return void redirect
     23 * @return void
    2424 */
    2525function dmk_not_loggedin_redirect() {
    2626    global $pagenow;
    2727
    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    }
    3031}
     32
     33/**
     34 * Redirect to wp-login.php.
     35 *
     36 * @author Daan Kortenbach
     37 *
     38 * @return void redirect
     39 */
     40function 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  
    44Tags: redirect, login
    55Requires at least: 3.0.1
    6 Tested up to: 3.6
    7 Stable tag: 1.3
     6Tested up to: 3.8.1
     7Stable tag: 1.4
    88License: GPLv2 or later
    99License URI: http://www.gnu.org/licenses/gpl-2.0.html
     
    2222== Changelog ==
    2323
     24= 1.4 =
     25* Moved the conditionals to the init hook due to some edge cases not redirecting.
     26
    2427= 1.3 =
    2528* Plugin naming.
Note: See TracChangeset for help on using the changeset viewer.