PluginProbe
Password Protected — Lock Entire Site, Pages, Posts, Categories, and Partial Content / 2.6.8
Password Protected — Lock Entire Site, Pages, Posts, Categories, and Partial Content v2.6.8
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.8, at admin/admin.php

965 lines 37.5 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 add_action( 'init', array( $this, 'init' ) );
25 }
26
27 /**
28 * Password protected setting tabs
29 * customizable using filter hook
30 */
31 public function password_protected_register_setting_tabs() {
32 $this->setting_tabs = array(
33 'general' => 'General',
34 'advanced' => 'Advanced',
35 );
36
37 $this->setting_tabs = apply_filters( 'password_protected_setting_tabs', $this->setting_tabs );
38
39 $this->setting_tabs['help'] = 'Help';
40 $this->setting_tabs['getpro'] = 'Get Pro';
41 if( $this->password_protected_pro_is_installed_and_activated() )
42 unset( $this->setting_tabs['getpro'] );
43 }
44
45 /**
46 * Admin enqueue scripts.
47 *
48 * @param string $hooks Page Hook.
49 */
50 public function admin_enqueue_scripts( $hooks ) {
51
52 if ( 'settings_page_password-protected' === $hooks || 'toplevel_page_password-protected' === $hooks ) {
53 wp_enqueue_style( 'password-protected-page-script', PASSWORD_PROTECTED_URL . 'assets/css/admin.css', array(), '2.6.2' );
54 wp_enqueue_script( 'password-protected-admin-script', PASSWORD_PROTECTED_URL . 'assets/js/admin.js', array('jquery'), '2.6.2' );
55 }
56 }
57
58 public function init() {
59 if ( isset( $_GET['page'] ) && 'password-protected-get-pro' === $_GET['page'] ) {
60 wp_redirect( 'https://passwordprotectedwp.com/pricing/?utm_source=Plugin&utm_medium=Submenu' );
61 exit;
62 }
63 }
64
65 /**
66 * Add Privacy Policy
67 */
68 public function add_privacy_policy() {
69
70 if ( ! function_exists( 'wp_add_privacy_policy_content' ) ) {
71 return 1;
72 }
73
74 $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' );
75
76 wp_add_privacy_policy_content( __( 'Password Protected Plugin', 'password-protected' ), wp_kses_post( wpautop( $content, false ) ) );
77
78 }
79
80 /**
81 * Admin Menu
82 */
83 public function admin_menu() {
84
85 $capability = apply_filters( 'password_protected_options_page_capability', 'manage_options' );
86 $this->settings_page_id = add_options_page(
87 __( 'Password Protected', 'password-protected' ),
88 __( 'Password Protected', 'password-protected' ),
89 $capability,
90 'password-protected',
91 array(
92 $this,
93 'settings_page'
94 )
95 );
96 add_menu_page(
97 'Password Protected',
98 'Password Protected',
99 'manage_options',
100 'password-protected',
101 array( $this, 'pp_admin_menu_page_callback' ),
102 'dashicons-lock',
103 99
104 );
105 add_action( 'load-' . $this->settings_page_id, array( $this, 'add_help_tabs' ), 20 );
106
107
108 if ( ! class_exists( 'Password_Protected_Pro' ) ) {
109 add_submenu_page(
110 'password-protected',
111 __( 'Get Pro', 'password-protected' ),
112 __( '↳ ⭐ Get Pro', 'password-protected' ),
113 'manage_options',
114 'password-protected-get-pro',
115 array( $this, 'password_protected_get_pro_features' )
116 );
117 }
118 }
119
120 /**
121 * Settings Page
122 */
123 public function settings_page() {
124 ?>
125
126 <div class="wrap">
127 <div id="icon-options-general" class="icon32"><br /></div>
128 <h2><?php _e( 'Password Protected Settings', 'password-protected' ) ?></h2>
129 <form method="post" action="options.php">
130 <?php
131 settings_fields( 'password-protected' );
132 do_settings_sections( 'password-protected' );
133 ?>
134 <p class="submit"><input type="submit" name="submit" id="submit" class="button button-primary" value="<?php _e( 'Save Changes' ) ?>"></p>
135 </form>
136 <?php do_settings_sections( 'password-protected-login-designer' ); ?>
137
138 <div id="help-notice">
139 <?php do_settings_sections( 'password-protected-compat' ); ?>
140 </div>
141 </div>
142
143 <?php
144 }
145
146 /** @since 2.6
147 * Admin Menu Settings Page
148 */
149 public function pp_admin_menu_page_callback() {
150 $tab = ( isset( $_GET['tab'] ) AND sanitize_text_field( $_GET['page'] ) == 'password-protected' ) ? sanitize_text_field( $_GET['tab'] ) : 'general';
151 ?>
152 <div class="wrap">
153 <div class="wrap-row">
154 <div class="wrap-col-70">
155 <h2 class="nav-tab-wrapper">
156 <?php foreach( $this->setting_tabs as $index => $setting_tab ) : ?>
157 <a href="?page=password-protected&tab=<?php echo $index; ?>" class="nav-tab <?php echo esc_attr( $index ); ?> <?php echo ( $tab == $index ) ? 'nav-tab-active' : '' ?> ">
158 <?php echo sprintf(__('%s', 'password-protected'), $setting_tab); ?>
159 </a>
160 <?php endforeach; ?>
161 </h2>
162 <?php
163 settings_fields( 'password-protected' );
164 ?>
165 <?php settings_errors(); ?>
166 <?php $this->password_protected_render_tab_content( $tab ); ?>
167 </div>
168 <div id="pp-sidebar" class="wrap-col-25">
169 <?php
170 $_tab = '';
171 if ( isset( $_GET['tab'] ) ) {
172 $_tab = sanitize_text_field( wp_unslash( $_GET['tab'] ) );
173 }
174 if ( 'getpro' !== $_tab ) :
175 do_settings_sections( 'password-protected-try-pro' );
176 do_settings_sections( 'password-protected-login-designer' );
177 do_action('password_protected_sidebar');
178 endif;
179 ?>
180 </div>
181 </div>
182 </div>
183 <?php
184 }
185
186 /**
187 * password protected render settings page in menu
188 */
189 public function password_protected_render_tab_content( $tab ) {
190 switch( $tab ) {
191 case 'general':
192 do_settings_sections( 'password-protected-help' );
193 echo '<form method="post" action="options.php">';
194 settings_fields( 'password-protected' );
195 do_settings_sections( 'password-protected' );
196 submit_button();
197 echo '</form>';
198 break;
199
200 case 'advanced':
201 echo '<form method="post" action="options.php">';
202 settings_fields( 'password-protected-advanced' );
203 do_action( 'password_protected_advanced_tab_content' );
204 do_settings_fields( 'password-protected&tab=advanced', 'password-protected-advanced' );
205 do_settings_sections( 'password-protected-advanced-tab' );
206 Password_Protected_reCAPTCHA::recpatcha_screen();
207
208 do_action( 'password_protected_after_google_recaptcha' );
209
210 submit_button();
211 echo '</form>';
212 break;
213
214 case 'help':
215 ?>
216 <div id="help-notice">
217 <?php do_settings_sections( 'password-protected-compat' ); ?>
218 </div>
219 <?php
220 break;
221
222 case 'getpro':
223 $this->password_protected_get_pro_features();
224 break;
225
226 case $tab;
227 do_action( 'password_protected_tab_'.$tab.'_content' );
228 break;
229
230 default:
231 echo "Something went wrong! Please contact support.";
232 break;
233 }
234 }
235
236 /**
237 * Add Help Tabs
238 */
239 public function add_help_tabs() {
240
241 global $wp_version;
242
243 if ( version_compare( $wp_version, '3.3', '<' ) ) {
244 return 1;
245 }
246
247 do_action( 'password_protected_help_tabs', get_current_screen() );
248
249 }
250
251 /**
252 * Help Tabs
253 *
254 * @param object $current_screen Screen object.
255 */
256 public function help_tabs( $current_screen ) {
257
258 $current_screen->add_help_tab( array(
259 'id' => 'PASSWORD_PROTECTED_SETTINGS',
260 'title' => __( 'Password Protected', 'password-protected' ),
261 'content' => __( '<p><strong>Password Protected Status</strong><br />Turn on/off password protection.</p>', 'password-protected' )
262 . __( '<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' )
263 . __( '<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' )
264 ) );
265
266 }
267
268 /**
269 * Settings API
270 */
271 public function password_protected_settings() {
272 // general tab
273 add_settings_section(
274 'password_protected',
275 '',
276 array( $this, 'password_protected_settings_section' ),
277 $this->options_group
278 );
279
280 add_settings_field(
281 'password_protected_status',
282 __( 'Password Protected Status', 'password-protected' ),
283 array( $this, 'password_protected_status_field' ),
284 $this->options_group,
285 'password_protected'
286 );
287
288 add_settings_field(
289 'password_protected_permissions',
290 __( 'Protected Permissions', 'password-protected' ),
291 array( $this, 'password_protected_permissions_field' ),
292 $this->options_group,
293 'password_protected'
294 );
295
296 add_settings_field(
297 'password_protected_password',
298 __( 'New Password', 'password-protected' ),
299 array( $this, 'password_protected_password_field' ),
300 $this->options_group,
301 'password_protected'
302 );
303
304 add_settings_field(
305 'password_protected_allowed_ip_addresses',
306 __( 'Allow IP Addresses', 'password-protected' ),
307 array( $this, 'password_protected_allowed_ip_addresses_field' ),
308 $this->options_group,
309 'password_protected'
310 );
311
312 add_settings_field(
313 'password_protected_remember_me',
314 __( 'Allow Remember me', 'password-protected' ),
315 array( $this, 'password_protected_remember_me_field' ),
316 $this->options_group,
317 'password_protected'
318 );
319
320 add_settings_field(
321 'password_protected_remember_me_lifetime',
322 __( 'Remember for this many days', 'password-protected' ),
323 array( $this, 'password_protected_remember_me_lifetime_field' ),
324 $this->options_group,
325 'password_protected'
326 );
327
328 // password protected advanced tab
329 add_settings_section(
330 'password-protected-advanced-tab',
331 'Password Protected Page description',
332 array( $this, 'password_protected_page_description' ),
333 'password-protected&tab=advanced'
334 );
335
336 add_settings_field(
337 'text-above-password',
338 __( 'Text Above Password Field', 'password-protected' ),
339 array( $this, 'password_protected_text_above_password' ),
340 'password-protected&tab=advanced',
341 'password-protected-advanced-tab'
342 );
343
344 add_settings_field(
345 'text-below-password',
346 __( 'Text Below Password Field ', 'password-protected' ),
347 array( $this, 'password_protected_text_below_password' ),
348 'password-protected&tab=advanced',
349 'password-protected-advanced-tab'
350 );
351
352 add_settings_field(
353 'password-protected-use-transient',
354 __( 'Use Transients', 'password-protected' ),
355 array( $this, 'password_protected_use_transient' ),
356 'password-protected&tab=advanced',
357 'password-protected-advanced-tab',
358 array(
359 'label_for' => 'password-protected-use-transient',
360 )
361 );
362
363 // password protected help tab
364 add_settings_section(
365 'password-protected-help',
366 '',
367 array( $this, 'password_protected_help_tab' ),
368 'password-protected-help'
369 );
370
371
372 // sidebar login designer compatibity
373 if( !$this->login_designer_is_installed_and_activated() ) {
374 add_settings_section(
375 'password-protected-login-designer',
376 '',
377 array( $this, 'login_designer_message' ),
378 'password-protected-login-designer'
379 );
380 }
381
382 if( !$this->password_protected_pro_is_installed_and_activated() ) {
383 add_settings_section(
384 'password-protected-try-pro',
385 '',
386 array( $this, 'password_protected_try_pro' ),
387 'password-protected-try-pro'
388 );
389 }
390
391 // registering settings
392 register_setting( $this->options_group, 'password_protected_status', 'intval' );
393 register_setting( $this->options_group, 'password_protected_feeds', 'intval' );
394 register_setting( $this->options_group, 'password_protected_rest', 'intval' );
395 register_setting( $this->options_group, 'password_protected_administrators', 'intval' );
396 register_setting( $this->options_group, 'password_protected_users', 'intval' );
397 register_setting( $this->options_group, 'password_protected_password', array( $this, 'sanitize_password_protected_password' ) );
398 register_setting( $this->options_group, 'password_protected_allowed_ip_addresses', array( $this, 'sanitize_ip_addresses' ) );
399 register_setting( $this->options_group, 'password_protected_remember_me', 'boolval' );
400 register_setting( $this->options_group, 'password_protected_remember_me_lifetime', 'intval' );
401 register_setting( $this->options_group . '-advanced', 'password_protected_use_transient' );
402 register_setting( $this->options_group.'-advanced', 'password_protected_text_above_password', array( 'type' => 'string' ) );
403 register_setting( $this->options_group.'-advanced', 'password_protected_text_below_password', array( 'type' => 'string' ) );
404
405 }
406
407 /**
408 * Login Designer Message
409 */
410 public function login_designer_message(){
411 $image = plugin_dir_url( __DIR__ ) . "assets/images/login-designer-demo.gif";
412 echo '<div id="pp-sidebar-box">
413 <h3>
414 🎨' . 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>🌈
415 </h3>
416 <img draggable="false" role="img" class="image" src=" ' . esc_attr($image) . ' ">
417 <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>
418
419 </div>';
420 }
421
422 /**
423 * Sanitize Password Field Input
424 *
425 * @param string $val Password.
426 * @return string Sanitized password.
427 */
428 public function sanitize_password_protected_password( $val ) {
429
430 $old_val = get_option( 'password_protected_password' );
431
432 if ( is_array( $val ) ) {
433 if ( empty( $val['new'] ) ) {
434 return $old_val;
435 } elseif ( empty( $val['confirm'] ) ) {
436 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' ) );
437 return $old_val;
438 } elseif ( $val['new'] != $val['confirm'] ) {
439 add_settings_error( 'password_protected_password', 'password_protected_password', __( 'New password not saved. Password fields did not match.', 'password-protected' ) );
440 return $old_val;
441 } elseif ( $val['new'] == $val['confirm'] ) {
442 add_settings_error( 'password_protected_password', 'password_protected_password', __( 'New password saved.', 'password-protected' ), 'updated' );
443 return $val['new'];
444 }
445 return get_option( 'password_protected_password' );
446 }
447
448
449 return $val;
450
451 }
452
453 /**
454 * Sanitize IP Addresses
455 *
456 * @param string $val IP addresses.
457 * @return string Sanitized IP addresses.
458 */
459 public function sanitize_ip_addresses( $val ) {
460
461 $ip_addresses = explode( "\n", $val );
462 $ip_addresses = array_map( 'sanitize_text_field', $ip_addresses );
463 $ip_addresses = array_map( 'trim', $ip_addresses );
464 $ip_addresses = array_map( array( $this, 'validate_ip_address' ), $ip_addresses );
465 $ip_addresses = array_filter( $ip_addresses );
466
467 $val = implode( "\n", $ip_addresses );
468
469 return $val;
470
471 }
472
473 /**
474 * Validate IP Address
475 *
476 * @param string $ip_address IP Address.
477 * @return string Validated IP Address.
478 */
479 private function validate_ip_address( $ip_address ) {
480
481 return filter_var( $ip_address, FILTER_VALIDATE_IP );
482
483 }
484
485 /**
486 * Password Protected Section
487 */
488 public function password_protected_settings_section() {
489
490 return 1;
491
492 }
493
494 /**
495 * Password Protection Status Field
496 */
497 public function password_protected_status_field() {
498
499 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>';
500
501 }
502
503 /**
504 * Password Protection Permissions Field
505 */
506 public function password_protected_permissions_field() {
507
508 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>';
509 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>';
510 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>';
511 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>';
512
513 }
514
515 /**
516 * Password Field
517 */
518 public function password_protected_password_field() {
519
520 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>
521 <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>';
522
523 }
524
525 /**
526 * Allowed IP Addresses Field
527 */
528 public function password_protected_allowed_ip_addresses_field() {
529 echo '<textarea name="password_protected_allowed_ip_addresses" id="password_protected_allowed_ip_addresses" rows="3" />' . esc_html( get_option( 'password_protected_allowed_ip_addresses' ) ) . '</textarea>';
530
531 echo '<p class="description">' . esc_html__( 'Enter one IP address per line.', 'password-protected' );
532 if ( isset( $_SERVER['REMOTE_ADDR'] ) ) {
533 echo ' ' . esc_html( sprintf( __( 'Your IP address is %s.', 'password-protected' ), $_SERVER['REMOTE_ADDR'] ) );
534 }
535 echo '</p>';
536
537 }
538
539 /**
540 * Remember Me Field
541 */
542 public function password_protected_remember_me_field() {
543
544 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>';
545
546 }
547
548 /**
549 * Remember Me lifetime field
550 */
551 public function password_protected_remember_me_lifetime_field() {
552
553 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>';
554
555 }
556
557 /**
558 * Password Protected Page description
559 */
560 public function password_protected_page_description() {
561 return 1;
562 }
563
564 /**
565 * Password Protected text above passsword
566 */
567 public function password_protected_text_above_password() {
568 echo '<label><textarea id="password_protected_text_above_password" name="password_protected_text_above_password" rows="4" cols="50" class="regular-text">' . esc_attr( get_option('password_protected_text_above_password') ) . '</textarea></label>';
569 }
570
571 /**
572 * Password Protected below above passsword
573 */
574 public function password_protected_text_below_password() {
575 echo '<label><textarea id="password_protected_text_below_password" name="password_protected_text_below_password" rows="4" cols="50" class="regular-text">' . esc_attr( get_option('password_protected_text_below_password') ) . '</textarea></label>';
576 }
577
578 public function password_protected_use_transient() {
579 $use_transient = get_option( 'password_protected_use_transient', false );
580 $checked = empty( $use_transient ) ? '' : 'checked="checked"';
581 echo '<lable for="password-protected-use-transient"><input ' . esc_attr( $checked ) . ' type="checkbox" name="password_protected_use_transient" value="1" id="password-protected-use-transient" /> ' . esc_attr__( 'This option will save your passwords in transients for your IP instead of cookies. Only use it if you face any cache-related issues on your site.', 'password-protected' ) . '</lable>';
582 }
583
584 /**
585 * Help Tab text field
586 */
587 public function password_protected_help_tab() {
588 echo '<p>' . __( 'Password protect your web site. Users will be asked to enter a password to view the site.', 'password-protected' ) . '<br />
589 ' . __( 'For more information about Password Protected settings, view the "Help" tab at the top of this page.', 'password-protected' ) . '</p>';
590 }
591
592 /**
593 * Try pro sideabr
594 */
595 public function password_protected_try_pro() {
596 $image_url = PASSWORD_PROTECTED_URL . 'assets/images/';
597 echo '<div class="sidebar-widget">
598 <div class="banner-header">
599 <h2>Looking For More Options?</h2>
600 </div>
601 <div class="banner-body">
602 <div class="password-protected-feature">
603 <img src="' . $image_url . 'ppp-ads-04.png" alt="">
604 <div>
605 <a target="_blank" href="' . $this->utm_links_generator( 'post-and-page-protection', 'plugin', 'sidebar' ) . '">Protect Individual Post And Page</a>
606 </div>
607 </div>
608 <div class="password-protected-feature">
609 <img src="' . $image_url . 'ppp-ads-05.png" alt="">
610 <div>
611 <a target="_blank" href="' . $this->utm_links_generator( 'password-protect-individual-posts/how-to-secure-a-category-or-taxonomy', 'plugin', 'sidebar' ) . '">Protect Specific Categories / Taxonomies</a>
612 </div>
613 </div>
614 <div class="password-protected-feature">
615 <img src="' . $image_url . 'ppp-ads-06.png" alt="">
616 <div>
617 <a target="_blank" href="' . $this->utm_links_generator( 'pro/exclude-pages-posts-and-post-types', 'plugin', 'sidebar' ) . '">Exclude Specific Pages, Posts And Post Type</a>
618 </div>
619 </div>
620 <div class="password-protected-feature">
621 <img src="' . $image_url . 'ppp-ads-07.png" alt="">
622 <div>
623 <a target="_blank" href="' . $this->utm_links_generator( 'pro/password-activity-logs', 'plugin', 'sidebar' ) . '">Display Activity Log For Each Password Attempt</a>
624 </div>
625 </div>
626 <div class="password-protected-feature">
627 <img src="' . $image_url . 'ppp-ads-08.png" alt="" style="top: 5px">
628 <div>
629 <a target="_blank" href="' . $this->utm_links_generator( 'pro/manage-multiple-websites', 'plugin', 'sidebar' ) . '">
630 <div>
631 Multiple Password Management<br>
632 (Activate, Deactivate and Delete Passwords)
633 </div>
634 </a>
635 </div>
636 </div>
637 <div class="password-protected-feature">
638 <img src="' . $image_url . 'ppp-ads-09.png" alt="">
639 <div>
640 <a target="_blank" href="' . $this->utm_links_generator( 'post-and-page-protection/how-to-secure-all-posts-and-pages', 'plugin', 'sidebar' ) . '">Protect Specific Post Types</a>
641 </div>
642 </div>
643 <!-- <div class="password-protected-feature">
644 <img src="' . $image_url . 'ppp-ads-10.png" alt="">
645 <div>
646 <a target="_blank" href="' . $this->utm_links_generator( 'pro/exclude-pages-posts-and-post-types', 'plugin', 'sidebar' ) . '">Exclude Specific Pages And Posts</a>
647 </div>
648 </div> -->
649 <div class="password-protected-feature">
650 <img src="' . $image_url . 'ppp-ads-11.png" alt="">
651 <div>
652 <a target="_blank" href="' . $this->utm_links_generator( 'pro/limit-password-attempts-and-lockdown-time', 'plugin', 'sidebar' ) . '">Limit Password Attempts For A Certain Interval</a>
653 </div>
654 </div>
655 <div class="password-protected-feature">
656 <img src="' . $image_url . 'ppp-ads-12.png" alt="">
657 <div>
658 <a target="_blank" href="' . $this->utm_links_generator( 'pro/manage-multiple-websites', 'plugin', 'sidebar' ) . '">Set A Password Expiration Date And Usage Limit</a>
659 </div>
660 </div>
661 <div class="password-protected-feature">
662 <img src="' . $image_url . 'ppp-ads-13.png" alt="" style="top: 5px;">
663 <div>
664 <a target="_blank" href="' . $this->utm_links_generator( 'pro/bypass-password-protection-for-specific-urls', 'plugin', 'sidebar' ) . '">
665 <div>
666 Get A Bypass URL To Access Your<br> WordPress
667 Site Without A Password
668 </div>
669 </a>
670 </div>
671 </div>
672 </div>
673 <div class="banner-footer">
674 <a href="https://passwordprotectedwp.com/pricing?utm_source=plugin&utm_medium=sidebar" class="banner-button">👉🏻 Get Password Protected Pro</a>
675 </div>
676 </div>';
677 }
678 /**
679 * Pre-update 'password_protected_password' Option
680 *
681 * Before the password is saved, MD5 it!
682 * Doing it in this way allows developers to intercept with an earlier filter if they
683 * need to do something with the plaintext password.
684 *
685 * @param string $newvalue New Value.
686 * @param string $oldvalue Old Value.
687 * @return string Filtered new value.
688 */
689 public function pre_update_option_password_protected_password( $newvalue, $oldvalue ) {
690
691 global $Password_Protected;
692
693 if ( $newvalue != $oldvalue ) {
694 $newvalue = $Password_Protected->encrypt_password( $newvalue );
695 }
696
697 return $newvalue;
698
699 }
700
701 /**
702 * Plugin Row Meta
703 *
704 * Adds GitHub and translate links below the plugin description on the plugins page.
705 *
706 * @param array $plugin_meta Plugin meta display array.
707 * @param string $plugin_file Plugin reference.
708 * @param array $plugin_data Plugin data.
709 * @param string $status Plugin status.
710 * @return array Plugin meta array.
711 */
712 public function plugin_row_meta( $plugin_meta, $plugin_file, $plugin_data, $status ) {
713
714 if ( 'password-protected/password-protected.php' == $plugin_file ) {
715 $plugin_meta[] = sprintf( '<a href="%s">%s</a>', __( 'http://github.com/benhuson/password-protected', 'password-protected' ), __( 'GitHub', 'password-protected' ) );
716 $plugin_meta[] = sprintf( '<a href="%s">%s</a>', __( 'https://translate.wordpress.org/projects/wp-plugins/password-protected', 'password-protected' ), __( 'Translate', 'password-protected' ) );
717 }
718
719 return $plugin_meta;
720
721 }
722
723 /**
724 * Plugin Action Links
725 *
726 * Adds settings link on the plugins page.
727 *
728 * @param array $actions Plugin action links array.
729 * @return array Plugin action links array.
730 */
731 public function plugin_action_links( $actions ) {
732
733 $actions[] = sprintf( '<a href="%s">%s</a>', admin_url( 'admin.php?page=password-protected' ), __( 'Settings', 'password-protected' ) );
734 return $actions;
735
736 }
737
738 /**
739 * Password Admin Notice
740 * Warns the user if they have enabled password protection but not entered a password
741 */
742 public function password_protected_admin_notices() {
743 global $Password_Protected;
744
745 // Check Support
746 $screens = $this->plugin_screen_ids( array( 'dashboard', 'plugins' ) );
747 if ( $this->is_current_screen( $screens ) ) {
748 $supported = $Password_Protected->is_plugin_supported();
749
750 if ( is_wp_error( $supported ) ) {
751 echo $this->admin_error_display( $supported->get_error_message( $supported->get_error_code() ) );
752 }
753 }
754
755 // Settings
756 if ( $this->is_current_screen( $this->plugin_screen_ids() ) ) {
757 $status = get_option( 'password_protected_status' );
758 $pwd = get_option( 'password_protected_password' );
759
760 if ( (bool) $status && empty( $pwd ) ) {
761 $error_message = __( 'You have enabled password protection but not yet set a password. Please set one below.', 'password-protected' );
762 $error = apply_filters( 'password_protected_password_status_activation', $error_message );
763 if( !empty( $error ) ) {
764 echo $this->admin_error_display( $error );
765 }
766 }
767
768 if ( current_user_can( 'manage_options' ) && ( (bool) get_option( 'password_protected_administrators' ) || (bool) get_option( 'password_protected_users' ) ) ) {
769 if ( (bool) get_option( 'password_protected_administrators' ) && (bool) get_option( 'password_protected_users' ) ) {
770 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' ) );
771 } elseif ( (bool) get_option( 'password_protected_administrators' ) ) {
772 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' ) );
773 } elseif ( (bool) get_option( 'password_protected_users' ) ) {
774 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' ) );
775 }
776 }
777
778 }
779
780 }
781
782 /**
783 * Admin Error Display
784 *
785 * Returns a string wrapped in HTML to display an admin error.
786 *
787 * @param string $string Error string.
788 * @return string HTML error.
789 */
790 private function admin_error_display( $string ) {
791
792 return '<div class="error"><p>' . $string . '</p></div>';
793
794 }
795
796 /**
797 * Is Current Screen
798 *
799 * Checks wether the admin is displaying a specific screen.
800 *
801 * @param string|array $screen_id Admin screen ID(s).
802 * @return boolean
803 */
804 public function is_current_screen( $screen_id ) {
805
806 if ( function_exists( 'get_current_screen' ) ) {
807 $current_screen = get_current_screen();
808 if ( ! is_array( $screen_id ) ) {
809 $screen_id = array( $screen_id );
810 }
811 if ( in_array( $current_screen->id, $screen_id ) ) {
812 return true;
813 }
814 }
815
816 return false;
817
818 }
819
820 /**
821 * Plugin Screen IDs
822 *
823 * @param string|array $screen_id Additional screen IDs to add to the returned array.
824 * @return array Screen IDs.
825 */
826 public function plugin_screen_ids( $screen_id = '' ) {
827
828 $screen_ids = array( 'options-' . $this->options_group, 'settings_page_' . $this->options_group );
829 array_push( $screen_ids, 'toplevel_page_'.$this->options_group );
830 if ( ! empty( $screen_id ) ) {
831 if ( is_array( $screen_id ) ) {
832 $screen_ids = array_merge( $screen_ids, $screen_id );
833 } else {
834 $screen_ids[] = $screen_id;
835 }
836 }
837 // toplevel_page_password-protected
838 return $screen_ids;
839
840 }
841
842 /**
843 * @return bool
844 * true if login designer is installed and activated otherwise false
845 */
846 public function login_designer_is_installed_and_activated(): bool {
847 return class_exists( 'Login_Designer' );
848 }
849
850 /**
851 * @return bool
852 * true if password protected pro is installed and activated otherwise false
853 */
854 public function password_protected_pro_is_installed_and_activated(): bool {
855 return class_exists( 'Password_Protected_Pro' );
856 }
857
858 /**
859 * @return void
860 * Display Pro Features
861 */
862 public function password_protected_get_pro_features() {
863 $image_url = PASSWORD_PROTECTED_URL . 'assets/images/';
864 echo '<div class="banner">
865 <div class="banner-header">
866 <h1>Looking For More Options?</h1>
867 </div>
868 <div class="banner-body">
869 <div class="banner-col-2">
870 <div class="password-protected-feature">
871 <img src="' . $image_url . 'ppp-ads-04.png" alt="">
872 <div>
873 <a target="_blank" href="' . $this->utm_links_generator( 'post-and-page-protection' ) . '">Protect Individual Post And Page</a>
874 </div>
875 </div>
876 <div class="password-protected-feature">
877 <img src="' . $image_url . 'ppp-ads-05.png" alt="">
878 <div>
879 <a target="_blank" href="' . $this->utm_links_generator( 'password-protect-individual-posts/how-to-secure-a-category-or-taxonomy' ) . '">Protect Specific Categories / Taxonomies</a>
880 </div>
881 </div>
882 <div class="password-protected-feature">
883 <img src="' . $image_url . 'ppp-ads-06.png" alt="">
884 <div>
885 <a target="_blank" href="' . $this->utm_links_generator( 'pro/exclude-pages-posts-and-post-types' ) . '">Exclude Specific Post Type</a>
886 </div>
887 </div>
888 <div class="password-protected-feature">
889 <img src="' . $image_url . 'ppp-ads-07.png" alt="">
890 <div>
891 <a target="_blank" href="' . $this->utm_links_generator( 'pro/password-activity-logs' ) . '">Display Activity Log For Each Password Attempt</a>
892 </div>
893 </div>
894 <div class="password-protected-feature">
895 <img src="' . $image_url . 'ppp-ads-08.png" alt="" style="top: 3px">
896 <div>
897 <a target="_blank" href="' . $this->utm_links_generator( 'pro/manage-multiple-websites' ) . '">
898 <div>
899 Multiple Password Management<br>
900 (Activate, Deactivate and Delete Passwords)
901 </div>
902 </a>
903 </div>
904 </div>
905 </div>
906 <div class="banner-col-2">
907 <div class="password-protected-feature">
908 <img src="' . $image_url . 'ppp-ads-09.png" alt="">
909 <div>
910 <a target="_blank" href="' . $this->utm_links_generator( 'post-and-page-protection/how-to-secure-all-posts-and-pages' ) . '">Protect Specific Post Types</a>
911 </div>
912 </div>
913 <div class="password-protected-feature">
914 <img src="' . $image_url . 'ppp-ads-10.png" alt="">
915 <div>
916 <a target="_blank" href="' . $this->utm_links_generator( 'pro/exclude-pages-posts-and-post-types' ) . '">Exclude Specific Pages And Posts</a>
917 </div>
918 </div>
919 <div class="password-protected-feature">
920 <img src="' . $image_url . 'ppp-ads-11.png" alt="">
921 <div>
922 <a target="_blank" href="' . $this->utm_links_generator( 'pro/limit-password-attempts-and-lockdown-time' ) . '">Limit Password Attempts For A Certain Interval</a>
923 </div>
924 </div>
925 <div class="password-protected-feature">
926 <img src="' . $image_url . 'ppp-ads-12.png" alt="">
927 <div>
928 <a target="_blank" href="' . $this->utm_links_generator( 'pro/manage-multiple-websites' ) . '">Set A Password Expiration Date And Usage Limit</a>
929 </div>
930 </div>
931 <div class="password-protected-feature">
932 <img src="' . $image_url . 'ppp-ads-13.png" alt="" style="top:3px;">
933 <div>
934 <a target="_blank" href="' . $this->utm_links_generator( 'pro/bypass-password-protection-for-specific-urls' ) . '">
935 <div>
936 Get A Bypass URL To Access Your WordPress<br>
937 Site Without A Password
938 </div>
939 </a>
940 </div>
941 </div>
942 </div>
943 <div class="clearfix"></div>
944 </div>
945 <div class="banner-footer">
946 <a href="https://passwordprotectedwp.com/pricing?utm_source=plugin&utm_medium=protab" class="banner-button">👉🏻 Get Password Protected Pro</a>
947 </div>
948 </div>';
949 }
950
951 private function utm_links_generator( $page, $source = 'plugin', $utm_medium = 'protab' ) {
952 $url = 'https://passwordprotectedwp.com/documentation/';
953 $url .= $page;
954
955 return add_query_arg(
956 array(
957 'utm_source' => $source,
958 'utm_medium' => $utm_medium
959 ),
960 $url
961 );
962 }
963
964 }
965