🔒 EXCLUSIVE: Changeset/ - Full Gallery 2025

Changeset 1940138


Ignore:
Timestamp:
09/12/2018 04:51:27 PM (7 years ago)
Author:
daankortenbach
Message:

Tested up to bumped to 4.5 in tagged release 1.7.0

Location:
redirect-to-login-if-not-logged-in
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • redirect-to-login-if-not-logged-in/tags/trunk/readme.txt

    r848912 r1940138  
    11=== Redirect to login if not logged in ===
     2
     3Plugin Name: Redirect to login if not logged in
     4Plugin URI: http://wordpress.org/plugins/redirect-to-login-if-not-logged-in/
    25Contributors: daankortenbach
    3 Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=BKUCJXJJ8XJVY
    46Tags: redirect, login
    57Requires at least: 3.0.1
    6 Tested up to: 3.8.1
    7 Stable tag: 1.5
     8Tested up to: 5.0
     9Stable tag: 1.7.0
     10Version: 1.7.0
    811License: GPLv2 or later
    912License URI: http://www.gnu.org/licenses/gpl-2.0.html
    1013
    11 Redirects site visitors to the login page if the visitor is not logged in.
     14Redirects users to the login page if the visitor is not logged in.
    1215
    1316== Description ==
    1417
    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.
     18Redirects users to the login page if the user is not logged in. After login the user gets redirected to the original entry page. For advanced users a filter is provided to override the redirect.
     19
     20The principle behind this plugin is to redirect all users - from every post, page, archive, etc. - to the login page (usually wp-login.php). Except for the override filter it does nothing else.
     21
     22= Overriding the redirect =
     23
     24* **Note:** This plugin may not be for you, a membership plugin might be a better fit. Chris Lema writes excellent reviews of +30 membership plugins here: http://chrislema.com/category/memberships-plugins/
     25
     26If you do have a need for this plugin and you want to exclude specific views under specific conditions, a filter is provided to override the redirect.
     27
     28To override the redirect the filter must return a boolean value of `true`. WordPress core provides many conditional tags that either return `true` or `false` or you can write your own conditionals.
     29
     30Take a look at the Conditional Tags page on The WordPress Codex for some inspiration.
     31https://codex.wordpress.org/Conditional_Tags
     32
     33**Usage:**
     34Copy/paste/edit an example to the functions.php of your theme or create a new file in wp-content/mu-plugins/ if you do not wish to edit your theme.
     35
     36_Note: Be carefull not to use multiple filters at the same time as that may cause unexpected results. Instead use multiple conditions in one filter._
     37
     38* Override if the front page is either posts or a page:
     39
     40  ```add_filter( 'rtl_override_redirect', 'is_front_page' );```
     41
     42* Override if the post is 'hello-world':
     43
     44  ```add_filter( 'rtl_override_redirect', function() { 
     45    return is_single( 'hello-world' ); 
     46  });```
     47
     48* Override if the page is 'sample-page':
     49
     50  ```add_filter( 'rtl_override_redirect', function() { 
     51    return is_page( 'sample-page' ); 
     52  });```
     53
     54* Override if the page ID is 42, the slug is 'sample-page' or the title is 'About Me':
     55
     56  ```add_filter( 'rtl_override_redirect', function() { 
     57    return is_page( array( 42, 'sample-page', 'About Me' ) ); 
     58  });```
     59
     60* Override if the page ID is 42 or a post is 'hello-world':
     61
     62  ```add_filter( 'rtl_override_redirect', function() { 
     63    if ( is_page( 42 ) || is_single( 'hello-world' ) ) { 
     64        return true; 
     65    } 
     66  });```
    1667
    1768== Installation ==
    1869
    19 1. Upload `plugin-name.php` to the `/wp-content/plugins/` directory
     701. Upload `redirect-to-login-if-not-logged-in` to the `/wp-content/plugins/` directory
    20711. Activate the plugin through the 'Plugins' menu in WordPress
    2172
    2273== Changelog ==
     74
     75= 1.7.0 =
     76* Add redirect override filter.
     77* Add filter examples.
     78
     79= 1.6.3 =
     80* Fix svn repo.
     81
     82= 1.6.2 =
     83* Version file mismatch fix.
     84
     85= 1.6.1 =
     86* WordPress 4.2 compatibility update.
     87
     88= 1.6 =
     89* WordPress 4.1.1 compatibility update.
    2390
    2491= 1.5 =
  • redirect-to-login-if-not-logged-in/trunk/readme.txt

    r1137435 r1940138  
    11=== Redirect to login if not logged in ===
     2
     3Plugin Name: Redirect to login if not logged in
     4Plugin URI: http://wordpress.org/plugins/redirect-to-login-if-not-logged-in/
    25Contributors: daankortenbach
    3 Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=BKUCJXJJ8XJVY
    46Tags: redirect, login
    57Requires at least: 3.0.1
    6 Tested up to: 4.2
    7 Stable tag: 1.6.3
     8Tested up to: 5.0
     9Stable tag: 1.7.0
     10Version: 1.7.0
    811License: GPLv2 or later
    912License URI: http://www.gnu.org/licenses/gpl-2.0.html
    1013
    11 Redirects site visitors to the login page if the visitor is not logged in.
     14Redirects users to the login page if the visitor is not logged in.
    1215
    1316== Description ==
    1417
    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.
     18Redirects users to the login page if the user is not logged in. After login the user gets redirected to the original entry page. For advanced users a filter is provided to override the redirect.
     19
     20The principle behind this plugin is to redirect all users - from every post, page, archive, etc. - to the login page (usually wp-login.php). Except for the override filter it does nothing else.
     21
     22= Overriding the redirect =
     23
     24* **Note:** This plugin may not be for you, a membership plugin might be a better fit. Chris Lema writes excellent reviews of +30 membership plugins here: http://chrislema.com/category/memberships-plugins/
     25
     26If you do have a need for this plugin and you want to exclude specific views under specific conditions, a filter is provided to override the redirect.
     27
     28To override the redirect the filter must return a boolean value of `true`. WordPress core provides many conditional tags that either return `true` or `false` or you can write your own conditionals.
     29
     30Take a look at the Conditional Tags page on The WordPress Codex for some inspiration.
     31https://codex.wordpress.org/Conditional_Tags
     32
     33**Usage:**
     34Copy/paste/edit an example to the functions.php of your theme or create a new file in wp-content/mu-plugins/ if you do not wish to edit your theme.
     35
     36_Note: Be carefull not to use multiple filters at the same time as that may cause unexpected results. Instead use multiple conditions in one filter._
     37
     38* Override if the front page is either posts or a page:
     39
     40  ```add_filter( 'rtl_override_redirect', 'is_front_page' );```
     41
     42* Override if the post is 'hello-world':
     43
     44  ```add_filter( 'rtl_override_redirect', function() { 
     45    return is_single( 'hello-world' ); 
     46  });```
     47
     48* Override if the page is 'sample-page':
     49
     50  ```add_filter( 'rtl_override_redirect', function() { 
     51    return is_page( 'sample-page' ); 
     52  });```
     53
     54* Override if the page ID is 42, the slug is 'sample-page' or the title is 'About Me':
     55
     56  ```add_filter( 'rtl_override_redirect', function() { 
     57    return is_page( array( 42, 'sample-page', 'About Me' ) ); 
     58  });```
     59
     60* Override if the page ID is 42 or a post is 'hello-world':
     61
     62  ```add_filter( 'rtl_override_redirect', function() { 
     63    if ( is_page( 42 ) || is_single( 'hello-world' ) ) { 
     64        return true; 
     65    } 
     66  });```
    1667
    1768== Installation ==
     
    2172
    2273== Changelog ==
     74
     75= 1.7.0 =
     76* Add redirect override filter.
     77* Add filter examples.
    2378
    2479= 1.6.3 =
  • redirect-to-login-if-not-logged-in/trunk/redirect-to-login-if-not-logged-in.php

    r1137435 r1940138  
    22/**
    33 * @package Redirect to login if not logged in
    4  * @version 1.6.3
     4 * @version 1.7.0
    55 */
    66/*
    77Plugin Name:   Redirect to login if not logged in
    88Plugin URI:    http://wordpress.org/plugins/redirect-to-login-if-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.
     9Description:   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. Supports a filter to conditionally override pages.
    1010Author:        Daan Kortenbach
    11 Version:       1.6.3
    12 Author URI:    http://daan.kortenba.ch/
     11Version:       1.7.0
     12Author URI:    https://wppro.nl/
    1313License:       GPL-2.0 or later
    1414License URI:   http://www.gnu.org/licenses/gpl-2.0.txt
    1515*/
    1616
    17 add_action( 'parse_request', 'dmk_redirect_to_login_if_not_logged_in', 1 );
     17
     18namespace redirect_to_login_if_not_logged_in;
     19
     20redirect::init();
    1821/**
    19  * Redirects a user to the login page if not logged in.
     22 * Redirects a user to the login page if the user is not logged in.
     23 * After login the user gets redirected to the original entry page.
     24 * Provides a filter 'rtl_override_redirect' to override the redirect.
    2025 *
    21  * @author Daan Kortenbach
     26 * @package Redirect to login if not logged in
     27 * @since 1.7.0
    2228 */
    23 function dmk_redirect_to_login_if_not_logged_in() {
    24     is_user_logged_in() || auth_redirect();
     29class redirect {
     30
     31    /**
     32     * Init - Hook redirect to template_redirect if filter is used, else to parse_request to prevent unnecessary load.
     33     *
     34     * @since 1.7.0
     35     */
     36    public static function init() {
     37
     38        if ( has_filter( 'rtl_override_redirect' ) ){
     39            $hook = 'template_redirect';
     40        }
     41        else {
     42            $hook = 'parse_request';
     43        }
     44        add_action( $hook, array( __CLASS__, 'redirect' ), 1 );
     45    }
     46
     47    /**
     48     * If the rtl_override_redirect filter is not true the user is logged in or authentication redirect is invoked.
     49     *
     50     * @since 1.5
     51     */
     52    public static function redirect() {
     53
     54        /**
     55         * Filter to override the redirect.
     56         *
     57         * @since 1.7.0
     58         *
     59         * @var boolean $override Set to true to override redirect.
     60         */
     61        $override = apply_filters( 'rtl_override_redirect', $override = false );
     62
     63        if ( true !== $override ) {
     64            is_user_logged_in() || auth_redirect();
     65        }
     66    }
    2567}
    26 
    27 
    28 add_filter( 'login_url', 'dmk_strip_loggedout', 1, 1 );
    29 /**
    30  * Strips '?loggedout=true' from redirect url after login.
    31  *
    32  * @author Daan Kortenbach
    33  *
    34  * @param  string $login_url
    35  * @return string $login_url
    36  */
    37 function dmk_strip_loggedout( $login_url ) {
    38     return str_replace( '%3Floggedout%3Dtrue', '', $login_url );
    39 }
Note: See TracChangeset for help on using the changeset viewer.