Changeset 1940138
- Timestamp:
- 09/12/2018 04:51:27 PM (7 years ago)
- Location:
- redirect-to-login-if-not-logged-in
- Files:
-
- 3 edited
-
tags/trunk/readme.txt (modified) (1 diff)
-
trunk/readme.txt (modified) (2 diffs)
-
trunk/redirect-to-login-if-not-logged-in.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
redirect-to-login-if-not-logged-in/tags/trunk/readme.txt
r848912 r1940138 1 1 === Redirect to login if not logged in === 2 3 Plugin Name: Redirect to login if not logged in 4 Plugin URI: http://wordpress.org/plugins/redirect-to-login-if-not-logged-in/ 2 5 Contributors: daankortenbach 3 Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=BKUCJXJJ8XJVY4 6 Tags: redirect, login 5 7 Requires at least: 3.0.1 6 Tested up to: 3.8.1 7 Stable tag: 1.5 8 Tested up to: 5.0 9 Stable tag: 1.7.0 10 Version: 1.7.0 8 11 License: GPLv2 or later 9 12 License URI: http://www.gnu.org/licenses/gpl-2.0.html 10 13 11 Redirects site visitors to the login page if the visitor is not logged in.14 Redirects users to the login page if the visitor is not logged in. 12 15 13 16 == Description == 14 17 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. 18 Redirects 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 20 The 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 26 If 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 28 To 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 30 Take a look at the Conditional Tags page on The WordPress Codex for some inspiration. 31 https://codex.wordpress.org/Conditional_Tags 32 33 **Usage:** 34 Copy/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 });``` 16 67 17 68 == Installation == 18 69 19 1. Upload ` plugin-name.php` to the `/wp-content/plugins/` directory70 1. Upload `redirect-to-login-if-not-logged-in` to the `/wp-content/plugins/` directory 20 71 1. Activate the plugin through the 'Plugins' menu in WordPress 21 72 22 73 == 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. 23 90 24 91 = 1.5 = -
redirect-to-login-if-not-logged-in/trunk/readme.txt
r1137435 r1940138 1 1 === Redirect to login if not logged in === 2 3 Plugin Name: Redirect to login if not logged in 4 Plugin URI: http://wordpress.org/plugins/redirect-to-login-if-not-logged-in/ 2 5 Contributors: daankortenbach 3 Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=BKUCJXJJ8XJVY4 6 Tags: redirect, login 5 7 Requires at least: 3.0.1 6 Tested up to: 4.2 7 Stable tag: 1.6.3 8 Tested up to: 5.0 9 Stable tag: 1.7.0 10 Version: 1.7.0 8 11 License: GPLv2 or later 9 12 License URI: http://www.gnu.org/licenses/gpl-2.0.html 10 13 11 Redirects site visitors to the login page if the visitor is not logged in.14 Redirects users to the login page if the visitor is not logged in. 12 15 13 16 == Description == 14 17 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. 18 Redirects 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 20 The 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 26 If 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 28 To 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 30 Take a look at the Conditional Tags page on The WordPress Codex for some inspiration. 31 https://codex.wordpress.org/Conditional_Tags 32 33 **Usage:** 34 Copy/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 });``` 16 67 17 68 == Installation == … … 21 72 22 73 == Changelog == 74 75 = 1.7.0 = 76 * Add redirect override filter. 77 * Add filter examples. 23 78 24 79 = 1.6.3 = -
redirect-to-login-if-not-logged-in/trunk/redirect-to-login-if-not-logged-in.php
r1137435 r1940138 2 2 /** 3 3 * @package Redirect to login if not logged in 4 * @version 1. 6.34 * @version 1.7.0 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: 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. 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. Supports a filter to conditionally override pages. 10 10 Author: Daan Kortenbach 11 Version: 1. 6.312 Author URI: http ://daan.kortenba.ch/11 Version: 1.7.0 12 Author URI: https://wppro.nl/ 13 13 License: GPL-2.0 or later 14 14 License URI: http://www.gnu.org/licenses/gpl-2.0.txt 15 15 */ 16 16 17 add_action( 'parse_request', 'dmk_redirect_to_login_if_not_logged_in', 1 ); 17 18 namespace redirect_to_login_if_not_logged_in; 19 20 redirect::init(); 18 21 /** 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. 20 25 * 21 * @author Daan Kortenbach 26 * @package Redirect to login if not logged in 27 * @since 1.7.0 22 28 */ 23 function dmk_redirect_to_login_if_not_logged_in() { 24 is_user_logged_in() || auth_redirect(); 29 class 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 } 25 67 } 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 Kortenbach33 *34 * @param string $login_url35 * @return string $login_url36 */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.