My Private Site - Version 2.2

Version Description

  • Add the WordPress User Self-Registration field to the plugin's Settings page
  • Add the Settings page to the User submenu of Admin panel, too
Download this release

Release Info

Developer dgewirtz
Plugin Icon 128x128 My Private Site
Version 2.2
Comparing to
See all releases

Version 2.2

includes/admin-settings.php ADDED
@@ -0,0 +1,366 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ Initiated when in the Admin panels.
4
+ Used to create the Settings page for the plugin.
5
+ */
6
+
7
+ // Exit if .php file accessed directly
8
+ if ( !defined( 'ABSPATH' ) ) exit;
9
+
10
+ require_once( jr_ps_path() . 'includes/functions-admin.php' );
11
+
12
+ add_action( 'admin_menu', 'jr_ps_admin_hook' );
13
+ // Runs just before admin_init (below)
14
+
15
+ /**
16
+ * Add Admin Menu item for plugin
17
+ *
18
+ * Plugin needs its own Page in the Settings section of the Admin menu.
19
+ *
20
+ */
21
+ function jr_ps_admin_hook() {
22
+ // Add Settings Page for this Plugin
23
+ global $jr_ps_plugin_data;
24
+ add_options_page( $jr_ps_plugin_data['Name'], 'Private Site', 'manage_options', 'jr_ps_settings', 'jr_ps_settings_page' );
25
+ add_users_page( $jr_ps_plugin_data['Name'], 'Private Site', 'add_users', 'jr_ps_settings', 'jr_ps_settings_page' );
26
+ }
27
+
28
+ /**
29
+ * Settings page for plugin
30
+ *
31
+ * Display and Process Settings page for this plugin.
32
+ *
33
+ */
34
+ function jr_ps_settings_page() {
35
+ global $jr_ps_plugin_data;
36
+ add_thickbox();
37
+ echo '<div class="wrap">';
38
+ screen_icon( 'plugins' );
39
+ echo '<h2>' . $jr_ps_plugin_data['Name'] . '</h2><h3>Overview</h3><p>';
40
+ $settings = get_option( 'jr_ps_settings' );
41
+ if ( $settings['private_site'] ) {
42
+ echo 'This';
43
+ } else {
44
+ echo 'If you click the <b>Private Site</b> checkbox below, this';
45
+ }
46
+ ?>
47
+ Plugin creates a Private Site,
48
+ by ensuring that site visitors login
49
+ before viewing your web site.
50
+ The only things visible to anyone not logged in, including Search Engines, are:
51
+ <ul>
52
+ <li> &raquo; Your site's WordPress Login page;</li>
53
+ <li> &raquo; Any non-WordPress components of your web site, such as HTML, PHP, ASP or other non-WordPress web page files;</li>
54
+ <li> &raquo; Images and other media and text files, but only when accessed directly by their URL,
55
+ or from a browser's directory view, if available.</li>
56
+ </ul>
57
+ Other means are available to hide most, if not all, of the files mentioned above.
58
+ </p>
59
+ <p>
60
+ To see your site, each visitor will need to be registered as a User on your WordPress site.
61
+ They will also have to enter their Username and Password on the WordPress login screen.
62
+ </p>
63
+ <p>
64
+ You can choose what they see after they login by selecting a <b>Landing Location</b> in the section below.
65
+ </p>
66
+ <form action="options.php" method="POST">
67
+ <?php
68
+ // Plugin Settings are displayed and entered here:
69
+ settings_fields( 'jr_ps_settings' );
70
+ do_settings_sections( 'jr_ps_settings_page' );
71
+ echo '<p><input name="save" type="submit" value="Save Changes" class="button-primary" /></p></form>';
72
+
73
+ /* Turn off Warning about Private Site defaulting to OFF
74
+ once Admin has seen Settings page.
75
+ */
76
+ $internal_settings = get_option( 'jr_ps_internal_settings' );
77
+ if ( isset( $internal_settings['warning_privacy'] ) ) {
78
+ unset( $internal_settings['warning_privacy'] );
79
+ update_option( 'jr_ps_internal_settings', $internal_settings );
80
+ }
81
+ }
82
+
83
+ add_action( 'admin_init', 'jr_ps_admin_init' );
84
+
85
+ /**
86
+ * Register and define the settings
87
+ *
88
+ * Everything to be stored and/or can be set by the user
89
+ *
90
+ */
91
+ function jr_ps_admin_init() {
92
+ register_setting( 'jr_ps_settings', 'jr_ps_settings', 'jr_ps_validate_settings' );
93
+ add_settings_section( 'jr_ps_private_settings_section',
94
+ 'Make Site Private',
95
+ 'jr_ps_private_settings_expl',
96
+ 'jr_ps_settings_page'
97
+ );
98
+ add_settings_field( 'private_site',
99
+ 'Private Site',
100
+ 'jr_ps_echo_private_site',
101
+ 'jr_ps_settings_page',
102
+ 'jr_ps_private_settings_section'
103
+ );
104
+ add_settings_section( 'jr_ps_self_registration_section',
105
+ 'Allow Self-Registration',
106
+ 'jr_ps_self_registration_expl',
107
+ 'jr_ps_settings_page'
108
+ );
109
+ if ( is_multisite() ) {
110
+ /* Clone Network Admin panels: Settings-Network Settings-Registration Settings-Allow new registrations.
111
+ It will be Read-Only except for Super Administrators.
112
+ */
113
+ add_settings_field( 'registrations',
114
+ 'Allow new registrations',
115
+ 'jr_ps_echo_registrations',
116
+ 'jr_ps_settings_page',
117
+ 'jr_ps_self_registration_section'
118
+ );
119
+ } else {
120
+ /* Clone Site Admin panels: Settings-General Settings-Membership
121
+ */
122
+ add_settings_field( 'membership',
123
+ 'Membership',
124
+ 'jr_ps_echo_membership',
125
+ 'jr_ps_settings_page',
126
+ 'jr_ps_self_registration_section'
127
+ );
128
+ }
129
+ add_settings_field( 'reveal_registration',
130
+ 'Reveal User Registration Page',
131
+ 'jr_ps_echo_reveal_registration',
132
+ 'jr_ps_settings_page',
133
+ 'jr_ps_self_registration_section'
134
+ );
135
+ add_settings_section( 'jr_ps_landing_settings_section',
136
+ 'Landing Location',
137
+ 'jr_ps_landing_settings_expl',
138
+ 'jr_ps_settings_page'
139
+ );
140
+ add_settings_field( 'landing',
141
+ 'Where to after Login?',
142
+ 'jr_ps_echo_landing',
143
+ 'jr_ps_settings_page',
144
+ 'jr_ps_landing_settings_section'
145
+ );
146
+ add_settings_field( 'specific_url',
147
+ 'Specific URL',
148
+ 'jr_ps_echo_specific_url',
149
+ 'jr_ps_settings_page',
150
+ 'jr_ps_landing_settings_section'
151
+ );
152
+ }
153
+
154
+ /**
155
+ * Section text for Section1
156
+ *
157
+ * Display an explanation of this Section
158
+ *
159
+ */
160
+ function jr_ps_private_settings_expl() {
161
+ ?>
162
+ <p>
163
+ You will only have a Private Site if the checkbox just below is checked.
164
+ This allows you to disable the Private Site functionality
165
+ without deactivating the Plugin.
166
+ </p>
167
+ <?php
168
+ }
169
+
170
+ function jr_ps_echo_private_site() {
171
+ $settings = get_option( 'jr_ps_settings' );
172
+ echo '<input type="checkbox" id="private_site" name="jr_ps_settings[private_site]" value="true"'
173
+ . checked( TRUE, $settings['private_site'], FALSE ) . ' />';
174
+ }
175
+
176
+ /**
177
+ * Section text for Section2
178
+ *
179
+ * Display an explanation of this Section
180
+ *
181
+ */
182
+ function jr_ps_self_registration_expl() {
183
+ echo '
184
+ <p>
185
+ If you want Users to be able to Register themselves on a Private Site,
186
+ there are two Settings involved.
187
+ First
188
+ is the WordPress Setting that actually allows new Users to self-register.
189
+ It is shown here as a convenience,
190
+ but:
191
+ <ol>
192
+ <li>This is the same
193
+ ';
194
+ if ( is_multisite() ) {
195
+ echo '<b>Allow New Registrations</b> field displayed on the <b>Network Settings</b> Admin panel;</li>';
196
+ } else {
197
+ echo '<b>Membership</b> field displayed on the <b>General Settings</b> Admin panel;</li>';
198
+ }
199
+ if ( is_multisite() && !is_super_admin() ) {
200
+ echo '<li>The field is greyed out below because only Super Administrators can change this field.';
201
+ } else {
202
+ echo '<li>Clicking the Save Changes button will update its value.';
203
+ }
204
+ echo '
205
+ </li>
206
+ </ol>
207
+ </p>
208
+ <p>
209
+ Second, is a Setting
210
+ (Reveal User Registration Page)
211
+ for this plugin,
212
+ to make the WordPress Registration page visible to Visitors who are not logged on.
213
+ Since Users cannot log on until they are Registered,
214
+ this Setting must be selected (check mark) for Self-Registration.
215
+ </p>
216
+ ';
217
+ }
218
+
219
+ function jr_ps_echo_reveal_registration() {
220
+ $settings = get_option( 'jr_ps_settings' );
221
+ echo '<input type="checkbox" id="reveal_registration" name="jr_ps_settings[reveal_registration]" value="true"'
222
+ . checked( TRUE, $settings['reveal_registration'], FALSE ) . ' />';
223
+ }
224
+
225
+ function jr_ps_echo_registrations() {
226
+ $setting = get_site_option( 'registration' );
227
+ foreach ( array(
228
+ 'none' => 'Registration is disabled.',
229
+ 'user' => 'User accounts may be registered.',
230
+ 'blog' => 'Logged in users may register new sites.',
231
+ 'all' => 'Both sites and user accounts can be registered.'
232
+ ) as $value => $description ) {
233
+ echo '<input type="radio" id="registrations" name="jr_ps_settings[registrations]" '
234
+ . checked( $value, $setting, FALSE )
235
+ . ' value="' . $value . '" '
236
+ . disabled( is_super_admin(), FALSE, FALSE )
237
+ . ' /> ' . $description . '<br />';
238
+ }
239
+ }
240
+
241
+ function jr_ps_echo_membership() {
242
+ echo '<input type="checkbox" id="membership" name="jr_ps_settings[membership]" value="1"'
243
+ . checked( '1', get_option( 'users_can_register' ), FALSE ) . ' /> Anyone can register';
244
+ }
245
+
246
+ /**
247
+ * Section text for Section3
248
+ *
249
+ * Display an explanation of this Section
250
+ *
251
+ */
252
+ function jr_ps_landing_settings_expl() {
253
+ ?>
254
+ <p>
255
+ What do you want your visitors to see immediately after they login?
256
+ For most Private Sites, the default
257
+ <b>Return to same URL</b>
258
+ setting works best,
259
+ as it takes visitors to where they would have been had they already been logged on when they clicked a link or entered a URL,
260
+ just as if they hit the browser's Back button twice and then the Refresh button after logging in.
261
+ </p>
262
+ <p>
263
+ <b>Specific URL</b> only applies when <b>Go to specific URL</b> is selected.
264
+ </p>
265
+ <?php
266
+ }
267
+
268
+ function jr_ps_echo_landing() {
269
+ $settings = get_option( 'jr_ps_settings' );
270
+ $first = TRUE;
271
+ foreach ( array(
272
+ 'return' => 'Return to same URL',
273
+ 'home' => 'Go to Site Home',
274
+ 'admin' => 'Go to WordPress Admin Dashboard',
275
+ 'url' => 'Go to Specific URL'
276
+ ) as $val => $desc ) {
277
+ if ( $first ) {
278
+ $first = FALSE;
279
+ } else {
280
+ echo '<br />';
281
+ }
282
+ echo '<input type="radio" id="landing" name="jr_ps_settings[landing]" '
283
+ . checked( $val, $settings['landing'], FALSE )
284
+ . ' value="' . $val . '" /> ' . $desc;
285
+ }
286
+ }
287
+
288
+ function jr_ps_echo_specific_url() {
289
+ $settings = get_option( 'jr_ps_settings' );
290
+ echo '<input type="text" id="specific_url" name="jr_ps_settings[specific_url]" size="100" maxlength="256" value="';
291
+ echo esc_url( $settings['specific_url'] ) . '" />';
292
+ }
293
+
294
+ function jr_ps_validate_settings( $input ) {
295
+ $valid = array();
296
+ $settings = get_option( 'jr_ps_settings' );
297
+
298
+ if ( isset( $input['private_site'] ) && ( $input['private_site'] === 'true' ) ) {
299
+ $valid['private_site'] = TRUE;
300
+ } else {
301
+ $valid['private_site'] = FALSE;
302
+ }
303
+
304
+ if ( isset( $input['reveal_registration'] ) && ( $input['reveal_registration'] === 'true' ) ) {
305
+ $valid['reveal_registration'] = TRUE;
306
+ } else {
307
+ $valid['reveal_registration'] = FALSE;
308
+ }
309
+
310
+ $valid['landing'] = $input['landing'];
311
+
312
+ if ( trim( $input['specific_url'] ) ) {
313
+ if ( jr_ps_site_url( $input['specific_url'] ) ) {
314
+ /* If URL is input without http:// or https://, then add it based on the Site URL.
315
+ */
316
+ $parse_url = parse_url( $input['specific_url'] );
317
+ if ( isset( $parse_url['scheme'] ) && in_array( strtolower( $parse_url['scheme'] ), array( 'http', 'https' ) ) ) {
318
+ $url = $input['specific_url'];
319
+ } else {
320
+ $parse_url = parse_url( get_home_url() );
321
+ $url = $parse_url['scheme'] . '://' . $input['specific_url'];
322
+ }
323
+ $valid['specific_url'] = esc_url_raw( $url, array( 'http', 'https' ) );
324
+ } else {
325
+ /* Reset to previous URL value and generate an error message.
326
+ */
327
+ $valid['specific_url'] = $settings['specific_url'];
328
+ add_settings_error(
329
+ 'jr_ps_settings',
330
+ 'jr_ps_urlerror',
331
+ 'Error in URL. It must point to someplace on this WordPress web site<br /><code>'
332
+ . sanitize_text_field( $input['specific_url'] ) . '</code>',
333
+ 'error'
334
+ );
335
+ }
336
+ } else {
337
+ $valid['specific_url'] = '';
338
+ if ( 'url' === $input['landing'] ) {
339
+ add_settings_error(
340
+ 'jr_ps_settings',
341
+ 'jr_ps_nourlerror',
342
+ 'Error in Landing Location: <i>Go to Specific URL</i> selected but no URL specified.',
343
+ 'error'
344
+ );
345
+ }
346
+ }
347
+
348
+ if ( is_multisite() ) {
349
+ if ( is_super_admin() ) {
350
+ if ( isset( $input['registrations'] ) ) {
351
+ update_site_option( 'registration', $input['registrations'] );
352
+ }
353
+ }
354
+ } else {
355
+ if ( isset( $input['membership'] ) ) {
356
+ $mem = $input['membership'];
357
+ } else {
358
+ $mem = '0';
359
+ }
360
+ update_option( 'users_can_register', $mem );
361
+ }
362
+
363
+ return $valid;
364
+ }
365
+
366
+ ?>
includes/all-admin.php ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ Loaded for all Admin panels.
4
+ */
5
+
6
+ // Exit if .php file accessed directly
7
+ if ( !defined( 'ABSPATH' ) ) exit;
8
+
9
+ $internal_settings = get_option( 'jr_ps_internal_settings' );
10
+ if ( isset( $internal_settings['warning_privacy'] ) ) {
11
+ add_action( 'all_admin_notices', 'jr_ps_warning_privacy' );
12
+ /**
13
+ * Warn that Private Site is turned OFF by default
14
+ *
15
+ * Put Warning on top of every Admin page (visible to Admins only)
16
+ * until Admin visits plugin's Settings page.
17
+ *
18
+ */
19
+ function jr_ps_warning_privacy() {
20
+ global $jr_ps_plugin_data;
21
+ if ( current_user_can( 'manage_options' ) ) {
22
+ echo '<div class="updated"><p><b>Private Site is currently turned off on ' . $jr_ps_plugin_data['Name'] . ' plugin <a href="'
23
+ . admin_url( 'options-general.php?page=jr_ps_settings' )
24
+ . '">Settings page</a>.</b></p></div>';
25
+ }
26
+ }
27
+ }
28
+
29
+ ?>
includes/functions-admin.php ADDED
@@ -0,0 +1,49 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Is the URL on the current WordPress web site?
5
+ *
6
+ * Checks if URL begins with Site Home URL.
7
+ * Strip http[s]://[www.] and leading and trailing blanks and convert to lower-case before comparing,
8
+ * to allow http, etc. to be omitted on entry
9
+ *
10
+ * @param string $url URL to be checked to be sure it is "on" the current WordPress web site
11
+ * @return bool bool TRUE if URL is on current WordPress web site; FALSE otherwise
12
+ */
13
+ function jr_ps_site_url( $url ) {
14
+ $site_home = jr_ps_urlcompare_prep( get_home_url() );
15
+ return ( substr( jr_ps_urlcompare_prep( $url ), 0, strlen( $site_home ) ) === $site_home );
16
+ }
17
+
18
+ /**
19
+ * Prepare a URL for comparison with another URL
20
+ *
21
+ * Strip [http[s]://][www.] and leading and trailing blanks, and convert to lower-case,
22
+ * to:
23
+ * (1) permit comparison of "synonym" URLs; and
24
+ * (2) allow http to be omitted when inputting a URL
25
+ *
26
+ * @param string $url URL to be prepped for comparison
27
+ * @return string URL prepped for comparison
28
+ */
29
+ function jr_ps_urlcompare_prep( $url ) {
30
+ $prep_url = strtolower( trim( $url ) );
31
+ if ( 'http' === substr( $prep_url, 0, 4 ) ) {
32
+ if ( 's' === substr( $prep_url, 4, 1 ) ) {
33
+ $cursor = 5; // Next character to look at in URL
34
+ } else {
35
+ $cursor = 4;
36
+ }
37
+ if ( '://' === substr( $prep_url, $cursor, 3 ) ) {
38
+ $cursor = $cursor + 3;
39
+ }
40
+ } else {
41
+ $cursor = 0;
42
+ }
43
+ if ( 'www.' === substr( $prep_url, $cursor, 4 ) ) {
44
+ $cursor = $cursor + 4;
45
+ }
46
+ return substr( $prep_url, $cursor );
47
+ }
48
+
49
+ ?>
includes/index.html ADDED
File without changes
includes/installed-plugins.php ADDED
@@ -0,0 +1,91 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ Initiated when in the Admin panels.
4
+ Used to handle the plugin's entry on the Install Plugins page.
5
+ */
6
+
7
+ /* Support WordPress Version 3.0.x before is_network_admin() existed
8
+ */
9
+ if ( function_exists( 'is_network_admin' ) && is_network_admin() ) {
10
+ // Add Link to the plugin's entry on the Network Admin "Plugins" Page, for easy access
11
+ add_filter( 'network_admin_plugin_action_links_' . jr_ps_plugin_basename(), 'jr_ps_plugin_network_action_links', 10, 1 );
12
+
13
+ /**
14
+ * Creates Settings link right on the Network Plugins Page entry.
15
+ *
16
+ * Helps the user understand where to go immediately upon Activation of the Plugin
17
+ * by creating entries on the Plugins page, right beside Deactivate and Edit.
18
+ *
19
+ * @param array $links Existing links for our Plugin, supplied by WordPress
20
+ * @param string $file Name of Plugin currently being processed
21
+ * @return string $links Updated set of links for our Plugin
22
+ */
23
+ function jr_ps_plugin_network_action_links( $links ) {
24
+ // The "page=" query string value must be equal to the slug
25
+ // of the Settings admin page.
26
+ array_push( $links, '<a href="' . get_bloginfo('wpurl') . '/wp-admin/network/settings.php?page=jr_ps_network_settings' . '">Settings</a>' );
27
+ return $links;
28
+ }
29
+ } else {
30
+ // Add Link to the plugin's entry on the Admin "Plugins" Page, for easy access
31
+ add_filter( 'plugin_action_links_' . jr_ps_plugin_basename(), 'jr_ps_plugin_action_links', 10, 1 );
32
+
33
+ if ( function_exists( 'is_plugin_active_for_network' ) && is_plugin_active_for_network( jr_ps_plugin_basename() ) ) {
34
+ // Add entry for the plugin on the each site's Admin "Plugins" Page, when Network Activated and not normally shown
35
+ add_action( 'pre_current_active_plugins', 'jr_ps_show_plugin' );
36
+
37
+ function jr_ps_show_plugin() {
38
+ global $wp_list_table;
39
+ global $jr_ps_path;
40
+ $wp_list_table->items[jr_ps_plugin_basename()] = get_plugin_data( $jr_ps_path . basename( jr_ps_plugin_basename() ) );
41
+ uasort( $wp_list_table->items, 'jr_ps_sort_plugins' );
42
+ return;
43
+ }
44
+
45
+ function jr_ps_sort_plugins( $a, $b ) {
46
+ return strcasecmp( $a['Name'], $b['Name'] );
47
+ }
48
+
49
+ /**
50
+ * Creates Settings entry right on the Plugins Page entry.
51
+ *
52
+ * Helps the user understand where to go immediately upon Activation of the Plugin
53
+ * by creating entries on the Plugins page, right beside Deactivate and Edit.
54
+ *
55
+ * @param array $links Existing links for our Plugin, supplied by WordPress
56
+ * @param string $file Name of Plugin currently being processed
57
+ * @return string $links Updated set of links for our Plugin
58
+ */
59
+ function jr_ps_plugin_action_links( $links ) {
60
+ /* Delete existing Links and replace with "Network Activated" (not a link)
61
+ and "Settings" as a link to Plugin Settings page.
62
+ The "page=" query string value must be equal to the slug
63
+ of the Settings admin page.
64
+ */
65
+ return array( 'Network Activated',
66
+ '<a href="' . get_bloginfo('wpurl') . '/wp-admin/admin.php?page=jr_ps_settings' . '">Settings</a>'
67
+ );
68
+ }
69
+ } else {
70
+ /**
71
+ * Creates Settings entry right on the Plugins Page entry.
72
+ *
73
+ * Helps the user understand where to go immediately upon Activation of the Plugin
74
+ * by creating entries on the Plugins page, right beside Deactivate and Edit.
75
+ *
76
+ * @param array $links Existing links for our Plugin, supplied by WordPress
77
+ * @param string $file Name of Plugin currently being processed
78
+ * @return string $links Updated set of links for our Plugin
79
+ */
80
+ function jr_ps_plugin_action_links( $links ) {
81
+ /* Add "Settings" to the end of existing Links
82
+ The "page=" query string value must be equal to the slug
83
+ of the Settings admin page.
84
+ */
85
+ array_push( $links, '<a href="' . get_bloginfo('wpurl') . '/wp-admin/admin.php?page=jr_ps_settings' . '">Settings</a>' );
86
+ return $links;
87
+ }
88
+ }
89
+ }
90
+
91
+ ?>
includes/net-settings.php ADDED
@@ -0,0 +1,61 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ Initiated when in the Network Admin panels.
4
+ Used to create the Settings page for the plugin.
5
+ */
6
+
7
+ add_action( 'network_admin_menu', 'jr_ps_network_admin_hook' );
8
+ // Runs just after admin_init
9
+
10
+ /**
11
+ * Add Network Admin Menu item for plugin
12
+ *
13
+ * Plugin needs its own Page in the Settings section of the Network Admin menu.
14
+ *
15
+ */
16
+ function jr_ps_network_admin_hook() {
17
+ // Add Network Settings Page for this Plugin
18
+ global $jr_ps_plugin_data;
19
+ add_submenu_page( 'settings.php', $jr_ps_plugin_data['Name'], 'Private Sites', 'manage_network_options', 'jr_ps_network_settings', 'jr_ps_network_settings_page' );
20
+ }
21
+
22
+ /**
23
+ * Network Settings page for plugin
24
+ *
25
+ * Display and Process Settings page for this plugin.
26
+ *
27
+ */
28
+ function jr_ps_network_settings_page() {
29
+ global $jr_ps_plugin_data;
30
+ add_thickbox();
31
+ echo '<div class="wrap">';
32
+ screen_icon( 'plugins' );
33
+ echo '<h2>' . $jr_ps_plugin_data['Name'] . '</h2>';
34
+ ?>
35
+ <p>
36
+ This Plugin has been <b>Network Activated</b> in a WordPress Multisite ("Network") installation.
37
+ Since all of this plugin's Settings can be specified separately for each individual WordPress site,
38
+ you will need to go to the Admin pages for each Site,
39
+ and review the plugin's Settings page,
40
+ making changes appropriate for that Site.
41
+ The plugin's Settings page can be found by opening the <b>Settings</b> submenu on the left sidebar of each Admin page for the Site
42
+ and selecting <b>Private Site</b>.
43
+ Or from the <b>Settings</b> link in the plugin's entry on the <b>Installed Plugins</b> page for the Site
44
+ <i>(WordPress does not list Network Activated plugins on each Site's Installed Plugins page,
45
+ but this plugin has added its own entry for your convenience)</i>.
46
+ </p>
47
+ <p>
48
+ Alternatively, you can <b>Network Deactivate</b> this plugin
49
+ and <b>Activate</b> it individually on each Site where you wish to use it.
50
+ </p>
51
+ <p>
52
+ If you would prefer, when this plugin is Network Activated,
53
+ to have a single set of Settings that would apply to all Sites in a WordPress network,
54
+ and/or be able to view and change all of the Settings for all Sites from this one Network Settings page that you are now viewing,
55
+ <a href="http://zatzlabs.com/contact-us/">please contact the Plugin author</a>
56
+ and this will be added to a future version of this plugin if there is enough interest expressed by webmasters such as you.
57
+ </p>
58
+ <?php
59
+ }
60
+
61
+ ?>
includes/public.php ADDED
@@ -0,0 +1,65 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ Initiated when on the "public" web site,
4
+ i.e. - not an Admin panel.
5
+ */
6
+
7
+ // Exit if .php file accessed directly
8
+ if ( !defined( 'ABSPATH' ) ) exit;
9
+
10
+ add_action( 'login_init', 'jr_ps_login' );
11
+ add_action( 'wp', 'jr_ps_force_login' );
12
+
13
+ /**
14
+ * Login Detection
15
+ *
16
+ * Set a global variable, $jr_ps_is_login, whenever a login occurs
17
+ *
18
+ * @return NULL Nothing is returned
19
+ */
20
+ function jr_ps_login() {
21
+ global $jr_ps_is_login;
22
+ $jr_ps_is_login = TRUE;
23
+ }
24
+
25
+ /**
26
+ * Present a login screen to anyone not logged in
27
+ *
28
+ * Check for already logged in or just logged in.
29
+ * Only called when is_admin() is FALSE
30
+ *
31
+ * @return NULL Nothing is returned
32
+ */
33
+ function jr_ps_force_login() {
34
+ global $jr_ps_is_login;
35
+ if ( !is_user_logged_in() && !isset( $jr_ps_is_login ) ) {
36
+ $settings = get_option( 'jr_ps_settings' );
37
+ switch ( $settings['landing'] ) {
38
+ case 'return':
39
+ // $_SERVER['HTTPS'] can be off in IIS
40
+ if ( empty( $_SERVER['HTTPS'] ) || ( $_SERVER['HTTPS'] == 'off' ) ) {
41
+ $http = 'http://';
42
+ } else {
43
+ $http = 'https://';
44
+ }
45
+ $after_login_url = $http . $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI'];
46
+ break;
47
+ case 'home':
48
+ $after_login_url = get_home_url();
49
+ break;
50
+ case 'admin':
51
+ $after_login_url = get_admin_url();
52
+ break;
53
+ case 'url':
54
+ $after_login_url = trim( $settings['specific_url'] );
55
+ break;
56
+ }
57
+ // Avoid situations where specific URL is requested, but URL is blank
58
+ if ( !empty( $after_login_url ) ) {
59
+ wp_redirect( wp_login_url( $after_login_url ) );
60
+ exit;
61
+ }
62
+ }
63
+ }
64
+
65
+ ?>
index.html ADDED
File without changes
jonradio-private-site.php ADDED
@@ -0,0 +1,166 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ Plugin Name: jonradio Private Site
4
+ Plugin URI: http://zatzlabs.com/plugins/
5
+ Description: Creates a Private Site by allowing only those logged on to view the WordPress web site. Settings select the initial destination after login.
6
+ Version: 2.2
7
+ Author: David Gewirtz
8
+ Author URI: http://zatzlabs.com/plugins/
9
+ License: GPLv2
10
+ */
11
+
12
+ /* Copyright 2013 jonradio (email : info@zatz.com)
13
+
14
+ This program is free software; you can redistribute it and/or modify
15
+ it under the terms of the GNU General Public License as published by
16
+ the Free Software Foundation; either version 2 of the License, or
17
+ (at your option) any later version.
18
+
19
+ This program is distributed in the hope that it will be useful,
20
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
21
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22
+ GNU General Public License for more details.
23
+
24
+ You should have received a copy of the GNU General Public License
25
+ along with this program; if not, write to the Free Software
26
+ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
27
+ */
28
+
29
+ /* Exit if .php file accessed directly
30
+ */
31
+ if ( !defined( 'ABSPATH' ) ) exit;
32
+
33
+ global $jr_ps_path;
34
+ $jr_ps_path = plugin_dir_path( __FILE__ );
35
+ /**
36
+ * Return Plugin's full directory path with trailing slash
37
+ *
38
+ * Local XAMPP install might return:
39
+ * C:\xampp\htdocs\wpbeta\wp-content\plugins\jonradio-private-site/
40
+ *
41
+ */
42
+ function jr_ps_path() {
43
+ global $jr_ps_path;
44
+ return $jr_ps_path;
45
+ }
46
+
47
+ global $jr_ps_plugin_basename;
48
+ $jr_ps_plugin_basename = plugin_basename( __FILE__ );
49
+ /**
50
+ * Return Plugin's Basename
51
+ *
52
+ * For this plugin, it would be:
53
+ * jonradio-multiple-themes/jonradio-multiple-themes.php
54
+ *
55
+ */
56
+ function jr_ps_plugin_basename() {
57
+ global $jr_ps_plugin_basename;
58
+ return $jr_ps_plugin_basename;
59
+ }
60
+
61
+ if ( !function_exists( 'get_plugin_data' ) ) {
62
+ require_once( ABSPATH . 'wp-admin/includes/plugin.php' );
63
+ }
64
+
65
+ global $jr_ps_plugin_data;
66
+ $jr_ps_plugin_data = get_plugin_data( __FILE__ );
67
+ $jr_ps_plugin_data['slug'] = basename( dirname( __FILE__ ) );
68
+
69
+ /* Detect initial activation or a change in plugin's Version number
70
+
71
+ Sometimes special processing is required when the plugin is updated to a new version of the plugin.
72
+ Also used in place of standard activation and new site creation exits provided by WordPress.
73
+ Once that is complete, update the Version number in the plugin's Network-wide settings.
74
+ */
75
+
76
+ if ( ( FALSE === ( $internal_settings = get_option( 'jr_ps_internal_settings' ) ) )
77
+ || empty( $internal_settings['version'] ) )
78
+ {
79
+ /* Plugin is either:
80
+ - updated from a version so old that Version was not yet stored in the plugin's settings, or
81
+ - first use after install:
82
+ - first time ever installed, or
83
+ - installed previously and properly uninstalled (data deleted)
84
+ */
85
+
86
+ $old_version = '0.1';
87
+ } else {
88
+ $old_version = $internal_settings['version'];
89
+ }
90
+
91
+ $settings = get_option( 'jr_ps_settings' );
92
+ if ( empty( $settings ) ) {
93
+ $settings = array(
94
+ 'private_site' => FALSE,
95
+ 'reveal_registration' => FALSE,
96
+ 'landing' => 'return',
97
+ 'specific_url' => ''
98
+ );
99
+ /* Add if Settings don't exist, re-initialize if they were empty.
100
+ */
101
+ update_option( 'jr_ps_settings', $settings );
102
+ /* New install on this site, old version or corrupt settings
103
+ */
104
+ $old_version = $jr_ps_plugin_data['Version'];
105
+ }
106
+
107
+ if ( version_compare( $old_version, $jr_ps_plugin_data['Version'], '!=' ) ) {
108
+ /* Create, if internal settings do not exist; update if they do exist
109
+ */
110
+ $internal_settings['version'] = $jr_ps_plugin_data['Version'];
111
+ if ( version_compare( $old_version, '2', '<' ) ) {
112
+ /* Previous versions turned Privacy on at Activation;
113
+ Now it is a Setting on the Settings page,
114
+ so warn Admin.
115
+ */
116
+ $internal_settings['warning_privacy'] = TRUE;
117
+ }
118
+ update_option( 'jr_ps_internal_settings', $internal_settings );
119
+
120
+ /* Handle all Settings changes made in old plugin versions
121
+ */
122
+ if ( version_compare( $old_version, '2.1', '<' ) ) {
123
+ $settings['reveal_registration'] = FALSE;
124
+ }
125
+ update_option( 'jr_ps_settings', $settings );
126
+ }
127
+
128
+ if ( is_admin() ) {
129
+ require_once( jr_ps_path() . 'includes/all-admin.php' );
130
+ /* Support WordPress Version 3.0.x before is_network_admin() existed
131
+ */
132
+ if ( function_exists( 'is_network_admin' ) && is_network_admin() ) {
133
+ // Network Admin pages in Network/Multisite install
134
+ if ( function_exists( 'is_plugin_active_for_network' ) && is_plugin_active_for_network( jr_ps_plugin_basename() ) ) {
135
+ // Network Admin Settings page for Plugin
136
+ require_once( jr_ps_path() . 'includes/net-settings.php' );
137
+ }
138
+ } else {
139
+ // Regular (non-Network) Admin pages
140
+ // Settings page for Plugin
141
+ require_once( jr_ps_path() . 'includes/admin-settings.php' );
142
+ }
143
+ // All changes to all Admin-Installed Plugins pages
144
+ require_once( jr_ps_path() . 'includes/installed-plugins.php' );
145
+ } else {
146
+ // Public WordPress content, i.e. - not Admin pages
147
+ $reveal = FALSE;
148
+ if ( ( TRUE === $settings['private_site'] ) && ( TRUE === $settings['reveal_registration'] ) ) {
149
+ function jr_ps_match_register( $reg_url ) {
150
+ return ( 0 === strcasecmp( $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI'], substr( $reg_url, 3 + strpos( $reg_url, '://' ) ) ) );
151
+ }
152
+ if ( jr_ps_match_register( wp_registration_url() ) ) {
153
+ $reveal = TRUE;
154
+ } else {
155
+ if ( is_multisite() && jr_ps_match_register( get_site_url( 0, 'wp-signup.php' ) ) ) {
156
+ $reveal = TRUE;
157
+ }
158
+ }
159
+ }
160
+ if ( FALSE === $reveal ) {
161
+ // Private Site code
162
+ require_once( jr_ps_path() . 'includes/public.php' );
163
+ }
164
+ }
165
+
166
+ ?>
readme.txt ADDED
@@ -0,0 +1,77 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ === jonradio Private Site ===
2
+ Contributors: dgewirtz
3
+ Donate link: http://zatzlabs.com/plugins/
4
+ Tags: login, visibility, private, security, plugin, pages, page, posts, post
5
+ Requires at least: 3.0
6
+ Tested up to: 3.6
7
+ Stable tag: 2.2
8
+ License: GPLv2 or later
9
+ License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
+
11
+ Create a Private Site visible only to your registered users.
12
+
13
+ == Description ==
14
+
15
+ Allows the Administrator to restrict a WordPress-based web site to viewing only by registered users who are logged on.
16
+
17
+ Any attempt to view any Page, Post or other part of the site will see anyone not logged on greeted by a WordPress login screen. A Settings Page allows the Administrator to determine where Users will be automatically directed to each time that they login, a "Landing Location".
18
+
19
+ If you allow Self-Registration, where new Users can Register themselves, you will need to select the "Reveal User Registration Page" setting or new Users will be blocked from seeing the WordPress Registration screen. For convenience, the WordPress Setting that controls Self-Registration of Users has been added to the Plugin's Settings page. **Important Note**: At least WordPress Version 3.6.0 is required when the "Reveal User Registration Page" is set (check mark in the checkbox), but preliminary reports indicate that previous WordPress versions may allow Self-Registration without this checkbox selected.
20
+
21
+ Another Setting allows the Private Site feature to be turned off. When the plugin is installed and activated, the Private Site feature is set off by default, to allow the Administrator an opportunity to become familiarized with the plugin's features and to set the desired settings. A warning that the site is not private appears after first activation of the plugin until the Administrator visits the plugin's Settings page.
22
+
23
+ If a WordPress Network is defined, the plugin can be activated individually for select sites. Or Network Activated. In either case, each site will have its own Settings page where the Private Site feature can be turned off (default) or on for just the one site, and a Landing Location defined for each site.
24
+
25
+ Login prompts are provided whenever a non-logged in user ("site visitor") attempts to access any URL controlled by WordPress on the web site. This plugin does not control non-WordPress web pages, such as .html and .php files created by hand or by other software products. Or images and other media and text files directly accessed by their URL, or from a browser's directory view, if available.
26
+
27
+ Yes, there are other plugins that hide some or all WordPress content for any site visitor who is not logged on. But when I was searching for a solution for one of the web sites I support, I decided to "write my own" because I knew how it worked and felt comfortable that there would be no way for anyone not logged in to view the site, including Search Engines.
28
+
29
+ == Installation ==
30
+
31
+ This section describes how to install the *jonradio Private Site* plugin and get it working.
32
+
33
+ 1. Use **Add Plugin** within the WordPress Admin panel to download and install this *jonradio Private Site* plugin from the WordPress.org plugin repository (preferred method). Or download and unzip this plugin, then upload the `/jonradio-private-site/` directory to your WordPress web site's `/wp-content/plugins/` directory
34
+ 1. Activate the *jonradio Private Site* plugin through the **Installed Plugins** Admin panel in WordPress. If you have a WordPress Network ("Multisite"), you can either **Network Activate** this plugin, or Activate it individually on the sites where you wish to use it.
35
+ 1. Go to the plugin's Settings page to make the Site **Private**, and set where the user ends up after logging in: the **Landing Location**.
36
+ 1. If you allow Self-Registration, where new Users can set up their own User Name on your WordPress site or Network, you will want to select **Reveal User Registration Page** on the plugin's Settings page.
37
+
38
+ == Changelog ==
39
+
40
+ = 2.2 =
41
+ * Add the WordPress User Self-Registration field to the plugin's Settings page
42
+ * Add the Settings page to the User submenu of Admin panel, too
43
+
44
+ = 2.1 =
45
+ * Add a settings checkbox to reveal the Register page for User Self-Registration
46
+
47
+ = 2.0 =
48
+ * Add Settings page, specifying Landing Location and turning Private Site off and on
49
+ * Warning for new default of OFF for Private Site until Settings are first viewed
50
+ * Add Networking Settings information page
51
+ * Track plugin version number in internal settings
52
+ * Replace WordPress Activation/Deactivation hooks with Version checking code from jonradio Multiple Themes
53
+ * Add Plugin entry on individual sites when plugin is Network Activated, and Settings link on all Plugin entries
54
+
55
+ = 1.1 =
56
+ * Change Action Hook to 'wp' from 'wp_head' to avoid Modify Header errors when certain other plugins are present
57
+
58
+ = 1.0 =
59
+ * Add readme.txt and screenshots
60
+ * Add in-line documentation for php functions
61
+
62
+ == Upgrade Notice ==
63
+
64
+ = 2.2 =
65
+ Display WordPress Self-Registration field on plugin Settings page.
66
+
67
+ = 2.1 =
68
+ Allow User Self-Registration by "revealing" the Register page to those not logged in.
69
+
70
+ = 2.0 =
71
+ Create a Settings page that defines where the user ends up after logging in
72
+
73
+ = 1.1 =
74
+ Should eliminate Modify Header errors due to conflict with other plugins
75
+
76
+ = 1.0 =
77
+ Production version, updated to meet WordPress Repository standards
uninstall.php ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ // Ensure call comes from WordPress, not a hacker or anyone else trying direct access.
3
+ if ( !defined( 'WP_UNINSTALL_PLUGIN' ) )
4
+ exit ();
5
+
6
+
7
+ /* Remove any tables, options, and such created by this Plugin */
8
+ if ( function_exists('is_multisite') && is_multisite() ) {
9
+ global $wpdb, $site_id;
10
+ $blogs = $wpdb->get_results( "SELECT blog_id FROM {$wpdb->blogs} WHERE site_id = $site_id" );
11
+ foreach ($blogs as $blog_obj) {
12
+ delete_blog_option( $blog_obj->blog_id, 'jr_ps_settings' );
13
+ delete_blog_option( $blog_obj->blog_id, 'jr_ps_internal_settings' );
14
+ }
15
+ } else {
16
+ delete_option( 'jr_ps_settings' );
17
+ delete_option( 'jr_ps_internal_settings' );
18
+ }
19
+ ?>