My Private Site - Version 3.0.11

Version Description

  • Fixed a CMB2 type error that popped up from time to time (Thanks, Michael!)
Download this release

Release Info

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

Code changes from version 3.0.10 to 3.0.11

Files changed (3) hide show
  1. jonradio-private-site.php +1 -1
  2. readme.txt +5 -2
  3. util/utilities5.php +74 -71
jonradio-private-site.php CHANGED
@@ -3,7 +3,7 @@
3
  Plugin Name: My Private Site
4
  Plugin URI: http://zatzlabs.com/plugins/
5
  Description: Easily secure posts, pages, or your entire WordPress site by requiring visitors to login.
6
- Version: 3.0.10
7
  Author: David Gewirtz
8
  Author URI: http://zatzlabs.com/plugins/
9
  License: GPLv2
3
  Plugin Name: My Private Site
4
  Plugin URI: http://zatzlabs.com/plugins/
5
  Description: Easily secure posts, pages, or your entire WordPress site by requiring visitors to login.
6
+ Version: 3.0.11
7
  Author: David Gewirtz
8
  Author URI: http://zatzlabs.com/plugins/
9
  License: GPLv2
readme.txt CHANGED
@@ -3,8 +3,8 @@ Contributors: dgewirtz
3
  Donate link: http://zatzlabs.com/lab-notes/
4
  Tags: login, visibility, private, security, plugin, pages, page, posts, post
5
  Requires at least: 4.0
6
- Tested up to: 6.0
7
- Stable tag: 3.0.10
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
@@ -92,6 +92,9 @@ Whenever you change your WordPress Permalinks (Settings-Permalinks in Admin pane
92
 
93
  == Changelog ==
94
 
 
 
 
95
  = 3.0.10 =
96
  * Fixed a bunch of over-eager security checks
97
 
3
  Donate link: http://zatzlabs.com/lab-notes/
4
  Tags: login, visibility, private, security, plugin, pages, page, posts, post
5
  Requires at least: 4.0
6
+ Tested up to: 6.1
7
+ Stable tag: 3.0.11
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
92
 
93
  == Changelog ==
94
 
95
+ = 3.0.11 =
96
+ * Fixed a CMB2 type error that popped up from time to time (Thanks, Michael!)
97
+
98
  = 3.0.10 =
99
  * Fixed a bunch of over-eager security checks
100
 
util/utilities5.php CHANGED
@@ -14,9 +14,10 @@ function my_private_site_array_size( $array ) {
14
  $count = 0;
15
  if ( is_array( $array ) ) {
16
  foreach ( $array as $value ) {
17
- ++$count;
18
  }
19
  }
 
20
  return $count;
21
  }
22
 
@@ -24,12 +25,13 @@ function my_private_site_force_unset_array_by_index( $array, $index ) {
24
  $new_array = array();
25
  $size = my_private_site_array_size( $array );
26
  $count = 0;
27
- for ( $i = 0; $i < $size; ++$i ) {
28
  if ( $index != $i ) {
29
  $new_array[ $count ] = $array[ $i ];
30
- ++$count;
31
  }
32
  }
 
33
  return $new_array;
34
  }
35
 
@@ -45,35 +47,35 @@ function my_private_site_cmb_options_display_with_tabs( $cmb_options ) {
45
  $tabs = my_private_site_cmb_options_page_tabs( $cmb_options );
46
  // All we're doing here is making sure we're on the right page
47
  // phpcs:ignore WordPress.Security.NonceVerification
48
- if(isset($_GET['page'])) {
49
- $get_page = sanitize_text_field( $_GET['page']);
50
- } else {
51
- $get_page = '';
52
- }
53
 
54
  ?>
55
- <div class="wrap cmb2-options-page option-<?php echo esc_attr($cmb_options->option_key); ?>">
56
  <?php if ( get_admin_page_title() ) : ?>
57
- <h2><?php echo wp_kses_post( get_admin_page_title() ); ?></h2>
58
  <?php endif; ?>
59
- <h2 class="nav-tab-wrapper">
60
  <?php foreach ( $tabs as $option_key => $tab_title ) : ?>
61
- <a class="nav-tab
62
  <?php
63
- if ( $get_page != '' && $option_key === $get_page ) :
64
  ?>
65
  nav-tab-active<?php endif; ?>"
66
- href="<?php menu_page_url( $option_key ); ?>"><?php echo wp_kses_post( $tab_title ); ?></a>
67
  <?php endforeach; ?>
68
- </h2>
69
- <form class="cmb-form" action="<?php echo esc_url( admin_url( 'admin-post.php' ) ); ?>" method="POST"
70
- id="<?php echo esc_attr($cmb_options->cmb->cmb_id); ?>" enctype="multipart/form-data"
71
- encoding="multipart/form-data">
72
- <input type="hidden" name="action" value="<?php echo esc_attr( $cmb_options->option_key ); ?>">
73
  <?php $cmb_options->options_page_metabox(); ?>
74
  <?php submit_button( esc_attr( $cmb_options->cmb->prop( 'save_button' ) ), 'primary', 'submit-cmb' ); ?>
75
- </form>
76
- </div>
77
  <?php
78
  }
79
 
@@ -117,6 +119,7 @@ function my_private_site_display_cmb2_submit_button( $section_options, $button_o
117
  'name' => $button_options['button_text'],
118
  'id' => $button_options['button_id'],
119
  'button_options' => $button_options,
 
120
  'render_row_cb' => 'my_private_site_display_cmb2_submit_button_callback',
121
  )
122
  );
@@ -143,7 +146,7 @@ function my_private_site_display_cmb2_submit_button_callback( $field_args, $fiel
143
  // show error if option set
144
  $error_msg = my_private_site_get_cmb2_submit_button_error_message( $button_id );
145
  if ( $error_msg != '' ) {
146
- echo '<div id="' . esc_attr($button_id) . '" class="notice notice-error">';
147
  echo esc_attr( $error_msg );
148
  echo '</div>';
149
  }
@@ -151,7 +154,7 @@ function my_private_site_display_cmb2_submit_button_callback( $field_args, $fiel
151
  // show message if option set
152
  $button_msg = my_private_site_get_cmb2_submit_button_success_message( $button_id );
153
  if ( $button_msg != '' ) {
154
- echo '<div id="' . esc_attr($button_id) . '" class="notice notice-message">';
155
  echo esc_attr( $button_msg );
156
  echo '</div>';
157
  }
@@ -185,16 +188,16 @@ function my_private_site_display_cmb2_submit_button_callback( $field_args, $fiel
185
 
186
  // display the button
187
  ?>
188
- <div class="cmb-action-button-row">
189
- <p class="submit">
190
- <input type="hidden" id="<?php echo esc_attr( $nonce_name ); ?>"
191
- name="<?php echo esc_attr( $nonce_name ); ?>"
192
- value="<?php echo esc_attr( $nonce ); ?>"/>
193
- <input type="submit" name="<?php echo esc_attr( $button_id ); ?>"
194
- id="<?php echo esc_attr( $button_id ); ?>"
195
- class="button button-primary"
196
- value="<?php echo esc_attr( $button_text ); ?>"></p>
197
- </div>
198
  <?php
199
  }
200
 
@@ -211,11 +214,11 @@ function my_private_site_set_cmb2_submit_button_flag( $button_id, $what_to_set,
211
  // it will be easier to read on the form settings pages
212
  // All we're doing here is making sure we're on the right page
213
  // phpcs:ignore WordPress.Security.NonceVerification
214
- if(isset($_POST['action'])) {
215
- $page_stub = sanitize_text_field($_POST['action']);
216
- } else {
217
- $page_stub = '';
218
- }
219
 
220
  $button_to_set = $button_id . $what_to_set;
221
 
@@ -257,7 +260,7 @@ function my_private_site_get_cmb2_submit_button_message( $button_id, $what_to_ge
257
  // All we're doing here is making sure we're on the right page
258
  // phpcs:ignore WordPress.Security.NonceVerification
259
  if ( isset( $_GET['page'] ) ) {
260
- $page_stub = sanitize_text_field( $_GET['page']);
261
 
262
  $button_list_option_name = 'jr_ps_' . $page_stub . '_button_list';
263
  $button_list_option = get_option( $button_list_option_name );
@@ -309,7 +312,7 @@ function my_private_site_cmb2_row_callback_for_action_button( $field_args, $fiel
309
  $error_msg = get_option( $button_error_id );
310
  if ( $error_msg != false ) {
311
  if ( $error_msg != '' ) {
312
- echo '<div id="' . esc_attr($button_error_id) . '" class="notice notice-error">';
313
  echo esc_attr( $error_msg );
314
  echo '</div>';
315
  }
@@ -318,7 +321,7 @@ function my_private_site_cmb2_row_callback_for_action_button( $field_args, $fiel
318
  $button_msg = get_option( $button_msg_id );
319
  if ( $button_msg != false ) {
320
  if ( $button_msg != '' ) {
321
- echo '<div id="' . esc_attr( $button_msg_id) . '" class="notice notice-message">';
322
  echo esc_attr( $error_msg );
323
  echo '</div>';
324
  }
@@ -326,13 +329,13 @@ function my_private_site_cmb2_row_callback_for_action_button( $field_args, $fiel
326
 
327
  // display the button
328
  ?>
329
- <div class="cmb-action-button-row">
330
- <p class="submit">
331
- <input type="submit" name="<?php echo esc_attr( $button_id ); ?>"
332
- id="<?php echo esc_attr( $button_id ); ?>"
333
- class="button button-primary"
334
- value="<?php echo esc_attr( $button_name ); ?>"></p>
335
- </div>
336
  <?php
337
  }
338
 
@@ -356,11 +359,11 @@ function my_private_site_cmb2_row_callback_for_static_desc( $field_args, $field
356
 
357
  ?>
358
 
359
- <div class="cmb-static-desc-row" id="<?php echo esc_attr( $id ); ?>">
360
- <div class="cmb-td">
361
- <p class="cmb2-metabox-description"><?php echo esc_textarea( $desc); ?></p>
362
- </div>
363
- </div>
364
 
365
  <?php
366
  }
@@ -377,7 +380,7 @@ function my_private_site_process_add_settings_fields_with_options5(
377
  $section_id = $settings_array['section_id'];
378
  }
379
 
380
- for ( $i = 0; $i < count( $options_array ); ++$i ) {
381
  // read in stored options
382
  // by using this approach, we don't need to special-case for
383
  // fields and field types that don't save option data
@@ -402,9 +405,9 @@ function my_private_site_is_referred_by_page( $page ) {
402
  // this is the name of the admin page we're checking
403
  // good for seeing if self-referring, if user was redirected from the current page
404
  $referring_page = '';
405
- if(isset($_SERVER['HTTP_REFERER'])) {
406
- $referring_page = sanitize_text_field( $_SERVER['HTTP_REFERER']);
407
- }
408
  $parts_list = wp_parse_url( $referring_page );
409
 
410
  if ( isset( $parts_list['query'] ) ) {
@@ -422,18 +425,18 @@ function my_private_site_is_referred_by_page( $page ) {
422
  }
423
 
424
  function my_private_site_cpt_list_type() {
425
- if(isset($_SERVER['REQUEST_URI'])) {
426
- $request = sanitize_url( $_SERVER['REQUEST_URI']) ;
427
- $parts_list = wp_parse_url( $request );
428
- parse_str( $parts_list['query'], $query_parts );
429
- if ( isset( $query_parts['post_type'] ) ) {
430
- $post_type = strtolower( $query_parts['post_type'] );
431
-
432
- return $post_type;
433
- } else {
434
- return '';
435
- }
436
- } else {
437
- return '';
438
- }
439
  }
14
  $count = 0;
15
  if ( is_array( $array ) ) {
16
  foreach ( $array as $value ) {
17
+ ++ $count;
18
  }
19
  }
20
+
21
  return $count;
22
  }
23
 
25
  $new_array = array();
26
  $size = my_private_site_array_size( $array );
27
  $count = 0;
28
+ for ( $i = 0; $i < $size; ++ $i ) {
29
  if ( $index != $i ) {
30
  $new_array[ $count ] = $array[ $i ];
31
+ ++ $count;
32
  }
33
  }
34
+
35
  return $new_array;
36
  }
37
 
47
  $tabs = my_private_site_cmb_options_page_tabs( $cmb_options );
48
  // All we're doing here is making sure we're on the right page
49
  // phpcs:ignore WordPress.Security.NonceVerification
50
+ if ( isset( $_GET['page'] ) ) {
51
+ $get_page = sanitize_text_field( $_GET['page'] );
52
+ } else {
53
+ $get_page = '';
54
+ }
55
 
56
  ?>
57
+ <div class="wrap cmb2-options-page option-<?php echo esc_attr( $cmb_options->option_key ); ?>">
58
  <?php if ( get_admin_page_title() ) : ?>
59
+ <h2><?php echo wp_kses_post( get_admin_page_title() ); ?></h2>
60
  <?php endif; ?>
61
+ <h2 class="nav-tab-wrapper">
62
  <?php foreach ( $tabs as $option_key => $tab_title ) : ?>
63
+ <a class="nav-tab
64
  <?php
65
+ if ( $get_page != '' && $option_key === $get_page ) :
66
  ?>
67
  nav-tab-active<?php endif; ?>"
68
+ href="<?php menu_page_url( $option_key ); ?>"><?php echo wp_kses_post( $tab_title ); ?></a>
69
  <?php endforeach; ?>
70
+ </h2>
71
+ <form class="cmb-form" action="<?php echo esc_url( admin_url( 'admin-post.php' ) ); ?>" method="POST"
72
+ id="<?php echo esc_attr( $cmb_options->cmb->cmb_id ); ?>" enctype="multipart/form-data"
73
+ encoding="multipart/form-data">
74
+ <input type="hidden" name="action" value="<?php echo esc_attr( $cmb_options->option_key ); ?>">
75
  <?php $cmb_options->options_page_metabox(); ?>
76
  <?php submit_button( esc_attr( $cmb_options->cmb->prop( 'save_button' ) ), 'primary', 'submit-cmb' ); ?>
77
+ </form>
78
+ </div>
79
  <?php
80
  }
81
 
119
  'name' => $button_options['button_text'],
120
  'id' => $button_options['button_id'],
121
  'button_options' => $button_options,
122
+ 'type' => 'ignoreme',
123
  'render_row_cb' => 'my_private_site_display_cmb2_submit_button_callback',
124
  )
125
  );
146
  // show error if option set
147
  $error_msg = my_private_site_get_cmb2_submit_button_error_message( $button_id );
148
  if ( $error_msg != '' ) {
149
+ echo '<div id="' . esc_attr( $button_id ) . '" class="notice notice-error">';
150
  echo esc_attr( $error_msg );
151
  echo '</div>';
152
  }
154
  // show message if option set
155
  $button_msg = my_private_site_get_cmb2_submit_button_success_message( $button_id );
156
  if ( $button_msg != '' ) {
157
+ echo '<div id="' . esc_attr( $button_id ) . '" class="notice notice-message">';
158
  echo esc_attr( $button_msg );
159
  echo '</div>';
160
  }
188
 
189
  // display the button
190
  ?>
191
+ <div class="cmb-action-button-row">
192
+ <p class="submit">
193
+ <input type="hidden" id="<?php echo esc_attr( $nonce_name ); ?>"
194
+ name="<?php echo esc_attr( $nonce_name ); ?>"
195
+ value="<?php echo esc_attr( $nonce ); ?>"/>
196
+ <input type="submit" name="<?php echo esc_attr( $button_id ); ?>"
197
+ id="<?php echo esc_attr( $button_id ); ?>"
198
+ class="button button-primary"
199
+ value="<?php echo esc_attr( $button_text ); ?>"></p>
200
+ </div>
201
  <?php
202
  }
203
 
214
  // it will be easier to read on the form settings pages
215
  // All we're doing here is making sure we're on the right page
216
  // phpcs:ignore WordPress.Security.NonceVerification
217
+ if ( isset( $_POST['action'] ) ) {
218
+ $page_stub = sanitize_text_field( $_POST['action'] );
219
+ } else {
220
+ $page_stub = '';
221
+ }
222
 
223
  $button_to_set = $button_id . $what_to_set;
224
 
260
  // All we're doing here is making sure we're on the right page
261
  // phpcs:ignore WordPress.Security.NonceVerification
262
  if ( isset( $_GET['page'] ) ) {
263
+ $page_stub = sanitize_text_field( $_GET['page'] );
264
 
265
  $button_list_option_name = 'jr_ps_' . $page_stub . '_button_list';
266
  $button_list_option = get_option( $button_list_option_name );
312
  $error_msg = get_option( $button_error_id );
313
  if ( $error_msg != false ) {
314
  if ( $error_msg != '' ) {
315
+ echo '<div id="' . esc_attr( $button_error_id ) . '" class="notice notice-error">';
316
  echo esc_attr( $error_msg );
317
  echo '</div>';
318
  }
321
  $button_msg = get_option( $button_msg_id );
322
  if ( $button_msg != false ) {
323
  if ( $button_msg != '' ) {
324
+ echo '<div id="' . esc_attr( $button_msg_id ) . '" class="notice notice-message">';
325
  echo esc_attr( $error_msg );
326
  echo '</div>';
327
  }
329
 
330
  // display the button
331
  ?>
332
+ <div class="cmb-action-button-row">
333
+ <p class="submit">
334
+ <input type="submit" name="<?php echo esc_attr( $button_id ); ?>"
335
+ id="<?php echo esc_attr( $button_id ); ?>"
336
+ class="button button-primary"
337
+ value="<?php echo esc_attr( $button_name ); ?>"></p>
338
+ </div>
339
  <?php
340
  }
341
 
359
 
360
  ?>
361
 
362
+ <div class="cmb-static-desc-row" id="<?php echo esc_attr( $id ); ?>">
363
+ <div class="cmb-td">
364
+ <p class="cmb2-metabox-description"><?php echo esc_textarea( $desc ); ?></p>
365
+ </div>
366
+ </div>
367
 
368
  <?php
369
  }
380
  $section_id = $settings_array['section_id'];
381
  }
382
 
383
+ for ( $i = 0; $i < count( $options_array ); ++ $i ) {
384
  // read in stored options
385
  // by using this approach, we don't need to special-case for
386
  // fields and field types that don't save option data
405
  // this is the name of the admin page we're checking
406
  // good for seeing if self-referring, if user was redirected from the current page
407
  $referring_page = '';
408
+ if ( isset( $_SERVER['HTTP_REFERER'] ) ) {
409
+ $referring_page = sanitize_text_field( $_SERVER['HTTP_REFERER'] );
410
+ }
411
  $parts_list = wp_parse_url( $referring_page );
412
 
413
  if ( isset( $parts_list['query'] ) ) {
425
  }
426
 
427
  function my_private_site_cpt_list_type() {
428
+ if ( isset( $_SERVER['REQUEST_URI'] ) ) {
429
+ $request = sanitize_url( $_SERVER['REQUEST_URI'] );
430
+ $parts_list = wp_parse_url( $request );
431
+ parse_str( $parts_list['query'], $query_parts );
432
+ if ( isset( $query_parts['post_type'] ) ) {
433
+ $post_type = strtolower( $query_parts['post_type'] );
434
+
435
+ return $post_type;
436
+ } else {
437
+ return '';
438
+ }
439
+ } else {
440
+ return '';
441
+ }
442
  }