Version Description
- New restriction option - show restricted visitor a specified page; use with custom page templates for great for website teasers!
- Major improvements to settings user interface, including hiding unused fields based on settings, easier selection of restriction type, and cleaner "remove" confirmation for IP address list
- Performance improvements - catches and blocks restricted visitors earlier in the loading process
- New filter hooks for other developers: 'restricted_site_access_is_restricted', 'restricted_site_access_approach', 'restricted_site_access_redirect_url', and 'restricted_site_access_head'
- Localization ready - rough Spanish translation included!
- Basic support for no JavaScript mode
- Optimized for PHP 5.2, per new WordPress 3.2 requirements (no longer supports PHP < 5.2.4)
- Assorted other improvements and optimizations to the code base
Download this release
Release Info
Developer | jakemgold |
Plugin | Restricted Site Access |
Version | 4.0 |
Comparing to | |
See all releases |
Code changes from version 3.2.1 to 4.0
- localization/restricted-site-access-es_ES.mo +0 -0
- localization/restricted-site-access-es_ES.po +198 -0
- readme.txt +54 -25
- restricted-site-access.js +39 -3
- restricted_site_access.php +162 -198
- screenshot-1.png +0 -0
- screenshot-2.png +0 -0
- screenshot-3.png +0 -0
- screenshot-4.png +0 -0
localization/restricted-site-access-es_ES.mo
ADDED
Binary file
|
localization/restricted-site-access-es_ES.po
ADDED
@@ -0,0 +1,198 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Copyright (C) 2011 10up
|
2 |
+
# This file is distributed under the same license as the Restricted Site Access package.
|
3 |
+
msgid ""
|
4 |
+
msgstr ""
|
5 |
+
"Project-Id-Version: Restricted Site Access\n"
|
6 |
+
"Report-Msgid-Bugs-To: \n"
|
7 |
+
"POT-Creation-Date: 2011-07-16 15:57-0500\n"
|
8 |
+
"PO-Revision-Date: 2011-07-16 16:00-0500\n"
|
9 |
+
"Last-Translator: Jake Goldman <jake@get10up.com>\n"
|
10 |
+
"Language-Team: 10up <jake@get10up.com>\n"
|
11 |
+
"MIME-Version: 1.0\n"
|
12 |
+
"Content-Type: text/plain; charset=UTF-8\n"
|
13 |
+
"Content-Transfer-Encoding: 8bit\n"
|
14 |
+
|
15 |
+
#: restricted_site_access.php:102
|
16 |
+
#: restricted_site_access.php:266
|
17 |
+
msgid "Access to this site is restricted."
|
18 |
+
msgstr "El acceso a este sitio está restringido."
|
19 |
+
|
20 |
+
#: restricted_site_access.php:142
|
21 |
+
#: restricted_site_access.php:316
|
22 |
+
msgid "Handle restricted visitors"
|
23 |
+
msgstr "Manejar visitantes restringido"
|
24 |
+
|
25 |
+
#: restricted_site_access.php:143
|
26 |
+
msgid "Restriction message"
|
27 |
+
msgstr "Restricción mensaje"
|
28 |
+
|
29 |
+
#: restricted_site_access.php:144
|
30 |
+
#: restricted_site_access.php:321
|
31 |
+
msgid "Redirect web address"
|
32 |
+
msgstr "Reorientar dirección web"
|
33 |
+
|
34 |
+
#: restricted_site_access.php:145
|
35 |
+
#: restricted_site_access.php:322
|
36 |
+
msgid "Redirect to same path"
|
37 |
+
msgstr "Redirigir a mismo camino"
|
38 |
+
|
39 |
+
#: restricted_site_access.php:146
|
40 |
+
#: restricted_site_access.php:323
|
41 |
+
msgid "Redirection status code"
|
42 |
+
msgstr "Redirección código de estatus"
|
43 |
+
|
44 |
+
#: restricted_site_access.php:147
|
45 |
+
msgid "Restricted notice page"
|
46 |
+
msgstr "Página nota restringido"
|
47 |
+
|
48 |
+
#: restricted_site_access.php:148
|
49 |
+
msgid "Unrestricted IP addresses"
|
50 |
+
msgstr "Direcciones IP sin restricciones"
|
51 |
+
|
52 |
+
#: restricted_site_access.php:155
|
53 |
+
msgid "Public access to this site has been restricted."
|
54 |
+
msgstr "Acceso público a este sitio ha sido restringido."
|
55 |
+
|
56 |
+
#: restricted_site_access.php:162
|
57 |
+
msgid "Restricted Site Access plug-in is blocking public access to this site."
|
58 |
+
msgstr "Restricted Site Access plug-in está bloqueando acceso público a este sitio."
|
59 |
+
|
60 |
+
#: restricted_site_access.php:173
|
61 |
+
msgid "Click \"Save Changes\" to save this IP address."
|
62 |
+
msgstr "Clic en \"Guardar cambios\" para guardar esta dirección IP."
|
63 |
+
|
64 |
+
#: restricted_site_access.php:174
|
65 |
+
#: restricted_site_access.php:249
|
66 |
+
msgid "remove"
|
67 |
+
msgstr "eliminar"
|
68 |
+
|
69 |
+
#: restricted_site_access.php:175
|
70 |
+
msgid "confirm removal"
|
71 |
+
msgstr "confirmar eliminación"
|
72 |
+
|
73 |
+
#: restricted_site_access.php:176
|
74 |
+
msgid "cancel"
|
75 |
+
msgstr "cancelar"
|
76 |
+
|
77 |
+
#: restricted_site_access.php:186
|
78 |
+
msgid "Please select the page you want to show restricted visitors. If no page is selected, WordPress will simply show a general restriction message."
|
79 |
+
msgstr "Por favor, seleccione la página que desea mostrar a los visitantes restringido. Si no se selecciona la página, WordPress, simplemente se mostrará un mensaje de restricción general."
|
80 |
+
|
81 |
+
#: restricted_site_access.php:188
|
82 |
+
msgid "Please enter the web address you would like to redirect restriced visitors to. If no address is entered, visitors will be redirected to the login screen."
|
83 |
+
msgstr "Por favor, introduzca la dirección Web que desee redirigir a los visitantes a restriced. Si no se introduce la dirección, los visitantes va a ser redirigido a la pantalla de inicio de sesión."
|
84 |
+
|
85 |
+
#: restricted_site_access.php:198
|
86 |
+
msgid "Restrict site access to visitors who are logged in or allowed by IP address"
|
87 |
+
msgstr "Restringir acceso al sitio a los visitantes que están registrado o autorizados por dirección IP"
|
88 |
+
|
89 |
+
#: restricted_site_access.php:224
|
90 |
+
msgid "Send them to the WordPress login screen"
|
91 |
+
msgstr "Enviar a la pantalla de login de WordPress"
|
92 |
+
|
93 |
+
#: restricted_site_access.php:227
|
94 |
+
msgid "Redirect them to a specified web address"
|
95 |
+
msgstr "Redirigir a una dirección web especificada"
|
96 |
+
|
97 |
+
#: restricted_site_access.php:230
|
98 |
+
msgid "Show them a simple message"
|
99 |
+
msgstr "Mostrarles un mensaje simple"
|
100 |
+
|
101 |
+
#: restricted_site_access.php:233
|
102 |
+
msgid "Show them a specific WordPress page I've created"
|
103 |
+
msgstr "Muéstrales una determinada página de WordPress que he creado"
|
104 |
+
|
105 |
+
#: restricted_site_access.php:253
|
106 |
+
msgid "add"
|
107 |
+
msgstr "añadir"
|
108 |
+
|
109 |
+
#: restricted_site_access.php:254
|
110 |
+
msgid "Enter a single IP address or a range using a subnet prefix"
|
111 |
+
msgstr "Especificar una única dirección IP o un rango con un prefijo de subred"
|
112 |
+
|
113 |
+
#: restricted_site_access.php:254
|
114 |
+
#: restricted_site_access.php:281
|
115 |
+
#: restricted_site_access.php:294
|
116 |
+
msgid "help"
|
117 |
+
msgstr "ayuda"
|
118 |
+
|
119 |
+
#: restricted_site_access.php:257
|
120 |
+
msgid "add my current IP address"
|
121 |
+
msgstr "añadir mi dirección IP actual"
|
122 |
+
|
123 |
+
#: restricted_site_access.php:260
|
124 |
+
msgid "To manage IP addresses, you must use a JavaScript enabled browser."
|
125 |
+
msgstr "Para administrar las direcciones IP, debe utilizar un buscador compatible con JavaScript."
|
126 |
+
|
127 |
+
#: restricted_site_access.php:281
|
128 |
+
msgid "Send restricted visitor to same path (relative URL) at the new web address"
|
129 |
+
msgstr "Enviar visitante restringido a mismo camino (URL relativa) en la nueva dirección web"
|
130 |
+
|
131 |
+
#: restricted_site_access.php:290
|
132 |
+
msgid "301 Permanent"
|
133 |
+
msgstr "301 Permanente"
|
134 |
+
|
135 |
+
#: restricted_site_access.php:291
|
136 |
+
msgid "302 Undefined"
|
137 |
+
msgstr "302 Indefinido"
|
138 |
+
|
139 |
+
#: restricted_site_access.php:292
|
140 |
+
msgid "307 Temporary"
|
141 |
+
msgstr "307 Temporario"
|
142 |
+
|
143 |
+
#: restricted_site_access.php:294
|
144 |
+
msgid "HTTP status code sent to browser"
|
145 |
+
msgstr "Código de estado HTTP envía al navegador"
|
146 |
+
|
147 |
+
#: restricted_site_access.php:314
|
148 |
+
msgid "is a plug-in by"
|
149 |
+
msgstr "es un plug-in de"
|
150 |
+
|
151 |
+
#: restricted_site_access.php:314
|
152 |
+
msgid "that allows you to restrict access to logged in users and a set of IP addresses."
|
153 |
+
msgstr "que le permite restringir el acceso a usuarios registrados y un conjunto de direcciones IP."
|
154 |
+
|
155 |
+
#: restricted_site_access.php:316
|
156 |
+
msgid "choose the method for handling visitors to your site that are restricted."
|
157 |
+
msgstr "elegir el método para el manejo de los visitantes de su sitio web que se encuentran restringidas."
|
158 |
+
|
159 |
+
#: restricted_site_access.php:317
|
160 |
+
msgid "Allowed IP addresses"
|
161 |
+
msgstr "Direcciones IP permitidas"
|
162 |
+
|
163 |
+
#: restricted_site_access.php:317
|
164 |
+
msgid "enter a single IP address (for example, 192.168.1.105) or an IP range using a network prefix (for example, 10.0.0.1/24). Enter your addresses carefully! Here's a"
|
165 |
+
msgstr "especificar una única dirección IP (por ejemplo, 192.168.1.105) o un rango de IP con un prefijo de red (por ejemplo, 10.0.0.1/24). Ingrese su dirección con cuidado! Aquí hay una"
|
166 |
+
|
167 |
+
#: restricted_site_access.php:317
|
168 |
+
msgid "handy calculator"
|
169 |
+
msgstr "práctica calculadora"
|
170 |
+
|
171 |
+
#: restricted_site_access.php:317
|
172 |
+
msgid "to check your prefix."
|
173 |
+
msgstr "para comprobar su prefijo."
|
174 |
+
|
175 |
+
#: restricted_site_access.php:319
|
176 |
+
msgid "Redirection Options"
|
177 |
+
msgstr "Opciones de Redirección"
|
178 |
+
|
179 |
+
#: restricted_site_access.php:320
|
180 |
+
msgid "The redirection fields are only used when \"Handle restricted visitors\" is set to \"Redirect them to a specified web address\"."
|
181 |
+
msgstr "Los campos de redirección se utiliza sólo cuando \"Manejar visitantes restringido\" se pone en \"Redirigir a una dirección web especificada\"."
|
182 |
+
|
183 |
+
#: restricted_site_access.php:321
|
184 |
+
msgid "the web address of the site you want the visitor redirected to."
|
185 |
+
msgstr "la dirección Web del sitio que desea que el visitante la redirección."
|
186 |
+
|
187 |
+
#: restricted_site_access.php:322
|
188 |
+
msgid "redirect the visitor to the same path (URI) entered at this site. Typically used when there are two, very similar sites at different public web addresses; for instance, a parallel development server accessible on the Internet but not intended for the public."
|
189 |
+
msgstr "redirigir al visitante en el mismo camino (URI), entró en este sitio. Normalmente se usa cuando hay dos, los sitios muy similar en las diferentes direcciones de Internet públicas, por ejemplo, un servidor de desarrollo paralelo accesible en Internet, pero no destinados al público."
|
190 |
+
|
191 |
+
#: restricted_site_access.php:323
|
192 |
+
msgid "redirect status codes can provide certain visitors, particularly search engines, more information about the nature of the redirect. A 301 redirect tells search engines that a page has moved permanently to the new location. 307 indicates a temporary redirect. 302 is an undefined redirect."
|
193 |
+
msgstr "redirigir los códigos de estado puede ofrecer a los visitantes algunos, en particular los motores de búsqueda, más información sobre la naturaleza de la redirección. Una redirección 301 le dice a los motores de búsqueda que una página se ha movido permanentemente a la nueva ubicación. 307 indica una redirección temporal. 302 es una redirección indefinido."
|
194 |
+
|
195 |
+
#: restricted_site_access.php:331
|
196 |
+
msgid "Settings"
|
197 |
+
msgstr "Configuración"
|
198 |
+
|
readme.txt
CHANGED
@@ -1,48 +1,76 @@
|
|
1 |
=== Restricted Site Access ===
|
2 |
-
Contributors: jakemgold, rcbth
|
3 |
Donate link: http://www.get10up.com/plugins/restricted-site-access-wordpress/
|
4 |
Tags: privacy, restricted, restrict, limited, permissions, security, block
|
5 |
-
Requires at least: 2
|
6 |
-
Tested up to: 3.1
|
7 |
-
Stable tag:
|
8 |
-
|
9 |
-
Limit access to visitors who are logged in or at specific IP addresses. Many options for handling blocked visitors.
|
10 |
-
Great for Intranets, dev sites.
|
11 |
|
|
|
12 |
|
13 |
== Description ==
|
14 |
|
15 |
-
Limit access your site to visitors who are logged in or accessing the site from a set of specific IP addresses.
|
16 |
-
Send restricted visitors to the log in page, redirect them, or display a message. A great solution for
|
17 |
-
Extranets, publicly hosted Intranets, or parallel development sites.
|
18 |
|
19 |
Adds a number of new configuration options to the Privacy settings panel. From this panel you can:
|
20 |
|
21 |
1. Enable or disable site access restriction
|
22 |
-
1. Change the restriction behavior: send to login, redirect,
|
23 |
-
1. Add IP addresses
|
24 |
-
1. Quickly add your current IP to the
|
25 |
-
1.
|
26 |
-
1.
|
27 |
-
1. Choose the HTTP redirect message for SEO friendliness
|
28 |
-
1. Customize the blocked visitor message
|
29 |
-
|
30 |
|
31 |
== Installation ==
|
32 |
|
33 |
-
1. Install easily with the WordPress plugin control panel or manually download the plugin and upload the extracted
|
34 |
-
folder to the `/wp-content/plugins/` directory
|
35 |
1. Activate the plugin through the 'Plugins' menu in WordPress
|
36 |
1. Configure the plugin by going to the "Privacy" menu under "Settings"
|
37 |
|
|
|
38 |
|
39 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
40 |
|
41 |
-
|
|
|
42 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
43 |
|
44 |
== Changelog ==
|
45 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
46 |
= 3.2.1 =
|
47 |
* Restored PHP4 compatibility
|
48 |
|
@@ -84,6 +112,7 @@ folder to the `/wp-content/plugins/` directory
|
|
84 |
= 1.0.1 =
|
85 |
* Important fundamental change related to handling of what should be restricted
|
86 |
|
87 |
-
|
88 |
-
|
89 |
-
|
|
1 |
=== Restricted Site Access ===
|
2 |
+
Contributors: jakemgold, rcbth
|
3 |
Donate link: http://www.get10up.com/plugins/restricted-site-access-wordpress/
|
4 |
Tags: privacy, restricted, restrict, limited, permissions, security, block
|
5 |
+
Requires at least: 3.2
|
6 |
+
Tested up to: 3.2.1
|
7 |
+
Stable tag: 4.0
|
|
|
|
|
|
|
8 |
|
9 |
+
Limit access to visitors who are logged in or at specific IP addresses. Many options for handling blocked visitors. Great for Intranets, dev sites.
|
10 |
|
11 |
== Description ==
|
12 |
|
13 |
+
Limit access your site to visitors who are logged in or accessing the site from a set of specific IP addresses. Send restricted visitors to the log in page, redirect them, or display a message or page. A great solution for Extranets, publicly hosted Intranets, or parallel development / staging sites.
|
|
|
|
|
14 |
|
15 |
Adds a number of new configuration options to the Privacy settings panel. From this panel you can:
|
16 |
|
17 |
1. Enable or disable site access restriction
|
18 |
+
1. Change the restriction behavior: send to login, redirect, display a message, display a page
|
19 |
+
1. Add IP addresses to an unrestricted list, including ranges
|
20 |
+
1. Quickly add your current IP to the unrestricted list
|
21 |
+
1. Customize the redirect location, including an option to send them to the same requested path and set the HTTP status code for SEO friendliness
|
22 |
+
1. Define a simple message to show restricted visitors, or select a page to show them - great for "coming soon" teasers!
|
|
|
|
|
|
|
23 |
|
24 |
== Installation ==
|
25 |
|
26 |
+
1. Install easily with the WordPress plugin control panel or manually download the plugin and upload the extracted folder to the `/wp-content/plugins/` directory
|
|
|
27 |
1. Activate the plugin through the 'Plugins' menu in WordPress
|
28 |
1. Configure the plugin by going to the "Privacy" menu under "Settings"
|
29 |
|
30 |
+
== Frequently Asked Questions ==
|
31 |
|
32 |
+
= How do I unrestrict specific pages or parts of my site? =
|
33 |
+
|
34 |
+
Developers can use the `restricted_site_access_is_restricted` filter to override Restricted Site Access. Note that the restriction checks runs before WordPress executes any queries, so use the global `$wp` variable to investigate what the visitor is trying to load.
|
35 |
+
|
36 |
+
For instance, to unblock an RSS feed, place the following PHP code in the theme's functions.php file or in a simple plug-in:
|
37 |
+
|
38 |
+
`add_filter( 'restricted_site_access_is_restricted', 'my_rsa_feed_override' );
|
39 |
+
|
40 |
+
function my_rsa_feed_override( $is_restricted ) {
|
41 |
+
global $wp;
|
42 |
+
// check query variables to see if this is the feed
|
43 |
+
if ( ! empty( $wp->query_vars['feed'] ) )
|
44 |
+
$is_restricted = false;
|
45 |
|
46 |
+
return $is_restricted;
|
47 |
+
}`
|
48 |
|
49 |
+
= How secure is this plug-in? =
|
50 |
+
|
51 |
+
Users that are not logged in or allowed by IP address will not be able to browse your site. Restricted Site Access does not block access to your "real" files, so direct links to files in your uploads folder (for instance) are not blocked. It is also important to remember that IP addresses can be spoofed by hackers. Because Restricted Site Access runs as a plug-in, it is subject to general WordPress vulnerabilities.
|
52 |
+
|
53 |
+
Restricted Site Access is not meant to be a top secret data safe, but simply a reliable and convenient way to handle unwanted visitors.
|
54 |
+
|
55 |
+
== Screenshots ==
|
56 |
+
|
57 |
+
1. Screenshot of settings panel with simple Restricted Site Access option (send to login page).
|
58 |
+
1. Screenshot of settings panel with redirection method enabled, and confirming removal of an IP address from the exception list
|
59 |
+
1. Plenty of inline help! Looks and behaves like native WordPress functionality.
|
60 |
+
1. Restricted access mode turned off in the privacy settings panel
|
61 |
|
62 |
== Changelog ==
|
63 |
|
64 |
+
= 4.0 =
|
65 |
+
* New restriction option - show restricted visitor a specified page; use with custom page templates for great for website teasers!
|
66 |
+
* Major improvements to settings user interface, including hiding unused fields based on settings, easier selection of restriction type, and cleaner "remove" confirmation for IP address list
|
67 |
+
* Performance improvements - catches and blocks restricted visitors earlier in the loading process
|
68 |
+
* New filter hooks for other developers: 'restricted_site_access_is_restricted', 'restricted_site_access_approach', 'restricted_site_access_redirect_url', and 'restricted_site_access_head'
|
69 |
+
* Localization ready - rough Spanish translation included!
|
70 |
+
* Basic support for no JavaScript mode
|
71 |
+
* Optimized for PHP 5.2, per new WordPress 3.2 requirements (no longer supports PHP < 5.2.4)
|
72 |
+
* Assorted other improvements and optimizations to the code base
|
73 |
+
|
74 |
= 3.2.1 =
|
75 |
* Restored PHP4 compatibility
|
76 |
|
112 |
= 1.0.1 =
|
113 |
* Important fundamental change related to handling of what should be restricted
|
114 |
|
115 |
+
== Upgrade Notice ==
|
116 |
+
|
117 |
+
= 4.0 =
|
118 |
+
This update improves performance, refines the user interface, and adds support for showing restricted visitors a specific page. Please be advised that this udpate is specifically designed for WordPress 3.2+, and like WordPress 3.2, <strong>no longer supports PHP < 5.2.4</strong>.
|
restricted-site-access.js
CHANGED
@@ -1,3 +1,5 @@
|
|
|
|
|
|
1 |
function add_ip(ip) {
|
2 |
if (!jQuery.trim(ip)) return false;
|
3 |
|
@@ -13,9 +15,43 @@ function add_ip(ip) {
|
|
13 |
});
|
14 |
if (ip_used) return false;
|
15 |
|
16 |
-
jQuery('<span style="display: none;"><input type="text" name="rsa_options[allowed][]" value="'+ip+'" readonly="true" /><input type="button" class="button" onclick="remove_ip(this);" value="
|
|
|
|
|
|
|
|
|
|
|
17 |
}
|
18 |
|
19 |
function remove_ip(btnObj) {
|
20 |
-
|
21 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
// functions for dynamic IP address boxes
|
2 |
+
|
3 |
function add_ip(ip) {
|
4 |
if (!jQuery.trim(ip)) return false;
|
5 |
|
15 |
});
|
16 |
if (ip_used) return false;
|
17 |
|
18 |
+
jQuery('<span style="display: none;"><input type="text" name="rsa_options[allowed][]" value="'+ip+'" readonly="true" /><input type="button" class="button" onclick="remove_ip(this);" value="' + restricted_site_access_l10n.Remove + '" /> <span class="description">' + restricted_site_access_l10n.SaveChanges + '</span><br /></span>').appendTo('#ip_list').slideDown();
|
19 |
+
}
|
20 |
+
|
21 |
+
function cancel_remove_ip(btnObj) {
|
22 |
+
jQuery(btnObj).siblings('.button-primary').removeClass('button-primary').val(restricted_site_access_l10n.Remove);
|
23 |
+
jQuery(btnObj).remove();
|
24 |
}
|
25 |
|
26 |
function remove_ip(btnObj) {
|
27 |
+
var jbtnObj = jQuery(btnObj);
|
28 |
+
if ( jbtnObj.hasClass('button-primary') ) jbtnObj.parent().slideUp(250,function(){ jQuery(this).remove() });
|
29 |
+
else jbtnObj.val(restricted_site_access_l10n.ConfirmRemove).addClass('button-primary').after('<input type="button" value="' + restricted_site_access_l10n.Cancel + '" class="button" onclick="cancel_remove_ip(this);" />');
|
30 |
+
}
|
31 |
+
|
32 |
+
// hide and show relevant pieces
|
33 |
+
var rsa_table = jQuery('#rsa-send-to-login').closest('table');
|
34 |
+
var rsa_redirect_fields = jQuery('.rsa_redirect_field').closest('tr');
|
35 |
+
var rsa_messsage_field = jQuery('#rsa_message').closest('tr');
|
36 |
+
var rsa_page_field = jQuery('#rsa_page').closest('tr');
|
37 |
+
|
38 |
+
if ( jQuery('#blog-restricted:checked').length <= 0 ) rsa_table.hide();
|
39 |
+
if ( jQuery('#rsa-redirect-visitor:checked').length <= 0 ) rsa_redirect_fields.hide();
|
40 |
+
if ( jQuery('#rsa-display-message:checked').length <= 0 ) rsa_messsage_field.hide();
|
41 |
+
if ( jQuery('#rsa-unblocked-page:checked').length <= 0 ) rsa_page_field.hide();
|
42 |
+
|
43 |
+
jQuery('input[name="rsa_options[approach]"]').change(function(){
|
44 |
+
if( jQuery('#rsa-redirect-visitor').is(':checked') ) rsa_redirect_fields.show();
|
45 |
+
else rsa_redirect_fields.hide();
|
46 |
+
|
47 |
+
if( jQuery('#rsa-display-message').is(':checked') ) rsa_messsage_field.show();
|
48 |
+
else rsa_messsage_field.hide();
|
49 |
+
|
50 |
+
if( jQuery('#rsa-unblocked-page').is(':checked') ) rsa_page_field.show();
|
51 |
+
else rsa_page_field.hide();
|
52 |
+
});
|
53 |
+
|
54 |
+
jQuery('input[name="blog_public"]').change(function(){
|
55 |
+
if( jQuery('#blog-restricted').is(':checked') ) rsa_table.show();
|
56 |
+
else rsa_table.hide();
|
57 |
+
});
|
restricted_site_access.php
CHANGED
@@ -2,8 +2,8 @@
|
|
2 |
/**
|
3 |
Plugin Name: Restricted Site Access
|
4 |
Plugin URI: http://www.get10up.com/plugins/restricted-site-access-wordpress/
|
5 |
-
Description: <strong>Limit access your site</strong> to visitors who are logged in or accessing the site from a set of specific IP addresses. Send restricted visitors to the log in page, redirect them, or display a message. <strong>Powerful control over redirection</strong>,
|
6 |
-
Version:
|
7 |
Author: Jake Goldman (10up)
|
8 |
Author URI: http://www.get10up.com
|
9 |
|
@@ -24,69 +24,44 @@
|
|
24 |
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
25 |
*/
|
26 |
|
27 |
-
|
28 |
-
* adds inet_pton support for ranges for servers that don't support (PHP pre 5.1, Windows PHP)
|
29 |
-
*/
|
30 |
-
|
31 |
-
if ( !function_exists('inet_pton') ) :
|
32 |
-
|
33 |
-
function inet_pton($ip)
|
34 |
-
{
|
35 |
-
# ipv4
|
36 |
-
if (strpos($ip, '.') !== FALSE) {
|
37 |
-
$ip = pack('N',ip2long($ip));
|
38 |
-
}
|
39 |
-
# ipv6
|
40 |
-
elseif (strpos($ip, ':') !== FALSE) {
|
41 |
-
$ip = explode(':', $ip);
|
42 |
-
$res = str_pad('', (4*(8-count($ip))), '0000', STR_PAD_LEFT);
|
43 |
-
foreach ($ip as $seg) {
|
44 |
-
$res .= str_pad($seg, 4, '0', STR_PAD_LEFT);
|
45 |
-
}
|
46 |
-
$ip = pack('H'.strlen($res), $res);
|
47 |
-
}
|
48 |
-
return $ip;
|
49 |
-
}
|
50 |
-
|
51 |
-
endif;
|
52 |
-
|
53 |
-
/**
|
54 |
-
* class to compartmentalize functionality
|
55 |
-
*/
|
56 |
-
|
57 |
-
class restricted_site_access
|
58 |
-
{
|
59 |
-
var $rsa_options;
|
60 |
|
61 |
-
|
62 |
-
|
|
|
63 |
$this->rsa_options = get_option('rsa_options');
|
64 |
|
65 |
-
add_action( '
|
66 |
add_action( 'admin_init', array( $this, 'admin_init' ) );
|
|
|
67 |
|
68 |
register_activation_hook( __FILE__, array( $this, 'activation' ) );
|
69 |
-
register_deactivation_hook( __FILE__, array( $this, 'deactivation' ) );
|
70 |
}
|
71 |
|
72 |
-
function
|
73 |
-
|
74 |
-
|
75 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
76 |
return;
|
77 |
|
78 |
$rsa_options = $this->rsa_options;
|
79 |
|
80 |
// check for the allow list, if its empty block everything
|
81 |
-
if( isset($rsa_options['allowed']) && ( $list = $rsa_options['allowed'] ) )
|
82 |
-
|
83 |
$remote_ip = $_SERVER['REMOTE_ADDR']; //save the remote ip
|
84 |
if( strpos($remote_ip, '.') ) $remote_ip = str_replace('::ffff:', '', $remote_ip); //handle dual-stack addresses
|
85 |
$remote_ip = inet_pton($remote_ip); //parse the remote ip
|
86 |
|
87 |
// iterate through the allow list
|
88 |
-
foreach($list as $line)
|
89 |
-
{
|
90 |
list($ip, $mask) = explode('/', $line . '/128'); // get the ip and mask from the list
|
91 |
|
92 |
$mask = str_repeat('f', $mask >> 2); //render the mask as bits, similar to info on the php.net man page discussion for inet_pton
|
@@ -111,39 +86,46 @@ class restricted_site_access
|
|
111 |
}
|
112 |
}
|
113 |
|
114 |
-
$rsa_restrict_approach = $rsa_options['approach'];
|
115 |
|
116 |
do_action( 'restrict_site_access_handling', $rsa_restrict_approach ); // allow users to hook handling
|
117 |
|
118 |
-
switch( $rsa_restrict_approach )
|
119 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
120 |
case 3:
|
121 |
-
|
122 |
-
|
|
|
123 |
|
124 |
-
wp_die( $
|
125 |
|
126 |
case 2:
|
127 |
-
if (
|
128 |
-
|
129 |
-
|
130 |
-
$rsa_redirect_url .= $_SERVER["REQUEST_URI"]; // path
|
131 |
|
132 |
-
$
|
|
|
|
|
|
|
133 |
}
|
134 |
-
break;
|
135 |
|
136 |
default:
|
137 |
$rsa_redirect_head = 302;
|
138 |
-
$rsa_redirect_url = wp_login_url( empty($_SERVER["REQUEST_URI"]) ?
|
139 |
}
|
140 |
|
141 |
-
wp_redirect( $rsa_redirect_url, $rsa_redirect_head );
|
142 |
exit;
|
143 |
}
|
144 |
|
145 |
-
function admin_init()
|
146 |
-
{
|
147 |
// customize privacy message
|
148 |
add_filter( 'privacy_on_link_text', array( $this, 'privacy_on_link_text' ) );
|
149 |
add_filter( 'privacy_on_link_title', array( $this, 'privacy_on_link_title' ) );
|
@@ -156,230 +138,213 @@ class restricted_site_access
|
|
156 |
|
157 |
// settings for restricted site access
|
158 |
register_setting( 'privacy', 'rsa_options', array( $this, 'sanitize_options' ) ); //array of fundamental options including ID and caching info
|
159 |
-
add_settings_section( 'restricted-site-access',
|
160 |
-
add_settings_field( 'approach', __('
|
161 |
-
add_settings_field( '
|
162 |
-
add_settings_field( '
|
163 |
-
add_settings_field( '
|
164 |
-
add_settings_field( '
|
165 |
-
add_settings_field( '
|
|
|
166 |
|
167 |
add_filter( 'plugin_action_links_' . plugin_basename(__FILE__), array( $this, 'plugin_action_links' ) );
|
168 |
}
|
169 |
|
170 |
-
function
|
171 |
-
|
172 |
-
function privacy_on_link_text( $text )
|
173 |
-
{
|
174 |
if ( get_option('blog_public') == 2 )
|
175 |
-
$text = __('
|
176 |
|
177 |
return $text;
|
178 |
}
|
179 |
|
180 |
-
function privacy_on_link_title( $text )
|
181 |
-
{
|
182 |
if ( get_option('blog_public') == 2 )
|
183 |
-
$text = __('Restricted Site Access plug-in is blocking public access to this site.');
|
184 |
|
185 |
return $text;
|
186 |
}
|
187 |
|
188 |
-
function load_options_privacy()
|
189 |
-
|
190 |
-
wp_enqueue_script( 'restricted-site-access', plugin_dir_url( __FILE__ ) . 'restricted-site-access.js', array('jquery'), '3.2', true );
|
191 |
add_filter( 'contextual_help', array( $this, 'contextual_help' ) );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
192 |
}
|
193 |
|
194 |
-
function blog_privacy_selector() {
|
195 |
?>
|
196 |
<br />
|
197 |
<input id="blog-restricted" type="radio" name="blog_public" value="2" <?php checked( '2', get_option('blog_public') ); ?> />
|
198 |
-
<label for="blog-restricted"><?php _e('
|
199 |
<?php
|
200 |
}
|
201 |
|
202 |
-
function sanitize_options( $input )
|
203 |
-
|
204 |
-
$new_input['approach']
|
205 |
-
|
206 |
-
if ( !in_array( $new_input['approach'], array(1,2,3) ) )
|
207 |
$new_input['approach'] = 1;
|
208 |
|
209 |
-
$new_input['redirect_path'] = (
|
210 |
-
$new_input['head_code'] =
|
211 |
$new_input['message'] = trim( $input['message'] );
|
212 |
-
$new_input['redirect_url'] = esc_url( $input['redirect_url'], array('http','https') );
|
|
|
213 |
|
214 |
$new_input['allowed'] = $input['allowed']; // probably need regex at some point
|
215 |
|
216 |
return $new_input;
|
217 |
}
|
218 |
|
219 |
-
function settings_field_handling( $
|
220 |
-
{
|
221 |
if ( !isset($this->rsa_options['approach']) )
|
222 |
-
$this->rsa_options['approach'] =
|
223 |
?>
|
224 |
-
<
|
225 |
-
<
|
226 |
-
<
|
227 |
-
<
|
228 |
-
|
229 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
230 |
<?php
|
231 |
}
|
232 |
|
233 |
-
function settings_field_allowed( $
|
234 |
?>
|
|
|
235 |
<div id="ip_list">
|
236 |
<?php
|
237 |
-
|
238 |
-
$this->rsa_options['allowed'] = false;
|
239 |
-
|
240 |
-
$ips = $this->rsa_options['allowed'];
|
241 |
|
242 |
-
|
243 |
-
|
244 |
-
|
245 |
-
{
|
246 |
-
if ( empty($ip) )
|
247 |
-
continue;
|
248 |
|
249 |
-
|
250 |
-
}
|
251 |
}
|
252 |
?>
|
253 |
</div>
|
254 |
-
<input type="text" name="newip" id="newip" value="" /><input class="button" type="button" onclick="add_ip(jQuery('#newip').val());" value="add" />
|
255 |
-
<span class="description"><?php _e('Enter a single IP or a range using a subnet prefix
|
256 |
<br />
|
257 |
-
|
|
|
|
|
|
|
|
|
258 |
<?php
|
259 |
}
|
260 |
|
261 |
-
function settings_field_message( $
|
262 |
-
|
|
|
263 |
?>
|
264 |
-
<input type="text" name="rsa_options[message]" id="rsa_message" value="<?php echo
|
265 |
-
<span class="description"><?php _e('Default (blank): "Access to this site is restricted."'); ?></span>
|
266 |
<?php
|
267 |
}
|
268 |
|
269 |
-
function settings_field_redirect( $
|
270 |
-
{
|
271 |
?>
|
272 |
-
<input type="text" name="rsa_options[redirect_url]" id="redirect" value="<?php echo @esc_attr( $this->rsa_options['redirect_url'] ); ?>"
|
273 |
<?php
|
274 |
}
|
275 |
|
276 |
-
function settings_field_redirect_path( $
|
277 |
-
{
|
278 |
?>
|
279 |
-
<input type="checkbox" name="rsa_options[redirect_path]" value="1" id="redirect_path" <?php @checked( $this->rsa_options['redirect_path'] ); ?> />
|
280 |
-
<?php _e('Send visitor to same relative URL at
|
281 |
<?php
|
282 |
}
|
283 |
|
284 |
-
function settings_field_redirect_code( $
|
285 |
-
|
|
|
286 |
?>
|
287 |
-
<select name="rsa_options[head_code]" id="redirect_code">
|
288 |
-
<option value="301" <?php
|
289 |
-
<option value="302" <?php
|
290 |
-
<option value="307" <?php
|
291 |
</select>
|
292 |
-
<span class="description"><?php _e('
|
293 |
<?php
|
294 |
}
|
295 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
296 |
/**
|
297 |
* special contextual help added to the privacy screen
|
298 |
*/
|
299 |
-
function contextual_help( $text )
|
300 |
{
|
301 |
return $text . '
|
302 |
-
<h5>
|
303 |
-
<p><a href="http://www.get10up.com/plugins/restricted-site-access-wordpress/" target="_blank">
|
304 |
|
305 |
-
<p><strong>' . __('
|
306 |
-
<p><strong>' . __('Allowed
|
307 |
|
308 |
-
<h5>' . __('Redirection Options') . '</h5>
|
309 |
-
<p>' . __('The redirection fields are only used when "
|
310 |
-
<p><strong>' . __('Redirect
|
311 |
-
<p><strong>' . __('Redirect to same path') . '</strong> - ' . __('redirect the visitor to the same path (URI) entered at this site. Typically used when there are two, very similar sites at different public web addresses; for instance, a parallel development server accessible on the Internet but not intended for the public.') . '</p>
|
312 |
-
<p><strong>' . __('Redirection
|
313 |
-
|
314 |
-
<h5><a href="http://www.get10up.com/plugins/restricted-site-access-wordpress/" target="_blank">' . __('Restricted Site Access support') . '</a></h5>
|
315 |
';
|
316 |
}
|
317 |
|
318 |
/**
|
319 |
* add settings link directing user to privacy page on plug-in page
|
320 |
*/
|
321 |
-
function plugin_action_links( $links )
|
322 |
-
|
323 |
-
array_unshift( $links, '<a href="options-privacy.php">'.__('Settings').'</a>' );
|
324 |
return $links;
|
325 |
}
|
326 |
|
327 |
/**
|
328 |
* activation of plugin: upgrades old versions, immediately sets privacy
|
329 |
*/
|
330 |
-
function activation()
|
331 |
-
|
332 |
-
$blog_public =
|
333 |
-
|
334 |
-
// if upgrading from pre-3.0, update the blog_public option
|
335 |
-
if ( $rsa_options = $this->rsa_options )
|
336 |
-
{
|
337 |
-
if ( isset($rsa_options['active']) && !$rsa_options['active'] )
|
338 |
-
$blog_public = 1;
|
339 |
-
}
|
340 |
-
|
341 |
-
// upgrading pre 1.1
|
342 |
-
if ( get_option('rsa_restrict_approach') )
|
343 |
-
{
|
344 |
-
//visibility
|
345 |
-
if ( !get_option('rsa_is_active') )
|
346 |
-
$blog_public = 1;
|
347 |
-
|
348 |
-
//convert textarea ips to array
|
349 |
-
$allowed = get_option('rsa_allowed_ips');
|
350 |
-
if ($allowed)
|
351 |
-
{
|
352 |
-
$arrAllowed = preg_split('/\s+/', $allowed);
|
353 |
-
|
354 |
-
if ( empty($arrAllowed) )
|
355 |
-
$arrAllowed = array($allowed);
|
356 |
-
}
|
357 |
-
|
358 |
-
$rsa_options = array(
|
359 |
-
'allowed' => $arrAllowed,
|
360 |
-
'approach' => (get_option('rsa_restrict_approach')),
|
361 |
-
'redirect_path' => (get_option('rsa_redirect_path')),
|
362 |
-
'redirect_url' => (get_option('rsa_redirect_url')),
|
363 |
-
'head_code' => (get_option('rsa_redirect_head'))
|
364 |
-
);
|
365 |
-
update_option('rsa_options',$rsa_options);
|
366 |
-
|
367 |
-
delete_option('rsa_is_active');
|
368 |
-
delete_option('rsa_allowed_ips');
|
369 |
-
delete_option('rsa_restrict_approach');
|
370 |
-
delete_option('rsa_redirect_path');
|
371 |
-
delete_option('rsa_redirect_url');
|
372 |
-
delete_option('rsa_redirect_head');
|
373 |
-
}
|
374 |
-
|
375 |
update_option( 'blog_public', $blog_public ); // set blog visibility
|
376 |
}
|
377 |
|
378 |
/**
|
379 |
* restore privacy option to default value upon deactivating
|
380 |
*/
|
381 |
-
function deactivation()
|
382 |
-
{
|
383 |
if ( get_option('blog_public') == 2 )
|
384 |
update_option( 'blog_public', 1 );
|
385 |
}
|
@@ -393,8 +358,7 @@ $restricted_site_access = new restricted_site_access;
|
|
393 |
|
394 |
register_uninstall_hook( __FILE__, 'restricted_site_access_uninstall' );
|
395 |
|
396 |
-
function restricted_site_access_uninstall()
|
397 |
-
{
|
398 |
if ( get_option('blog_public') == 2 )
|
399 |
update_option( 'blog_public', 1 );
|
400 |
|
2 |
/**
|
3 |
Plugin Name: Restricted Site Access
|
4 |
Plugin URI: http://www.get10up.com/plugins/restricted-site-access-wordpress/
|
5 |
+
Description: <strong>Limit access your site</strong> to visitors who are logged in or accessing the site from a set of specific IP addresses. Send restricted visitors to the log in page, redirect them, or display a message or page. <strong>Powerful control over redirection</strong>, including <strong>SEO friendly redirect headers</strong>. Great solution for Extranets, publicly hosted Intranets, or parallel development sites.
|
6 |
+
Version: 4.0
|
7 |
Author: Jake Goldman (10up)
|
8 |
Author URI: http://www.get10up.com
|
9 |
|
24 |
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
25 |
*/
|
26 |
|
27 |
+
class restricted_site_access {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
28 |
|
29 |
+
private $rsa_options;
|
30 |
+
|
31 |
+
public function __construct() {
|
32 |
$this->rsa_options = get_option('rsa_options');
|
33 |
|
34 |
+
add_action( 'parse_request', array( $this, 'restrict_access' ), 1 );
|
35 |
add_action( 'admin_init', array( $this, 'admin_init' ) );
|
36 |
+
add_action( 'init', array( $this, 'init' ) );
|
37 |
|
38 |
register_activation_hook( __FILE__, array( $this, 'activation' ) );
|
39 |
+
register_deactivation_hook( __FILE__, array( $this, 'deactivation' ) );
|
40 |
}
|
41 |
|
42 |
+
function init() {
|
43 |
+
load_plugin_textdomain( 'restricted-site-access', false, dirname( plugin_basename( __FILE__ ) ) . '/localization/' );
|
44 |
+
}
|
45 |
+
|
46 |
+
public function restrict_access( $wp ) {
|
47 |
+
remove_action( 'parse_request', array( $this, 'restrict_access' ), 1 ); // only need it the first time
|
48 |
+
|
49 |
+
$is_restricted = ( is_admin() || is_user_logged_in() || get_option('blog_public') != 2 ) ? false : true;
|
50 |
+
|
51 |
+
if ( apply_filters( 'restricted_site_access_is_restricted', $is_restricted ) === false )
|
52 |
return;
|
53 |
|
54 |
$rsa_options = $this->rsa_options;
|
55 |
|
56 |
// check for the allow list, if its empty block everything
|
57 |
+
if( isset($rsa_options['allowed']) && ( $list = $rsa_options['allowed'] ) ) {
|
58 |
+
|
59 |
$remote_ip = $_SERVER['REMOTE_ADDR']; //save the remote ip
|
60 |
if( strpos($remote_ip, '.') ) $remote_ip = str_replace('::ffff:', '', $remote_ip); //handle dual-stack addresses
|
61 |
$remote_ip = inet_pton($remote_ip); //parse the remote ip
|
62 |
|
63 |
// iterate through the allow list
|
64 |
+
foreach($list as $line) {
|
|
|
65 |
list($ip, $mask) = explode('/', $line . '/128'); // get the ip and mask from the list
|
66 |
|
67 |
$mask = str_repeat('f', $mask >> 2); //render the mask as bits, similar to info on the php.net man page discussion for inet_pton
|
86 |
}
|
87 |
}
|
88 |
|
89 |
+
$rsa_restrict_approach = apply_filters( 'restricted_site_access_approach', $rsa_options['approach'] );
|
90 |
|
91 |
do_action( 'restrict_site_access_handling', $rsa_restrict_approach ); // allow users to hook handling
|
92 |
|
93 |
+
switch( $rsa_restrict_approach ) {
|
94 |
+
case 4:
|
95 |
+
if ( ! empty( $rsa_options['page'] ) && ( $page = get_page( $rsa_options['page'] ) ) ) {
|
96 |
+
unset( $wp->query_vars );
|
97 |
+
$wp->query_vars['page_id'] = $page->ID;
|
98 |
+
return;
|
99 |
+
}
|
100 |
+
|
101 |
case 3:
|
102 |
+
$message = empty($rsa_options['message']) ? __( "Access to this site is restricted.", 'restricted-site-access' ) : $rsa_options['message'];
|
103 |
+
$message .= "\n<!-- access protected by Restricted Site Access plug-in | http://www.get10up.com/plugins/restricted-site-access-wordpress/ -->";
|
104 |
+
$message = apply_filters( 'restricted_site_access_message', $message );
|
105 |
|
106 |
+
wp_die( $message, get_bloginfo('name') . ' - Site Access Restricted' );
|
107 |
|
108 |
case 2:
|
109 |
+
if ( ! empty($rsa_options['redirect_url']) ) {
|
110 |
+
if( ! empty($rsa_options['redirect_path']) )
|
111 |
+
$rsa_options['redirect_url'] .= $_SERVER["REQUEST_URI"]; // path
|
|
|
112 |
|
113 |
+
$rsa_redirect_url = $rsa_options['redirect_url'];
|
114 |
+
$rsa_redirect_head = empty($rsa_options['head_code']) ? 302 : (int) $rsa_options['head_code']; // code
|
115 |
+
|
116 |
+
break;
|
117 |
}
|
|
|
118 |
|
119 |
default:
|
120 |
$rsa_redirect_head = 302;
|
121 |
+
$rsa_redirect_url = wp_login_url( empty($_SERVER["REQUEST_URI"]) ? home_url() : $_SERVER["REQUEST_URI"] );
|
122 |
}
|
123 |
|
124 |
+
wp_redirect( apply_filters( 'restricted_site_access_redirect_url', $rsa_redirect_url ), apply_filters( 'restricted_site_access_head', $rsa_redirect_head ) );
|
125 |
exit;
|
126 |
}
|
127 |
|
128 |
+
public function admin_init() {
|
|
|
129 |
// customize privacy message
|
130 |
add_filter( 'privacy_on_link_text', array( $this, 'privacy_on_link_text' ) );
|
131 |
add_filter( 'privacy_on_link_title', array( $this, 'privacy_on_link_title' ) );
|
138 |
|
139 |
// settings for restricted site access
|
140 |
register_setting( 'privacy', 'rsa_options', array( $this, 'sanitize_options' ) ); //array of fundamental options including ID and caching info
|
141 |
+
add_settings_section( 'restricted-site-access', '', '__return_false', 'privacy' );
|
142 |
+
add_settings_field( 'approach', __('Handle restricted visitors', 'restricted-site-access'), array( $this, 'settings_field_handling' ), 'privacy', 'restricted-site-access' );
|
143 |
+
add_settings_field( 'message', __('Restriction message', 'restricted-site-access'), array( $this, 'settings_field_message' ), 'privacy', 'restricted-site-access' );
|
144 |
+
add_settings_field( 'redirect', __('Redirect web address', 'restricted-site-access'), array( $this, 'settings_field_redirect' ), 'privacy', 'restricted-site-access' );
|
145 |
+
add_settings_field( 'redirect_path', __('Redirect to same path', 'restricted-site-access'), array( $this, 'settings_field_redirect_path' ), 'privacy', 'restricted-site-access' );
|
146 |
+
add_settings_field( 'redirect_code', __('Redirection status code', 'restricted-site-access'), array( $this, 'settings_field_redirect_code' ), 'privacy', 'restricted-site-access' );
|
147 |
+
add_settings_field( 'rsa_page', __('Restricted notice page', 'restricted-site-access'), array( $this, 'settings_field_rsa_page' ), 'privacy', 'restricted-site-access' );
|
148 |
+
add_settings_field( 'allowed', __('Unrestricted IP addresses', 'restricted-site-access'), array( $this, 'settings_field_allowed' ), 'privacy', 'restricted-site-access' );
|
149 |
|
150 |
add_filter( 'plugin_action_links_' . plugin_basename(__FILE__), array( $this, 'plugin_action_links' ) );
|
151 |
}
|
152 |
|
153 |
+
public function privacy_on_link_text( $text ) {
|
|
|
|
|
|
|
154 |
if ( get_option('blog_public') == 2 )
|
155 |
+
$text = __('Public access to this site has been restricted.', 'restricted-site-access');
|
156 |
|
157 |
return $text;
|
158 |
}
|
159 |
|
160 |
+
public function privacy_on_link_title( $text ) {
|
|
|
161 |
if ( get_option('blog_public') == 2 )
|
162 |
+
$text = __('Restricted Site Access plug-in is blocking public access to this site.', 'restricted-site-access');
|
163 |
|
164 |
return $text;
|
165 |
}
|
166 |
|
167 |
+
public function load_options_privacy() {
|
168 |
+
wp_enqueue_script( 'restricted-site-access', plugin_dir_url( __FILE__ ) . 'restricted-site-access.js', array('jquery'), '3.3', true );
|
|
|
169 |
add_filter( 'contextual_help', array( $this, 'contextual_help' ) );
|
170 |
+
add_action( 'admin_notices', array( $this, 'admin_notice' ) );
|
171 |
+
|
172 |
+
$js_trans = array(
|
173 |
+
'SaveChanges' => __('Click "Save Changes" to save this IP address.','restricted-site-access'),
|
174 |
+
'Remove' => __('remove','restricted-site-access'),
|
175 |
+
'ConfirmRemove' => __('confirm removal','restricted-site-access'),
|
176 |
+
'Cancel' => __('cancel','restricted-site-access')
|
177 |
+
);
|
178 |
+
wp_localize_script( 'restricted-site-access', 'restricted_site_access_l10n', $js_trans );
|
179 |
+
}
|
180 |
+
|
181 |
+
function admin_notice() {
|
182 |
+
if ( empty( $this->rsa_options['approach'] ) )
|
183 |
+
return;
|
184 |
+
|
185 |
+
if ( $this->rsa_options['approach'] == 4 && empty( $this->rsa_options['page'] ) )
|
186 |
+
$message = '<strong>' . __( 'Please select the page you want to show restricted visitors. If no page is selected, WordPress will simply show a general restriction message.', 'restricted-site-access' ) . '</strong>';
|
187 |
+
elseif ( $this->rsa_options['approach'] == 2 && empty( $this->rsa_options['redirect_url'] ) )
|
188 |
+
$message = '<strong>' . __( 'Please enter the web address you would like to redirect restriced visitors to. If no address is entered, visitors will be redirected to the login screen.', 'restricted-site-access' ) . '</strong>';
|
189 |
+
|
190 |
+
if ( ! empty( $message ) )
|
191 |
+
echo '<div class="updated settings-error"><p>' . $message . '</p></div>';
|
192 |
}
|
193 |
|
194 |
+
public function blog_privacy_selector() {
|
195 |
?>
|
196 |
<br />
|
197 |
<input id="blog-restricted" type="radio" name="blog_public" value="2" <?php checked( '2', get_option('blog_public') ); ?> />
|
198 |
+
<label for="blog-restricted"><?php _e('Restrict site access to visitors who are logged in or allowed by IP address', 'restricted-site-access'); ?></label>
|
199 |
<?php
|
200 |
}
|
201 |
|
202 |
+
public function sanitize_options( $input ) {
|
203 |
+
$new_input['approach'] = (int) $input['approach'];
|
204 |
+
if ( $new_input['approach'] < 1 || $new_input['approach'] > 4 )
|
|
|
|
|
205 |
$new_input['approach'] = 1;
|
206 |
|
207 |
+
$new_input['redirect_path'] = empty( $input['redirect_path'] ) ? 0 : 1;
|
208 |
+
$new_input['head_code'] = in_array( (int) $input['head_code'], array(301,302,307) ) ? (int) $input['head_code'] : 302;
|
209 |
$new_input['message'] = trim( $input['message'] );
|
210 |
+
$new_input['redirect_url'] = empty( $input['redirect_url'] ) ? '' : esc_url( $input['redirect_url'], array('http','https') );
|
211 |
+
$new_input['page'] = empty( $input['page'] ) ? '' : (int) $input['page'];
|
212 |
|
213 |
$new_input['allowed'] = $input['allowed']; // probably need regex at some point
|
214 |
|
215 |
return $new_input;
|
216 |
}
|
217 |
|
218 |
+
public function settings_field_handling( $args ) {
|
|
|
219 |
if ( !isset($this->rsa_options['approach']) )
|
220 |
+
$this->rsa_options['approach'] = 1;
|
221 |
?>
|
222 |
+
<fieldset>
|
223 |
+
<input id="rsa-send-to-login" name="rsa_options[approach]" type="radio" value="1" <?php checked( $this->rsa_options['approach'], 1 ); ?> />
|
224 |
+
<label for="rsa-send-to-login"><?php _e('Send them to the WordPress login screen','restricted-site-access'); ?></label>
|
225 |
+
<br />
|
226 |
+
<input id="rsa-redirect-visitor" name="rsa_options[approach]" type="radio" value="2" <?php checked( $this->rsa_options['approach'], 2 ); ?> />
|
227 |
+
<label for="rsa-redirect-visitor"><?php _e('Redirect them to a specified web address','restricted-site-access'); ?></label>
|
228 |
+
<br />
|
229 |
+
<input id="rsa-display-message" name="rsa_options[approach]" type="radio" value="3" <?php checked( $this->rsa_options['approach'], 3 ); ?> />
|
230 |
+
<label for="rsa-display-message"><?php _e('Show them a simple message','restricted-site-access'); ?></label>
|
231 |
+
<br />
|
232 |
+
<input id="rsa-unblocked-page" name="rsa_options[approach]" type="radio" value="4" <?php checked( $this->rsa_options['approach'], 4 ); ?> />
|
233 |
+
<label for="rsa-unblocked-page"><?php _e('Show them a specific WordPress page I\'ve created','restricted-site-access'); ?></label>
|
234 |
+
</fieldset>
|
235 |
<?php
|
236 |
}
|
237 |
|
238 |
+
public function settings_field_allowed( $args ) {
|
239 |
?>
|
240 |
+
<div class="hide-if-no-js">
|
241 |
<div id="ip_list">
|
242 |
<?php
|
243 |
+
$ips = empty($this->rsa_options['allowed']) ? array() : $this->rsa_options['allowed'];
|
|
|
|
|
|
|
244 |
|
245 |
+
foreach ($ips as $key => $ip) {
|
246 |
+
if ( empty($ip) )
|
247 |
+
continue;
|
|
|
|
|
|
|
248 |
|
249 |
+
echo '<span><input type="text" name="rsa_options[allowed][]" value="' . esc_attr($ip) . '" readonly="true" /><input type="button" class="button" onclick="remove_ip(this);" value="' . __('remove','restricted-site-access') . '" /><br /></span>';
|
|
|
250 |
}
|
251 |
?>
|
252 |
</div>
|
253 |
+
<input type="text" name="newip" id="newip" value="" /><input class="button" type="button" onclick="add_ip(jQuery('#newip').val());" value="<?php _e('add','restricted-site-access'); ?>" />
|
254 |
+
<span class="description"><?php _e('Enter a single IP address or a range using a subnet prefix','restricted-site-access'); ?> (<a href="#" onclick="jQuery('#contextual-help-link').click(); return false;"><?php _e('help'); ?></a>)</span>
|
255 |
<br />
|
256 |
+
<?php if ( ! empty($_SERVER['REMOTE_ADDR']) ) { ?>
|
257 |
+
<input class="button" type="button" onclick="add_ip('<?php echo $_SERVER['REMOTE_ADDR']; ?>');" value="<?php _e('add my current IP address','restricted-site-access'); ?>" style="margin: 5px 0;" /><br />
|
258 |
+
<?php } ?>
|
259 |
+
</div>
|
260 |
+
<p class="hide-if-js"><strong><?php _e('To manage IP addresses, you must use a JavaScript enabled browser.','restricted-site-access'); ?></strong></p>
|
261 |
<?php
|
262 |
}
|
263 |
|
264 |
+
public function settings_field_message( $args ) {
|
265 |
+
if ( empty($this->rsa_options['message']) )
|
266 |
+
$this->rsa_options['message'] = __('Access to this site is restricted.','restricted-site-access');
|
267 |
?>
|
268 |
+
<input type="text" name="rsa_options[message]" id="rsa_message" value="<?php echo esc_attr( $this->rsa_options['message'] ); ?>" class="regular-text" />
|
|
|
269 |
<?php
|
270 |
}
|
271 |
|
272 |
+
public function settings_field_redirect( $args ) {
|
|
|
273 |
?>
|
274 |
+
<input type="text" name="rsa_options[redirect_url]" id="redirect" class="rsa_redirect_field regular-text" value="<?php echo @esc_attr( $this->rsa_options['redirect_url'] ); ?>" />
|
275 |
<?php
|
276 |
}
|
277 |
|
278 |
+
public function settings_field_redirect_path( $args ) {
|
|
|
279 |
?>
|
280 |
+
<input type="checkbox" name="rsa_options[redirect_path]" value="1" id="redirect_path" class="rsa_redirect_field" <?php @checked( $this->rsa_options['redirect_path'] ); ?> />
|
281 |
+
<?php _e('Send restricted visitor to same path (relative URL) at the new web address','restricted-site-access'); ?> (<a href="#" onclick="jQuery('#contextual-help-link').click(); return false;"><?php _e('help'); ?></a>)
|
282 |
<?php
|
283 |
}
|
284 |
|
285 |
+
public function settings_field_redirect_code( $args ) {
|
286 |
+
if ( empty($this->rsa_options['head_code']) )
|
287 |
+
$this->rsa_options['head_code'] = 302;
|
288 |
?>
|
289 |
+
<select name="rsa_options[head_code]" id="redirect_code" class="rsa_redirect_field">
|
290 |
+
<option value="301" <?php selected( $this->rsa_options['head_code'], 301 ); ?>><?php _e('301 Permanent','restricted-site-access'); ?></option>
|
291 |
+
<option value="302" <?php selected( $this->rsa_options['head_code'], 302 ); ?>><?php _e('302 Undefined','restricted-site-access'); ?></option>
|
292 |
+
<option value="307" <?php selected( $this->rsa_options['head_code'], 307 ); ?>><?php _e('307 Temporary','restricted-site-access'); ?></option>
|
293 |
</select>
|
294 |
+
<span class="description"><?php _e('HTTP status code sent to browser','restricted-site-access'); ?> (<a href="#" onclick="jQuery('#contextual-help-link').click(); return false;"><?php _e('help'); ?></a>)</span>
|
295 |
<?php
|
296 |
}
|
297 |
|
298 |
+
public function settings_field_rsa_page( $args ) {
|
299 |
+
wp_dropdown_pages(array(
|
300 |
+
'selected' => @$this->rsa_options['page'],
|
301 |
+
'show_option_none' => 'Select a page',
|
302 |
+
'name' => 'rsa_options[page]',
|
303 |
+
'id' => 'rsa_page'
|
304 |
+
));
|
305 |
+
}
|
306 |
+
|
307 |
/**
|
308 |
* special contextual help added to the privacy screen
|
309 |
*/
|
310 |
+
public function contextual_help( $text )
|
311 |
{
|
312 |
return $text . '
|
313 |
+
<h5>Restricted Site Access</h5>
|
314 |
+
<p><a href="http://www.get10up.com/plugins/restricted-site-access-wordpress/" target="_blank">Restricted Site Access</a> ' . __('is a plug-in by','restricted-site-access') . ' <a href="http://www.get10up.com" target="_blank">Jake Goldman</a> (<a href="http://www.get10up.com/plugins/restricted-site-access-wordpress/" target="_blank">10up</a>) ' . __('that allows you to restrict access to logged in users and a set of IP addresses.','restricted-site-access') . '</p>
|
315 |
|
316 |
+
<p><strong>' . __('Handle restricted visitors','restricted-site-access') . '</strong> - ' . __('choose the method for handling visitors to your site that are restricted.','restricted-site-access') . '</p>
|
317 |
+
<p><strong>' . __('Allowed IP addresses','restricted-site-access') . '</strong> - ' . __('enter a single IP address (for example, 192.168.1.105) or an IP range using a network prefix (for example, 10.0.0.1/24). Enter your addresses carefully! Here\'s a','restricted-site-access') . ' <a href="http://www.csgnetwork.com/ipinfocalc.html" target="_blank">' . __('handy calculator','restricted-site-access') . '</a> ' . __('to check your prefix.','restricted-site-access') . '</p>
|
318 |
|
319 |
+
<h5>' . __('Redirection Options','restricted-site-access') . '</h5>
|
320 |
+
<p>' . __('The redirection fields are only used when "Handle restricted visitors" is set to "Redirect them to a specified web address".','restricted-site-access') . '</p>
|
321 |
+
<p><strong>' . __('Redirect web address','restricted-site-access') . '</strong> - ' . __('the web address of the site you want the visitor redirected to.','restricted-site-access') . '</p>
|
322 |
+
<p><strong>' . __('Redirect to same path','restricted-site-access') . '</strong> - ' . __('redirect the visitor to the same path (URI) entered at this site. Typically used when there are two, very similar sites at different public web addresses; for instance, a parallel development server accessible on the Internet but not intended for the public.','restricted-site-access') . '</p>
|
323 |
+
<p><strong>' . __('Redirection status code','restricted-site-access') . '</strong> - ' . __('redirect status codes can provide certain visitors, particularly search engines, more information about the nature of the redirect. A 301 redirect tells search engines that a page has moved permanently to the new location. 307 indicates a temporary redirect. 302 is an undefined redirect.','restricted-site-access') . '</p>
|
|
|
|
|
324 |
';
|
325 |
}
|
326 |
|
327 |
/**
|
328 |
* add settings link directing user to privacy page on plug-in page
|
329 |
*/
|
330 |
+
public function plugin_action_links( $links ) {
|
331 |
+
$links[] = '<a href="options-privacy.php">'.__('Settings').'</a>';
|
|
|
332 |
return $links;
|
333 |
}
|
334 |
|
335 |
/**
|
336 |
* activation of plugin: upgrades old versions, immediately sets privacy
|
337 |
*/
|
338 |
+
public function activation() {
|
339 |
+
// if upgrading from pre-3.0, update the blog_public option, otherwise just set to 2
|
340 |
+
$blog_public = ( isset($this->rsa_options['active']) && ! $this->rsa_options['active'] ) ? 1 : 2;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
341 |
update_option( 'blog_public', $blog_public ); // set blog visibility
|
342 |
}
|
343 |
|
344 |
/**
|
345 |
* restore privacy option to default value upon deactivating
|
346 |
*/
|
347 |
+
public function deactivation() {
|
|
|
348 |
if ( get_option('blog_public') == 2 )
|
349 |
update_option( 'blog_public', 1 );
|
350 |
}
|
358 |
|
359 |
register_uninstall_hook( __FILE__, 'restricted_site_access_uninstall' );
|
360 |
|
361 |
+
function restricted_site_access_uninstall() {
|
|
|
362 |
if ( get_option('blog_public') == 2 )
|
363 |
update_option( 'blog_public', 1 );
|
364 |
|
screenshot-1.png
CHANGED
Binary file
|
screenshot-2.png
ADDED
Binary file
|
screenshot-3.png
ADDED
Binary file
|
screenshot-4.png
ADDED
Binary file
|