Force Login - Version 3.2

Version Description

  • Streamlined - removed v_getUrl function to reduce possible duplicates of global functions - props johappel.
Download this release

Release Info

Developer kevinvess
Plugin Icon 128x128 Force Login
Version 3.2
Comparing to
See all releases

Code changes from version 3.1 to 3.2

Files changed (2) hide show
  1. readme.txt +27 -4
  2. wp-force-login.php +10 -9
readme.txt CHANGED
@@ -3,8 +3,8 @@ Contributors: kevinvess
3
  Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=kevin%40vess%2eme&lc=US&item_name=Kevin%20Vess%20-%20WordPress&currency_code=USD&bn=PP%2dDonationsBF%3abtn_donateCC_LG%2egif%3aNonHosted
4
  Tags: access, closed, force user login, hidden, login, password, privacy, private, protected, registered only, restricted
5
  Requires at least: 2.7
6
- Tested up to: 4.2
7
- Stable tag: 3.1
8
  License: GPLv2 or later
9
 
10
  Force Login is a simple lightweight plugin that requires visitors to log in to interact with the website.
@@ -42,7 +42,7 @@ Upload the Force Login plugin to your site, then Activate it.
42
 
43
  By default, the plugin sends visitors back to the URL they tried to visit. However, you can set a specific URL to always redirect users to by adding the following filter to your functions.php file.
44
 
45
- The URL must be absolute (as in, http://example.com/mypage/). Recommended: site_url( '/mypage/' ).
46
 
47
  `
48
  /**
@@ -58,7 +58,7 @@ add_filter('v_forcelogin_redirect', 'my_forcelogin_redirect', 10, 1);
58
 
59
  = How can I add exceptions for certain pages or posts? =
60
 
61
- You can specify an array of URLs to whitelist by adding the following filter to your functions.php file. Each URL must be absolute (as in, http://example.com/mypage/). Recommended: site_url( '/mypage/' ).
62
 
63
  `
64
  /**
@@ -74,9 +74,29 @@ function my_forcelogin_whitelist( $whitelist ) {
74
  add_filter('v_forcelogin_whitelist', 'my_forcelogin_whitelist', 10, 1);
75
  `
76
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
77
 
78
  == Changelog ==
79
 
 
 
 
80
  = 3.1 =
81
  - Rewrote v_getUrl function to use HTTP_HOST instead of SERVER_NAME - props [Arlen22](https://github.com/Arlen22).
82
 
@@ -102,6 +122,9 @@ add_filter('v_forcelogin_whitelist', 'my_forcelogin_whitelist', 10, 1);
102
 
103
  == Upgrade Notice ==
104
 
 
 
 
105
  = 3.0 =
106
  New features: added developer hooks for customizing the plugin.
107
 
3
  Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=kevin%40vess%2eme&lc=US&item_name=Kevin%20Vess%20-%20WordPress&currency_code=USD&bn=PP%2dDonationsBF%3abtn_donateCC_LG%2egif%3aNonHosted
4
  Tags: access, closed, force user login, hidden, login, password, privacy, private, protected, registered only, restricted
5
  Requires at least: 2.7
6
+ Tested up to: 4.3
7
+ Stable tag: 3.2
8
  License: GPLv2 or later
9
 
10
  Force Login is a simple lightweight plugin that requires visitors to log in to interact with the website.
42
 
43
  By default, the plugin sends visitors back to the URL they tried to visit. However, you can set a specific URL to always redirect users to by adding the following filter to your functions.php file.
44
 
45
+ The URL must be absolute (as in, http://example.com/mypage/). Recommended: [site_url( '/mypage/' )](https://codex.wordpress.org/Function_Reference/site_url).
46
 
47
  `
48
  /**
58
 
59
  = How can I add exceptions for certain pages or posts? =
60
 
61
+ You can specify an array of URLs to whitelist by adding the following filter to your functions.php file. Each URL must be absolute (as in, http://example.com/mypage/). Recommended: [site_url( '/mypage/' )](https://codex.wordpress.org/Function_Reference/site_url).
62
 
63
  `
64
  /**
74
  add_filter('v_forcelogin_whitelist', 'my_forcelogin_whitelist', 10, 1);
75
  `
76
 
77
+ = How do I get the WordPress mobile app to work? =
78
+
79
+ By default, the plugin blocks access to all page URLs; you will need to whitelist the XML-RPC page to allow the WordPress app to access your site for remote publishing.
80
+
81
+ `
82
+ /**
83
+ * Filter Force Login to allow exceptions for specific URLs.
84
+ *
85
+ * @return array An array of URLs. Must be absolute.
86
+ **/
87
+ function my_forcelogin_whitelist( $whitelist ) {
88
+ $whitelist[] = site_url( '/xmlrpc.php' );
89
+ return $whitelist;
90
+ }
91
+ add_filter('v_forcelogin_whitelist', 'my_forcelogin_whitelist', 10, 1);
92
+ `
93
+
94
 
95
  == Changelog ==
96
 
97
+ = 3.2 =
98
+ - Streamlined - removed v_getUrl function to reduce possible duplicates of global functions - props [johappel](https://github.com/johappel).
99
+
100
  = 3.1 =
101
  - Rewrote v_getUrl function to use HTTP_HOST instead of SERVER_NAME - props [Arlen22](https://github.com/Arlen22).
102
 
122
 
123
  == Upgrade Notice ==
124
 
125
+ = 3.2 =
126
+ Removed function v_getUrl.
127
+
128
  = 3.0 =
129
  New features: added developer hooks for customizing the plugin.
130
 
wp-force-login.php CHANGED
@@ -3,7 +3,7 @@
3
  Plugin Name: Force Login
4
  Plugin URI: http://vess.me/
5
  Description: Easily hide your WordPress site from public viewing by requiring visitors to log in first. Activate to turn on.
6
- Version: 3.1
7
  Author: Kevin Vess
8
  Author URI: http://vess.me/
9
  License: GPLv2 or later
@@ -25,18 +25,19 @@ along with this program; if not, write to the Free Software
25
  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
26
  */
27
 
28
- function v_getUrl() {
29
- $url = isset( $_SERVER['HTTPS'] ) && 'on' === $_SERVER['HTTPS'] ? 'https' : 'http';
30
- $url .= '://' . $_SERVER['HTTP_HOST'];
31
- $url .= in_array( $_SERVER['SERVER_PORT'], array('80', '443') ) ? '' : ':' . $_SERVER['SERVER_PORT'];
32
- $url .= $_SERVER['REQUEST_URI'];
33
- return $url;
34
- }
35
  function v_forcelogin() {
36
  if( !is_user_logged_in() ) {
37
- $url = v_getUrl();
 
 
 
 
 
 
38
  $whitelist = apply_filters('v_forcelogin_whitelist', array());
39
  $redirect_url = apply_filters('v_forcelogin_redirect', $url);
 
 
40
  if( preg_replace('/\?.*/', '', $url) != preg_replace('/\?.*/', '', wp_login_url()) && !in_array($url, $whitelist) ) {
41
  wp_safe_redirect( wp_login_url( $redirect_url ), 302 ); exit();
42
  }
3
  Plugin Name: Force Login
4
  Plugin URI: http://vess.me/
5
  Description: Easily hide your WordPress site from public viewing by requiring visitors to log in first. Activate to turn on.
6
+ Version: 3.2
7
  Author: Kevin Vess
8
  Author URI: http://vess.me/
9
  License: GPLv2 or later
25
  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
26
  */
27
 
 
 
 
 
 
 
 
28
  function v_forcelogin() {
29
  if( !is_user_logged_in() ) {
30
+ // Get URL
31
+ $url = isset( $_SERVER['HTTPS'] ) && 'on' === $_SERVER['HTTPS'] ? 'https' : 'http';
32
+ $url .= '://' . $_SERVER['HTTP_HOST'];
33
+ $url .= in_array( $_SERVER['SERVER_PORT'], array('80', '443') ) ? '' : ':' . $_SERVER['SERVER_PORT'];
34
+ $url .= $_SERVER['REQUEST_URI'];
35
+
36
+ // Apply filters
37
  $whitelist = apply_filters('v_forcelogin_whitelist', array());
38
  $redirect_url = apply_filters('v_forcelogin_redirect', $url);
39
+
40
+ // Redirect visitors
41
  if( preg_replace('/\?.*/', '', $url) != preg_replace('/\?.*/', '', wp_login_url()) && !in_array($url, $whitelist) ) {
42
  wp_safe_redirect( wp_login_url( $redirect_url ), 302 ); exit();
43
  }