PluginProbe
Password Protected — Lock Entire Site, Pages, Posts, Categories, and Partial Content / 2.6
Password Protected — Lock Entire Site, Pages, Posts, Categories, and Partial Content v2.6
2.8.4 2.8.3 2.8.2 2.8.1 trunk 1.0 1.1 1.2 1.2.1 1.2.2 1.3 1.4 1.5 1.6 1.6.1 1.6.2 1.7 1.7.1 1.7.2 1.8 1.9 2.0 2.0.1 2.0.2 2.0.3 All 63 releases
password-protected / admin / admin.php

admin.php in Password Protected — Lock Entire Site, Pages, Posts, Categories, and Partial Content 2.6, at admin/admin.php

764 lines 27.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 class Password_Protected_Admin {
4
5 var $settings_page_id;
6 var $options_group = 'password-protected';
7 var $setting_tabs = array();
8
9 /**
10 * Constructor
11 */
12 public function __construct() {
13 global $wp_version;
14 add_action( 'admin_init', array( $this, 'password_protected_register_setting_tabs' ) );
15 add_action( 'admin_init', array( $this, 'password_protected_settings' ), 5 );
16 add_action( 'admin_init', array( $this, 'add_privacy_policy' ) );
17 add_action( 'admin_menu', array( $this, 'admin_menu' ) );
18 add_action( 'password_protected_help_tabs', array( $this, 'help_tabs' ), 5 );
19 add_action( 'admin_notices', array( $this, 'password_protected_admin_notices' ) );
20 add_filter( 'plugin_row_meta', array( $this, 'plugin_row_meta' ), 10, 4 );
21 add_filter( 'plugin_action_links_password-protected/password-protected.php', array( $this, 'plugin_action_links' ) );
22 add_filter( 'pre_update_option_password_protected_password', array( $this, 'pre_update_option_password_protected_password' ), 10, 2 );
23 add_action( 'admin_enqueue_scripts', array( $this, 'admin_enqueue_scripts' ) );
24 }
25
26 /**
27 * Password protected setting tabs
28 * customizable using filter hook
29 */
30 public function password_protected_register_setting_tabs() {
31 $this->setting_tabs = array(
32 'general' => 'General',
33 'advanced' => 'Advanced',
34 'help' => 'Help',
35 'getpro' => 'Get Pro'
36 );
37 if( $this->password_protected_pro_is_installed_and_activated() )
38 unset( $this->setting_tabs['getpro'] );
39
40 $this->setting_tabs = apply_filters( 'password_protected_setting_tabs', $this->setting_tabs );
41 }
42
43 /**
44 * Admin enqueue scripts.
45 *
46 * @param string $hooks Page Hook.
47 */
48 public function admin_enqueue_scripts( $hooks ) {
49
50 if ( 'settings_page_password-protected' === $hooks || 'toplevel_page_password-protected' === $hooks ) {
51 wp_enqueue_style( 'password-protected-page-script', PASSWORD_PROTECTED_URL . 'assets/css/admin.css', array(), '2.6.0' );
52 wp_enqueue_script( 'password-protected-admin-script', PASSWORD_PROTECTED_URL . 'assets/js/admin.js', array('jquery'), '2.6.0' );
53 }
54 }
55
56 /**
57 * Add Privacy Policy
58 */
59 public function add_privacy_policy() {
60
61 if ( ! function_exists( 'wp_add_privacy_policy_content' ) ) {
62 return 1;
63 }
64
65 $content = _x( 'The Password Protected plugin stores a cookie on successful password login containing a hashed version of the entered password. It does not store any information about the user. The cookie stored is named <code>bid_n_password_protected_auth</code> where <code>n</code> is the blog ID in a multisite network', 'privacy policy content', 'password-protected' );
66
67 wp_add_privacy_policy_content( __( 'Password Protected Plugin', 'password-protected' ), wp_kses_post( wpautop( $content, false ) ) );
68
69 }
70
71 /**
72 * Admin Menu
73 */
74 public function admin_menu() {
75
76 $capability = apply_filters( 'password_protected_options_page_capability', 'manage_options' );
77 $this->settings_page_id = add_options_page( __( 'Password Protected', 'password-protected' ), __( 'Password Protected', 'password-protected' ), $capability, 'password-protected', array( $this, 'settings_page' ) );
78 add_menu_page(
79 'Password Protected',
80 'Password Protected',
81 'manage_options',
82 'password-protected',
83 array( $this, 'pp_admin_menu_page_callback' ),
84 'dashicons-lock',
85 99
86 );
87 add_action( 'load-' . $this->settings_page_id, array( $this, 'add_help_tabs' ), 20 );
88
89 }
90
91 /**
92 * Settings Page
93 */
94 public function settings_page() {
95 ?>
96
97 <div class="wrap">
98 <div id="icon-options-general" class="icon32"><br /></div>
99 <h2><?php _e( 'Password Protected Settings', 'password-protected' ) ?></h2>
100 <form method="post" action="options.php">
101 <?php
102 settings_fields( 'password-protected' );
103 do_settings_sections( 'password-protected' );
104 ?>
105 <p class="submit"><input type="submit" name="submit" id="submit" class="button button-primary" value="<?php _e( 'Save Changes' ) ?>"></p>
106 </form>
107 <?php do_settings_sections( 'password-protected-login-designer' ); ?>
108
109 <div id="help-notice">
110 <?php do_settings_sections( 'password-protected-compat' ); ?>
111 </div>
112 </div>
113
114 <?php
115 }
116
117 /** @since 2.6
118 * Admin Menu Settings Page
119 */
120 public function pp_admin_menu_page_callback() {
121 $tab = ( isset( $_GET['tab'] ) AND sanitize_text_field( $_GET['page'] ) == 'password-protected' ) ? sanitize_text_field( $_GET['tab'] ) : 'general';
122 ?>
123 <div class="wrap">
124 <div class="wrap-row">
125 <div class="wrap-col-70">
126 <h2 class="nav-tab-wrapper">
127 <?php foreach( $this->setting_tabs as $index => $setting_tab ) : ?>
128 <a href="?page=password-protected&tab=<?php echo $index; ?>" class="nav-tab <?php echo esc_attr( $index ); ?> <?php echo ( $tab == $index ) ? 'nav-tab-active' : '' ?> ">
129 <?php echo sprintf(__('%s', 'password-protected'), $setting_tab); ?>
130 </a>
131 <?php endforeach; ?>
132 </h2>
133 <?php
134 settings_fields( 'password-protected' );
135 ?>
136 <?php settings_errors(); ?>
137 <?php $this->password_protected_render_tab_content( $tab ); ?>
138 </div>
139 <div id="pp-sidebar" class="wrap-col-25">
140 <?php
141 do_settings_sections( 'password-protected-login-designer' );
142 do_settings_sections( 'password-protected-try-pro' );
143 do_action('password_protected_sidebar');
144 ?>
145 </div>
146 </div>
147 </div>
148 <?php
149 }
150
151 /**
152 * password protected render settings page in menu
153 */
154 public function password_protected_render_tab_content( $tab ) {
155 switch( $tab ) {
156 case 'general':
157 do_settings_sections( 'password-protected-help' );
158 echo '<form method="post" action="options.php">';
159 settings_fields( 'password-protected' );
160 do_settings_sections( 'password-protected' );
161 submit_button();
162 echo '</form>';
163 break;
164
165 case 'advanced':
166 echo '<form method="post" action="options.php">';
167 settings_fields( 'password-protected-advanced' );
168 do_action( 'password_protected_advanced_tab_content' );
169 do_settings_fields( 'password-protected&tab=advanced', 'password-protected-advanced' );
170 do_settings_sections( 'password-protected-advanced-tab' );
171 Password_Protected_reCAPTCHA::recpatcha_screen();
172 echo '</form>';
173 break;
174
175 case 'help':
176 ?>
177 <div id="help-notice">
178 <?php do_settings_sections( 'password-protected-compat' ); ?>
179 </div>
180 <?php
181 break;
182
183 case 'getpro':
184 $this->password_protected_get_pro_features();
185 break;
186
187 case $tab;
188 do_action( 'password_protected_tab_'.$tab.'_content' );
189 break;
190
191 default:
192 echo "Something went wrong! Please contact support.";
193 break;
194 }
195 }
196
197 /**
198 * Add Help Tabs
199 */
200 public function add_help_tabs() {
201
202 global $wp_version;
203
204 if ( version_compare( $wp_version, '3.3', '<' ) ) {
205 return 1;
206 }
207
208 do_action( 'password_protected_help_tabs', get_current_screen() );
209
210 }
211
212 /**
213 * Help Tabs
214 *
215 * @param object $current_screen Screen object.
216 */
217 public function help_tabs( $current_screen ) {
218
219 $current_screen->add_help_tab( array(
220 'id' => 'PASSWORD_PROTECTED_SETTINGS',
221 'title' => __( 'Password Protected', 'password-protected' ),
222 'content' => __( '<p><strong>Password Protected Status</strong><br />Turn on/off password protection.</p>', 'password-protected' )
223 . __( '<p><strong>Protected Permissions</strong><br />Allow access for logged in users and administrators without needing to enter a password. You will need to enable this option if you want administrators to be able to preview the site in the Theme Customizer. Also allow RSS Feeds to be accessed when the site is password protected.</p>', 'password-protected' )
224 . __( '<p><strong>Password Fields</strong><br />To set a new password, enter it into both fields. You cannot set an `empty` password. To disable password protection uncheck the Enabled checkbox.</p>', 'password-protected' )
225 ) );
226
227 }
228
229 /**
230 * Settings API
231 */
232 public function password_protected_settings() {
233 // general tab
234 add_settings_section(
235 'password_protected',
236 '',
237 array( $this, 'password_protected_settings_section' ),
238 $this->options_group
239 );
240
241 add_settings_field(
242 'password_protected_status',
243 __( 'Password Protected Status', 'password-protected' ),
244 array( $this, 'password_protected_status_field' ),
245 $this->options_group,
246 'password_protected'
247 );
248
249 add_settings_field(
250 'password_protected_permissions',
251 __( 'Protected Permissions', 'password-protected' ),
252 array( $this, 'password_protected_permissions_field' ),
253 $this->options_group,
254 'password_protected'
255 );
256
257 add_settings_field(
258 'password_protected_password',
259 __( 'New Password', 'password-protected' ),
260 array( $this, 'password_protected_password_field' ),
261 $this->options_group,
262 'password_protected'
263 );
264
265 add_settings_field(
266 'password_protected_allowed_ip_addresses',
267 __( 'Allow IP Addresses', 'password-protected' ),
268 array( $this, 'password_protected_allowed_ip_addresses_field' ),
269 $this->options_group,
270 'password_protected'
271 );
272
273 add_settings_field(
274 'password_protected_remember_me',
275 __( 'Allow Remember me', 'password-protected' ),
276 array( $this, 'password_protected_remember_me_field' ),
277 $this->options_group,
278 'password_protected'
279 );
280
281 add_settings_field(
282 'password_protected_remember_me_lifetime',
283 __( 'Remember for this many days', 'password-protected' ),
284 array( $this, 'password_protected_remember_me_lifetime_field' ),
285 $this->options_group,
286 'password_protected'
287 );
288
289 // password protected advanced tab
290 add_settings_section(
291 'password-protected-advanced-tab',
292 'Password Protected Page description',
293 array( $this, 'password_protected_page_description' ),
294 'password-protected&tab=advanced'
295 );
296
297 add_settings_field(
298 'text-above-password',
299 __( 'Text Above Password Field', 'password-protected' ),
300 array( $this, 'password_protected_text_above_password' ),
301 'password-protected&tab=advanced',
302 'password-protected-advanced-tab'
303 );
304
305 add_settings_field(
306 'text-below-password',
307 __( 'Text Below Password Field ', 'password-protected' ),
308 array( $this, 'password_protected_text_below_password' ),
309 'password-protected&tab=advanced',
310 'password-protected-advanced-tab'
311 );
312
313 // password protected help tab
314 add_settings_section(
315 'password-protected-help',
316 '',
317 array( $this, 'password_protected_help_tab' ),
318 'password-protected-help'
319 );
320
321 // sidebar login designer compatibity
322 if( !$this->login_designer_is_installed_and_activated() ) {
323 add_settings_section(
324 'password-protected-login-designer',
325 '',
326 array( $this, 'login_designer_message' ),
327 'password-protected-login-designer'
328 );
329 }
330
331 if( !$this->password_protected_pro_is_installed_and_activated() ) {
332 add_settings_section(
333 'password-protected-try-pro',
334 '',
335 array( $this, 'password_protected_try_pro' ),
336 'password-protected-try-pro'
337 );
338 }
339
340 // registering settings
341 register_setting( $this->options_group, 'password_protected_status', 'intval' );
342 register_setting( $this->options_group, 'password_protected_feeds', 'intval' );
343 register_setting( $this->options_group, 'password_protected_rest', 'intval' );
344 register_setting( $this->options_group, 'password_protected_administrators', 'intval' );
345 register_setting( $this->options_group, 'password_protected_users', 'intval' );
346 register_setting( $this->options_group, 'password_protected_password', array( $this, 'sanitize_password_protected_password' ) );
347 register_setting( $this->options_group, 'password_protected_allowed_ip_addresses', array( $this, 'sanitize_ip_addresses' ) );
348 register_setting( $this->options_group, 'password_protected_remember_me', 'boolval' );
349 register_setting( $this->options_group, 'password_protected_remember_me_lifetime', 'intval' );
350 register_setting( $this->options_group.'-advanced', 'password_protected_text_above_password', array( 'type' => 'string' ) );
351 register_setting( $this->options_group.'-advanced', 'password_protected_text_below_password', array( 'type' => 'string' ) );
352
353 }
354
355 /**
356 * Login Designer Message
357 */
358 public function login_designer_message(){
359 $image = plugin_dir_url( __DIR__ ) . "assets/images/login-designer-demo.gif";
360 echo '<div id="pp-sidebar-box">
361 <h3>
362 🎨' . esc_attr__( 'Now you can customize your Password Protected screen with the', 'password-protected' ) . ' <a href="'. admin_url( '/plugin-install.php?s=login%2520designer&tab=search&type=term' ) .'">Login Designer plugin</a>🌈
363 </h3>
364 <img draggable="false" role="img" class="image" src=" ' . esc_attr($image) . ' ">
365 <h3><a href="'. admin_url( '/plugin-install.php?s=login%2520designer&tab=search&type=term' ) .'" class="pp-try button-primary">' . esc_attr__( '👉 Try it now! It\'s Free.', 'password-protected' ) . '</a></h3>
366
367 </div>';
368 }
369
370 /**
371 * Sanitize Password Field Input
372 *
373 * @param string $val Password.
374 * @return string Sanitized password.
375 */
376 public function sanitize_password_protected_password( $val ) {
377
378 $old_val = get_option( 'password_protected_password' );
379
380 if ( is_array( $val ) ) {
381 if ( empty( $val['new'] ) ) {
382 return $old_val;
383 } elseif ( empty( $val['confirm'] ) ) {
384 add_settings_error( 'password_protected_password', 'password_protected_password', __( 'New password not saved. When setting a new password please enter it in both fields.', 'password-protected' ) );
385 return $old_val;
386 } elseif ( $val['new'] != $val['confirm'] ) {
387 add_settings_error( 'password_protected_password', 'password_protected_password', __( 'New password not saved. Password fields did not match.', 'password-protected' ) );
388 return $old_val;
389 } elseif ( $val['new'] == $val['confirm'] ) {
390 add_settings_error( 'password_protected_password', 'password_protected_password', __( 'New password saved.', 'password-protected' ), 'updated' );
391 return $val['new'];
392 }
393 return get_option( 'password_protected_password' );
394 }
395
396
397 return $val;
398
399 }
400
401 /**
402 * Sanitize IP Addresses
403 *
404 * @param string $val IP addresses.
405 * @return string Sanitized IP addresses.
406 */
407 public function sanitize_ip_addresses( $val ) {
408
409 $ip_addresses = explode( "\n", $val );
410 $ip_addresses = array_map( 'sanitize_text_field', $ip_addresses );
411 $ip_addresses = array_map( 'trim', $ip_addresses );
412 $ip_addresses = array_map( array( $this, 'validate_ip_address' ), $ip_addresses );
413 $ip_addresses = array_filter( $ip_addresses );
414
415 $val = implode( "\n", $ip_addresses );
416
417 return $val;
418
419 }
420
421 /**
422 * Validate IP Address
423 *
424 * @param string $ip_address IP Address.
425 * @return string Validated IP Address.
426 */
427 private function validate_ip_address( $ip_address ) {
428
429 return filter_var( $ip_address, FILTER_VALIDATE_IP );
430
431 }
432
433 /**
434 * Password Protected Section
435 */
436 public function password_protected_settings_section() {
437
438 return 1;
439
440 }
441
442 /**
443 * Password Protection Status Field
444 */
445 public function password_protected_status_field() {
446
447 echo '<label><input name="password_protected_status" id="password_protected_status" type="checkbox" value="1" ' . checked( 1, get_option( 'password_protected_status' ), false ) . ' /> ' . __( 'Enabled', 'password-protected' ) . '</label>';
448
449 }
450
451 /**
452 * Password Protection Permissions Field
453 */
454 public function password_protected_permissions_field() {
455
456 echo '<p><label><input name="password_protected_administrators" id="password_protected_administrators" type="checkbox" value="1" ' . checked( 1, get_option( 'password_protected_administrators' ), false ) . ' /> ' . __( 'Allow Administrators', 'password-protected' ) . '</label></p>';
457 echo '<p><label><input name="password_protected_users" id="password_protected_users" type="checkbox" value="1" ' . checked( 1, get_option( 'password_protected_users' ), false ) . ' /> ' . __( 'Allow Logged In Users', 'password-protected' ) . '</label></p>';
458 echo '<p><label><input name="password_protected_feeds" id="password_protected_feeds" type="checkbox" value="1" ' . checked( 1, get_option( 'password_protected_feeds' ), false ) . ' /> ' . __( 'Allow RSS Feeds', 'password-protected' ) . '</label></p>';
459 echo '<p><label><input name="password_protected_rest" id="password_protected_rest" type="checkbox" value="1" ' . checked( 1, get_option( 'password_protected_rest' ), false ) . ' /> ' . __( 'Allow REST API Access', 'password-protected' ) . '</label></p>';
460
461 }
462
463 /**
464 * Password Field
465 */
466 public function password_protected_password_field() {
467
468 echo '<input type="password" name="password_protected_password[new]" id="password_protected_password_new" size="16" value="" autocomplete="off"> <p><span class="description">' . __( 'If you would like to change the password, type a new one. Otherwise, leave this blank.', 'password-protected' ) . '</span></p><br>
469 <input type="password" name="password_protected_password[confirm]" id="password_protected_password_confirm" size="16" value="" autocomplete="off"> <p><span class="description">' . __( 'Type your new password again.', 'password-protected' ) . '</span></p>';
470
471 }
472
473 /**
474 * Allowed IP Addresses Field
475 */
476 public function password_protected_allowed_ip_addresses_field() {
477
478 echo '<textarea name="password_protected_allowed_ip_addresses" id="password_protected_allowed_ip_addresses" rows="3" />' . get_option( 'password_protected_allowed_ip_addresses' ) . '</textarea>';
479
480 echo '<p class="description">' . esc_html__( 'Enter one IP address per line.', 'password-protected' );
481 if ( isset( $_SERVER['REMOTE_ADDR'] ) ) {
482 echo ' ' . esc_html( sprintf( __( 'Your IP address is %s.', 'password-protected' ), $_SERVER['REMOTE_ADDR'] ) );
483 }
484 echo '</p>';
485
486 }
487
488 /**
489 * Remember Me Field
490 */
491 public function password_protected_remember_me_field() {
492
493 echo '<label><input name="password_protected_remember_me" id="password_protected_remember_me" type="checkbox" value="1" ' . checked( 1, get_option( 'password_protected_remember_me' ), false ) . ' /></label>';
494
495 }
496
497 /**
498 * Remember Me lifetime field
499 */
500 public function password_protected_remember_me_lifetime_field() {
501
502 echo '<label><input name="password_protected_remember_me_lifetime" id="password_protected_remember_me_lifetime" min="1" type="number" value="' . get_option( 'password_protected_remember_me_lifetime', 14 ) . '" /></label>';
503
504 }
505
506 /**
507 * Password Protected Page description
508 */
509 public function password_protected_page_description() {
510 return 1;
511 }
512
513 /**
514 * Password Protected text above passsword
515 */
516 public function password_protected_text_above_password() {
517 echo '<label><textarea id="password_protected_text_above_password" name="password_protected_text_above_password" rows="4" cols="50" class="regular-text">' . get_option('password_protected_text_above_password') . '</textarea></label>';
518 }
519
520 /**
521 * Password Protected below above passsword
522 */
523 public function password_protected_text_below_password() {
524 echo '<label><textarea id="password_protected_text_below_password" name="password_protected_text_below_password" rows="4" cols="50" class="regular-text">' . get_option('password_protected_text_below_password') . '</textarea></label>';
525 }
526
527 /**
528 * Help Tab text field
529 */
530 public function password_protected_help_tab() {
531 echo '<p>' . __( 'Password protect your web site. Users will be asked to enter a password to view the site.', 'password-protected' ) . '<br />
532 ' . __( 'For more information about Password Protected settings, view the "Help" tab at the top of this page.', 'password-protected' ) . '</p>';
533 }
534
535 /**
536 * Try pro sideabr
537 */
538 public function password_protected_try_pro(){
539 $image = plugin_dir_url( __DIR__ ) . "assets/images/login-designer-demo.gif";
540 echo '
541 <div id="pp-sidebar-box">
542 <h3>
543 ' . esc_attr__( 'Looking for more options?', 'password-protected' ) . '
544 </h3>
545 <p class="pro-features"><a href="'.esc_url( "https://passwordwp.com/?utm=wp-dash" ).'">Click here to learn more about pro features</a></p>
546 <h3><a href="'.esc_url( "https://passwordwp.com/?utm=wp-dash" ).'" class="pp-try button-primary">' . esc_attr__( '👉 Try Pro', 'password-protected' ) . '</a></h3>
547
548 </div>';
549 }
550 /**
551 * Pre-update 'password_protected_password' Option
552 *
553 * Before the password is saved, MD5 it!
554 * Doing it in this way allows developers to intercept with an earlier filter if they
555 * need to do something with the plaintext password.
556 *
557 * @param string $newvalue New Value.
558 * @param string $oldvalue Old Value.
559 * @return string Filtered new value.
560 */
561 public function pre_update_option_password_protected_password( $newvalue, $oldvalue ) {
562
563 global $Password_Protected;
564
565 if ( $newvalue != $oldvalue ) {
566 $newvalue = $Password_Protected->encrypt_password( $newvalue );
567 }
568
569 return $newvalue;
570
571 }
572
573 /**
574 * Plugin Row Meta
575 *
576 * Adds GitHub and translate links below the plugin description on the plugins page.
577 *
578 * @param array $plugin_meta Plugin meta display array.
579 * @param string $plugin_file Plugin reference.
580 * @param array $plugin_data Plugin data.
581 * @param string $status Plugin status.
582 * @return array Plugin meta array.
583 */
584 public function plugin_row_meta( $plugin_meta, $plugin_file, $plugin_data, $status ) {
585
586 if ( 'password-protected/password-protected.php' == $plugin_file ) {
587 $plugin_meta[] = sprintf( '<a href="%s">%s</a>', __( 'http://github.com/benhuson/password-protected', 'password-protected' ), __( 'GitHub', 'password-protected' ) );
588 $plugin_meta[] = sprintf( '<a href="%s">%s</a>', __( 'https://translate.wordpress.org/projects/wp-plugins/password-protected', 'password-protected' ), __( 'Translate', 'password-protected' ) );
589 }
590
591 return $plugin_meta;
592
593 }
594
595 /**
596 * Plugin Action Links
597 *
598 * Adds settings link on the plugins page.
599 *
600 * @param array $actions Plugin action links array.
601 * @return array Plugin action links array.
602 */
603 public function plugin_action_links( $actions ) {
604
605 $actions[] = sprintf( '<a href="%s">%s</a>', admin_url( 'admin.php?page=password-protected' ), __( 'Settings', 'password-protected' ) );
606 return $actions;
607
608 }
609
610 /**
611 * Password Admin Notice
612 * Warns the user if they have enabled password protection but not entered a password
613 */
614 public function password_protected_admin_notices() {
615 global $Password_Protected;
616
617 // Check Support
618 $screens = $this->plugin_screen_ids( array( 'dashboard', 'plugins' ) );
619 if ( $this->is_current_screen( $screens ) ) {
620 $supported = $Password_Protected->is_plugin_supported();
621
622 if ( is_wp_error( $supported ) ) {
623 echo $this->admin_error_display( $supported->get_error_message( $supported->get_error_code() ) );
624 }
625 }
626
627 // Settings
628 if ( $this->is_current_screen( $this->plugin_screen_ids() ) ) {
629 $status = get_option( 'password_protected_status' );
630 $pwd = get_option( 'password_protected_password' );
631
632 if ( (bool) $status && empty( $pwd ) ) {
633 $error_message = __( 'You have enabled password protection but not yet set a password. Please set one below.', 'password-protected' );
634 $error = apply_filters( 'password_protected_password_status_activation', $error_message );
635 if( !empty( $error ) ) {
636 echo $this->admin_error_display( $error );
637 }
638 }
639
640 if ( current_user_can( 'manage_options' ) && ( (bool) get_option( 'password_protected_administrators' ) || (bool) get_option( 'password_protected_users' ) ) ) {
641 if ( (bool) get_option( 'password_protected_administrators' ) && (bool) get_option( 'password_protected_users' ) ) {
642 echo $this->admin_error_display( __( 'You have enabled password protection and allowed administrators and logged in users - other users will still need to enter a password to view the site.', 'password-protected' ) );
643 } elseif ( (bool) get_option( 'password_protected_administrators' ) ) {
644 echo $this->admin_error_display( __( 'You have enabled password protection and allowed administrators - other users will still need to enter a password to view the site.', 'password-protected' ) );
645 } elseif ( (bool) get_option( 'password_protected_users' ) ) {
646 echo $this->admin_error_display( __( 'You have enabled password protection and allowed logged in users - other users will still need to enter a password to view the site.', 'password-protected' ) );
647 }
648 }
649
650 }
651
652 }
653
654 /**
655 * Admin Error Display
656 *
657 * Returns a string wrapped in HTML to display an admin error.
658 *
659 * @param string $string Error string.
660 * @return string HTML error.
661 */
662 private function admin_error_display( $string ) {
663
664 return '<div class="error"><p>' . $string . '</p></div>';
665
666 }
667
668 /**
669 * Is Current Screen
670 *
671 * Checks wether the admin is displaying a specific screen.
672 *
673 * @param string|array $screen_id Admin screen ID(s).
674 * @return boolean
675 */
676 public function is_current_screen( $screen_id ) {
677
678 if ( function_exists( 'get_current_screen' ) ) {
679 $current_screen = get_current_screen();
680 if ( ! is_array( $screen_id ) ) {
681 $screen_id = array( $screen_id );
682 }
683 if ( in_array( $current_screen->id, $screen_id ) ) {
684 return true;
685 }
686 }
687
688 return false;
689
690 }
691
692 /**
693 * Plugin Screen IDs
694 *
695 * @param string|array $screen_id Additional screen IDs to add to the returned array.
696 * @return array Screen IDs.
697 */
698 public function plugin_screen_ids( $screen_id = '' ) {
699
700 $screen_ids = array( 'options-' . $this->options_group, 'settings_page_' . $this->options_group );
701 array_push( $screen_ids, 'toplevel_page_'.$this->options_group );
702 if ( ! empty( $screen_id ) ) {
703 if ( is_array( $screen_id ) ) {
704 $screen_ids = array_merge( $screen_ids, $screen_id );
705 } else {
706 $screen_ids[] = $screen_id;
707 }
708 }
709 // toplevel_page_password-protected
710 return $screen_ids;
711
712 }
713
714 /**
715 * @return bool
716 * true if login designer is installed and activated otherwise false
717 */
718 public function login_designer_is_installed_and_activated(): bool {
719 return class_exists( 'Login_Designer' );
720 }
721
722 /**
723 * @return bool
724 * true if password protected pro is installed and activated otherwise false
725 */
726 public function password_protected_pro_is_installed_and_activated(): bool {
727 return class_exists( 'Password_Protected_Pro' );
728 }
729
730 /**
731 * @return void
732 * Display Pro Features
733 */
734 public function password_protected_get_pro_features() {
735 ?>
736 <div class="pro-tab-content">
737 <div role="tabpanel" class="tab-pane fade" id="section4" style="display: block;">
738 <div id="wcwp" class="wrap" style="background: #FFF;">
739 <div class="pro_container">
740 <h2>Pro Features</h2>
741 <ol>
742 <li><p>Option to exclude individual pages and posts.</p></li>
743 <li><p>Exclude specific post types.</p></li>
744 <li><p>Feature to limit password attempts for certain interval.</p></li>
745 <li><p>Ability to manage multiple passwords with the following options:</p>
746 <ol style="list-style-type: lower-alpha;margin-top: 5px;">
747 <li>Option to activate and deactivate manually.</li>
748 <li>Set the expiry date for each password.</li>
749 <li>Set the usage limit for each password.</li>
750 </ol>
751 </li>
752 <li><p>Display activity log for each password attempt.</p></li>
753 </ol>
754
755 <a href="<?php echo esc_url( "https://passwordwp.com/?utm=wp-dash" ); ?>" class="get_pro_btn">Get Pro Now</a>
756 </div>
757 </div>
758 </div>
759 </div>
760 <?php
761 }
762
763 }
764