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

1,548 lines 59.9 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' ), 15 );
16 add_action( 'admin_init', array( $this, 'add_privacy_policy' ) );
17 add_action( 'admin_menu', array( $this, 'admin_menu' ) );
18 add_action( 'password_protected_subtab_password-protected-page-description_content', array( $this, 'password_protected_page_description_tab' ) );
19 add_action( 'password_protected_help_tabs', array( $this, 'help_tabs' ), 5 );
20 add_action( 'admin_notices', array( $this, 'password_protected_admin_notices' ) );
21 add_filter( 'plugin_row_meta', array( $this, 'plugin_row_meta' ), 10, 4 );
22 add_filter( 'plugin_action_links_password-protected/password-protected.php', array( $this, 'plugin_action_links' ) );
23 add_filter( 'pre_update_option_password_protected_password', array( $this, 'pre_update_option_password_protected_password' ), 10, 2 );
24 add_action( 'admin_enqueue_scripts', array( $this, 'admin_enqueue_scripts' ) );
25 add_action( 'init', array( $this, 'init' ) );
26
27 add_action( 'enqueue_block_editor_assets', array( $this, 'enqueue_block_editor_upsell_assets' ) );
28 add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_classic_editor_upsell_assets' ) );
29
30 add_action( 'password_protected_subtab_cache-issue_content', array( $this, 'cache_related_issue' ) );
31 add_action( 'admin_footer', array( $this, 'add_script_in_footer' ), 9999 );
32 add_filter( 'password_protected_setting_tabs', array( $this, 'register_setting_tabs' ), -1 );
33 add_filter( 'password_protected_setting_tabs', array( $this, 'register_help_tabs' ), 9999 );
34 }
35
36 public function register_setting_tabs( $tabs ) {
37 $new_tabs = array(
38 'general' => array(
39 'title' => __( 'General', 'password-protected' ),
40 'slug' => 'general',
41 'icon' => 'dashicons-migrate',
42 ),
43
44 'advanced' => array(
45 'title' => __( 'Advanced', 'password-protected' ),
46 'slug' => 'advanced',
47 'icon' => 'dashicons-admin-settings',
48 'sub-tabs' => array(
49 'exclude-from-protection' => array(
50 'title' => __( 'Exclude From Protection', 'password-protected' ),
51 'slug' => 'exclude-from-protection',
52 ),
53
54 'password-protected-page-description' => array(
55 'title' => __( 'Protected Page Content', 'password-protected' ),
56 'slug' => 'password-protected-page-description',
57 ),
58
59 'bypass-url' => array(
60 'title' => __( 'Bypass URL', 'password-protected' ),
61 'slug' => 'bypass-url',
62 ),
63
64 'cache-issue' => array(
65 'title' => __( 'Cache Issue', 'password-protected' ),
66 'slug' => 'cache-issue',
67 ),
68
69 'custom-error-message' => array(
70 'title' => __( 'Custom Error Message', 'password-protected' ),
71 'slug' => 'custom-error-message',
72 ),
73 ),
74 ),
75
76 'manage_passwords' => array(
77 'title' => __( 'Multiple Passwords', 'password-protected' ),
78 'slug' => 'manage_passwords',
79 'icon' => 'dashicons-shield',
80 'show_as_submenu' => true,
81 'position' => 2,
82 ),
83
84 'content-protection' => array(
85 'title' => __( 'Content Protection', 'password-protected' ),
86 'slug' => 'content-protection',
87 'icon' => 'dashicons-superhero',
88 'position' => 1,
89 'show_as_submenu' => true,
90 'sub-tabs' => array(
91 'post-type-protection' => array(
92 'title' => __( 'Post Type Protection', 'password-protected' ),
93 'slug' => 'post-type-protection',
94 ),
95
96 'taxonomy-protection' => array(
97 'title' => __( 'Taxonomy Protection', 'password-protected' ),
98 'slug' => 'taxonomy-protection',
99 ),
100
101 'partial-protection' => array(
102 'title' => __( 'Partial Content Protection', 'password-protected' ),
103 'slug' => 'partial-protection',
104 ),
105 ),
106 ),
107
108 'security' => array(
109 'title' => __( 'Security', 'password-protected' ),
110 'slug' => 'security',
111 'icon' => 'dashicons-shield-alt',
112 'sub-tabs' => array(
113 'whitelist-user-role' => array(
114 'title' => __( 'Whitelist User Role', 'password-protected' ),
115 'slug' => 'whitelist-user-role',
116 ),
117
118 'all-captchas' => array(
119 'title' => __( 'Captcha', 'password-protected' ),
120 'slug' => 'all-captchas',
121 ),
122
123 'wp-admin-protection' => array(
124 'title' => __( 'WP-Admin Protection', 'password-protected' ),
125 'slug' => 'wp-admin-protection',
126 ),
127
128 'attempt-limitation' => array(
129 'title' => __( 'Attempt Limitation', 'password-protected' ),
130 'slug' => 'attempt-limitation',
131 ),
132 ),
133 ),
134
135 'logs' => array(
136 'title' => __( 'Logs', 'password-protected' ),
137 'slug' => 'logs',
138 'icon' => 'dashicons-media-text',
139 'show_as_submenu' => true,
140 'position' => 3,
141 'sub-tabs' => array(
142 'activity_logs' => array(
143 'title' => __( 'Activity Logs', 'password-protected' ),
144 'slug' => 'activity_logs',
145 ),
146
147 'activity-report' => array(
148 'title' => __( 'Activity Report', 'password-protected' ),
149 'slug' => 'activity-report',
150 ),
151 ),
152 ),
153
154 'protected-screen' => array(
155 'title' => __( 'Customize', 'password-protected' ),
156 'slug' => 'protected-screen',
157 'icon' => 'dashicons-admin-customizer',
158 'show_as_submenu' => true,
159 'position' => 5,
160 ),
161
162 'request-password' => array(
163 'title' => __( 'Password Request', 'password-protected' ),
164 'slug' => 'request-password',
165 'icon' => 'dashicons-email-alt',
166 'show_as_submenu' => true,
167 'position' => 4,
168 'sub-tabs' => array(
169 'password-request' => array(
170 'title' => __( 'Request Password', 'password-protected' ),
171 'slug' => 'password-request',
172 ),
173 'requests' => array(
174 'title' => __( 'Requests', 'password-protected' ),
175 'slug' => 'requests',
176 ),
177 'email-templates' => array(
178 'title' => __( 'Email Templates', 'password-protected' ),
179 'slug' => 'email-templates',
180 ),
181 ),
182 ),
183 );
184
185 return array_merge( $tabs, $new_tabs );
186 }
187
188 public function register_help_tabs( $tabs ) {
189
190 $tabs['help'] = array(
191 'title' => __( 'Help', 'password-protected' ),
192 'slug' => 'help',
193 'icon' => 'dashicons-editor-help',
194 );
195
196 if ( ! class_exists( 'Password_Protected_Pro' ) ) {
197 $tabs['getpro'] = array(
198 'title' => __( 'Get Pro', 'password-protected' ),
199 'slug' => 'getpro',
200 'icon' => 'dashicons-superhero-alt',
201 );
202 }
203
204 return $tabs;
205 }
206
207 public function add_script_in_footer() {
208 ?>
209 <script type="text/javascript">
210 jQuery( document ).ready( function( $ ) {
211 $( '.toplevel_page_password-protected a' ).each( function( index,element ) {
212 if ( 'admin.php?page=password-protected-get-pro' === $( element ).attr( 'href' ) ) {
213 $( element ).css( { 'background-color': '#8076ff', 'color': '#ffffff', 'padding': '15px auto' } );
214 }
215 } );
216 } );
217 </script>
218 <?php
219 }
220
221 /**
222 * Password protected setting tabs
223 * customizable using filter hook
224 */
225 public function password_protected_register_setting_tabs() {
226 $this->setting_tabs = apply_filters( 'password_protected_setting_tabs', array() );
227 }
228
229 /**
230 * Admin enqueue scripts.
231 *
232 * @param string $hooks Page Hook.
233 */
234 public function admin_enqueue_scripts( $hooks ) {
235
236 if ( 'settings_page_password-protected' === $hooks || 'toplevel_page_password-protected' === $hooks ) {
237 global $Password_Protected;
238 wp_enqueue_style(
239 'password-protected-poppins',
240 'https://fonts.googleapis.com/css2?family=Poppins:wght@400;500;600;700&display=swap',
241 array(),
242 null
243 );
244 wp_enqueue_style( 'password-protected-page-script', PASSWORD_PROTECTED_URL . 'assets/css/admin.css', array( 'password-protected-poppins' ), $Password_Protected->version );
245 wp_enqueue_script( 'password-protected-admin-script', PASSWORD_PROTECTED_URL . 'assets/js/admin.js', array('jquery'), $Password_Protected->version );
246 wp_localize_script(
247 'password-protected-admin-script',
248 'passwordProtectedAdminObject',
249 array(
250 'imageURL' => PASSWORD_PROTECTED_URL . 'assets/images/',
251 'heading' => __( "Don't Settle for Limited Password Protection", 'password-protected' ),
252 'description' => __( 'Upgrade to Business plan and unlock all premium features!', 'password-protected' ),
253 'buttonText' => __( 'Upgrade to Premium', 'password-protected' ),
254 'buttonRedirect' => add_query_arg(
255 array(
256 'page' => 'password-protected',
257 'tab' => 'getpro',
258 ),
259 admin_url( 'admin.php' )
260 ),
261 )
262 );
263 }
264 }
265
266 /**
267 * Enqueue assets for block editor native visibility upsell.
268 */
269 public function enqueue_block_editor_upsell_assets() {
270 if ( class_exists( 'Password_Protected_Pro' ) ) {
271 return;
272 }
273 global $Password_Protected;
274
275 wp_enqueue_script(
276 'password-protected-native-visibility-upsell',
277 PASSWORD_PROTECTED_URL . 'assets/js/native-visibility-upsell.js',
278 array( 'jquery' ),
279 $Password_Protected->version,
280 true
281 );
282
283 wp_localize_script(
284 'password-protected-native-visibility-upsell',
285 'passwordProtectedUpsell',
286 array(
287 'settingsUrl' => admin_url( 'admin.php?page=password-protected' ),
288 )
289 );
290 }
291
292 /**
293 * Enqueue assets for classic editor native visibility upsell.
294 *
295 * @param string $hook The current admin page hook.
296 */
297 public function enqueue_classic_editor_upsell_assets( $hook ) {
298 if ( class_exists( 'Password_Protected_Pro' ) ) {
299 return;
300 }
301 if ( 'post.php' !== $hook && 'post-new.php' !== $hook ) {
302 return;
303 }
304
305 global $Password_Protected;
306
307 wp_enqueue_script(
308 'password-protected-classic-visibility-upsell',
309 PASSWORD_PROTECTED_URL . 'assets/js/classic-visibility-upsell.js',
310 array( 'jquery' ),
311 $Password_Protected->version,
312 true
313 );
314
315 wp_localize_script(
316 'password-protected-classic-visibility-upsell',
317 'passwordProtectedUpsell',
318 array(
319 'settingsUrl' => admin_url( 'admin.php?page=password-protected' ),
320 )
321 );
322 }
323
324 public function init() {
325
326 if ( ! class_exists( 'Password_Protected_Pro' ) ) {
327
328 add_action( 'password_protected_subtab_exclude-from-protection_content', array( $this, 'dummy_content' ) );
329 add_action( 'password_protected_subtab_custom-error-message_content', array( $this, 'dummy_content' ) );
330 add_action( 'text_before_after_login_form', array( $this, 'dummy_content' ) );
331 add_action( 'password_protected_subtab_attempt-limitation_content', array( $this, 'dummy_content' ) );
332 add_action( 'password_protected_subtab_bypass-url_content', array( $this, 'dummy_content' ) );
333 add_action( 'password_protected_tab_manage_passwords_content', array( $this, 'dummy_content' ) );
334 add_action( 'password_protected_subtab_post-type-protection_content', array( $this, 'dummy_content' ) );
335 add_action( 'password_protected_subtab_taxonomy-protection_content', array( $this, 'dummy_content' ) );
336 add_action( 'password_protected_subtab_partial-protection_content', array( $this, 'dummy_content' ) );
337 add_action( 'password_protected_subtab_whitelist-user-role_content', array( $this, 'dummy_content' ) );
338 add_action( 'password_protected_subtab_wp-admin-protection_content', array( $this, 'dummy_content' ) );
339 add_action( 'password_protected_subtab_activity_logs_content', array( $this, 'dummy_content' ) );
340
341 add_action( 'password_protected_subtab_logo-styles_content', array( $this, 'dummy_content' ) );
342 add_action( 'password_protected_subtab_label-styles_content', array( $this, 'dummy_content' ) );
343 add_action( 'password_protected_subtab_field-styles_content', array( $this, 'dummy_content' ) );
344 add_action( 'password_protected_subtab_button-styles_content', array( $this, 'dummy_content' ) );
345 add_action( 'password_protected_subtab_remember-me-styles_content', array( $this, 'dummy_content' ) );
346 add_action( 'password_protected_subtab_form-background_content', array( $this, 'dummy_content' ) );
347 add_action( 'password_protected_subtab_body-background_content', array( $this, 'dummy_content' ) );
348 add_action( 'password_protected_subtab_below-form_content', array( $this, 'dummy_content' ) );
349 add_action( 'password_protected_subtab_below-page_content', array( $this, 'dummy_content' ) );
350 add_action( 'password_protected_subtab_custom-css_content', array( $this, 'dummy_content' ) );
351 add_action( 'password_protected_subtab_password-request_content', array( $this, 'dummy_content' ) );
352 add_action( 'password_protected_subtab_requests_content', array( $this, 'dummy_content' ) );
353 add_action( 'password_protected_subtab_email-templates_content', array( $this, 'dummy_content' ) );
354 }
355
356 if ( isset( $_GET['page'] ) && 'password-protected-get-pro' === $_GET['page'] ) {
357 wp_redirect( 'https://passwordprotectedwp.com/pricing/?utm_source=Plugin&utm_medium=Submenu' );
358 exit;
359 }
360 }
361
362 /**
363 * Add Privacy Policy
364 */
365 public function add_privacy_policy() {
366
367 if ( ! function_exists( 'wp_add_privacy_policy_content' ) ) {
368 return 1;
369 }
370
371 $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' );
372
373 wp_add_privacy_policy_content( __( 'Password Protected Plugin', 'password-protected' ), wp_kses_post( wpautop( $content, false ) ) );
374
375 }
376
377 /**
378 * Admin Menu
379 */
380 public function admin_menu() {
381
382 $capability = apply_filters( 'password_protected_options_page_capability', 'manage_options' );
383 $this->settings_page_id = add_options_page(
384 __( 'Password Protected', 'password-protected' ),
385 __( 'Password Protected', 'password-protected' ),
386 $capability,
387 'password-protected',
388 array(
389 $this,
390 'settings_page'
391 )
392 );
393
394 add_menu_page(
395 'Password Protected',
396 'Password Protected',
397 'manage_options',
398 'password-protected',
399 array( $this, 'pp_admin_menu_page_callback' ),
400 'dashicons-lock',
401 99
402 );
403
404 add_submenu_page(
405 'password-protected',
406 'Password Protected',
407 'General',
408 'manage_options',
409 'password-protected',
410 array( $this, 'pp_admin_menu_page_callback' )
411 );
412
413 add_action( 'load-' . $this->settings_page_id, array( $this, 'add_help_tabs' ), 20 );
414
415 $menus = apply_filters( 'password_protected_setting_tabs', array() );
416
417 foreach ( $menus as $menu_key => $menu ) {
418 if ( isset( $menu['show_as_submenu'] ) && $menu['show_as_submenu'] ) {
419 add_submenu_page(
420 'password-protected',
421 $menu['title'],
422 $menu['title'],
423 'manage_options',
424 add_query_arg(
425 array(
426 'page' => 'password-protected',
427 'tab' => $menu['slug'],
428 ),
429 admin_url( 'admin.php' )
430 ),
431 null
432 );
433 }
434 }
435
436 if ( ! class_exists( 'Password_Protected_Pro' ) ) {
437 add_submenu_page(
438 'password-protected',
439 __( 'Get Pro Now', 'password-protected' ),
440 __( '⭐ Get Pro Now', 'password-protected' ),
441 'manage_options',
442 'password-protected-get-pro',
443 array( $this, 'password_protected_get_pro_features' )
444 );
445 }
446 }
447
448 /**
449 * Settings Page
450 */
451 public function settings_page() {
452 ?>
453
454 <div class="wrap">
455 <div id="icon-options-general" class="icon32"><br /></div>
456 <h2><?php _e( 'Password Protected Settings', 'password-protected' ) ?></h2>
457 <form method="post" action="options.php">
458 <?php
459 settings_fields( 'password-protected' );
460 do_settings_sections( 'password-protected' );
461 ?>
462 <p class="submit"><input type="submit" name="submit" id="submit" class="button button-primary" value="<?php _e( 'Save Changes' ) ?>"></p>
463 </form>
464 <?php
465 // do_settings_sections( 'password-protected-login-designer' );
466 ?>
467
468 <div id="help-notice">
469 <?php do_settings_sections( 'password-protected-compat' ); ?>
470 </div>
471 </div>
472
473 <?php
474 }
475
476 /** @since 2.6
477 * Admin Menu Settings Page
478 */
479 public function pp_admin_menu_page_callback() {
480 $tab = ( isset( $_GET['tab'] ) && sanitize_text_field( $_GET['page'] ) == 'password-protected' ) ? sanitize_text_field( $_GET['tab'] ) : 'general';
481 $subtab = ( isset( $_GET['sub-tab'] ) && sanitize_text_field( $_GET['page'] ) == 'password-protected' ) ? sanitize_text_field( $_GET['sub-tab'] ) : '';
482
483 // for backward compatibility.
484 $this->setting_tabs = array_filter(
485 $this->setting_tabs,
486 function( $tab ) {
487 return isset( $tab['title'] ) && isset( $tab['slug'] ) && isset( $tab['icon'] );
488 }
489 );
490 if ( isset( $this->setting_tabs[ $tab ]['sub-tabs'] ) && ! empty( $this->setting_tabs[ $tab ]['sub-tabs'] ) ) {
491 $this->setting_tabs[ $tab ]['sub-tabs'] = array_filter(
492 $this->setting_tabs[ $tab ]['sub-tabs'],
493 function ( $subtab ) {
494 return isset( $subtab['title'] ) && isset( $subtab['slug'] );
495 }
496 );
497 }
498 ?>
499 <div class="wrap">
500 <?php $attributes = class_exists( 'Password_Protected_Pro' ) ? 'style="display: block;"' : 'class="wrap-row"' ; ?>
501 <div <?php echo $attributes; ?>>
502 <?php $attributes = class_exists( 'Password_Protected_Pro' ) ? 'style="width: 100%;"' : 'class="wrap-col-70"'; ?>
503 <div <?php echo $attributes; ?>>
504 <?php settings_errors(); ?>
505
506 <div class="pp-wrapper">
507
508 <div class="pp-nav-wrapper">
509 <?php foreach( $this->setting_tabs as $index => $setting_tab ) : ?>
510 <div class="pp-nav-tab <?php echo ( $tab === $setting_tab['slug'] ) ? 'pp-nav-tab-active' : ''; ?> <?php echo ( 'getpro' === $setting_tab['slug'] ) ? 'pp-pro-tab' : ''; ?>">
511 <a href="<?php echo admin_url( 'admin.php?page=password-protected&tab=' . $setting_tab['slug'] ); ?>" class="get-pro-txt">
512 <?php if ( 'getpro' === $setting_tab['slug'] ) : ?>
513 <span class="pp-get-pro-tab-icon">
514 <img src="<?php echo esc_url( PASSWORD_PROTECTED_URL . 'assets/images/pro-tab-icon.png' ); ?>" alt="" class="pro-tab-icon">
515 </span>
516
517 <?php elseif ( filter_var( $setting_tab['icon'], FILTER_VALIDATE_URL ) ) : ?>
518
519 <span>
520 <img src="<?php echo esc_url( $setting_tab['icon'] ); ?>" alt="">
521 </span>
522
523 <?php else : ?>
524
525 <span class="dashicons <?php echo esc_attr( $setting_tab['icon'] ); ?>"></span>
526
527 <?php endif; ?>
528
529 <?php echo esc_html( $setting_tab['title'] ); ?>
530 </a>
531 </div>
532 <?php endforeach; ?>
533 </div>
534
535 <div class="pp-content-wrapper">
536 <?php if ( isset( $this->setting_tabs[ $tab ] ) && isset( $this->setting_tabs[ $tab ]['sub-tabs'] ) && ! empty( $this->setting_tabs[ $tab ]['sub-tabs'] ) ) : ?>
537 <div class="pp-sub-tabs-wrapper">
538 <div class="pp-subtabs-links">
539 <?php if ( empty( $subtab ) ) { ?>
540 <?php
541 $subtab = array_keys( $this->setting_tabs[ $tab ]['sub-tabs'] );
542 $subtab = $subtab[0];
543 ?>
544 <?php } ?>
545 <?php foreach ( $this->setting_tabs[ $tab ]['sub-tabs'] as $sub_tab ) : ?>
546 <a class="<?php echo $subtab === $sub_tab['slug'] ? 'active' : '' ?>" href="<?php echo admin_url( 'admin.php?page=password-protected&tab=' . $tab . '&sub-tab=' . $sub_tab['slug'] ); ?>"><?php echo $sub_tab['title']; ?></a>
547 <?php endforeach; ?>
548 </div>
549 </div>
550 <?php endif; ?>
551
552 <div class="pp-settings-wrapper">
553 <?php $this->password_protected_render_tab_content( $tab, $subtab ); ?>
554 </div>
555 </div>
556 </div>
557 </div>
558
559 <?php $attributes = class_exists( 'Password_Protected_Pro' ) ? 'style="display:none;"' : 'id="pp-sidebar" class="wrap-col-25"'; ?>
560 <div <?php echo $attributes; ?>>
561 <?php
562 $_tab = '';
563 if ( isset( $_GET['tab'] ) ) {
564 $_tab = sanitize_text_field( wp_unslash( $_GET['tab'] ) );
565 }
566 if ( 'getpro' !== $_tab ) :
567 do_settings_sections( 'password-protected-try-pro' );
568 // do_settings_sections( 'password-protected-login-designer' );
569 do_action('password_protected_sidebar');
570 endif;
571 ?>
572 </div>
573 </div>
574 </div>
575 <?php
576 }
577
578 public function password_protected_page_description_tab() {
579 echo '<form action="options.php" method="post" enctype="multipart/form-data">';
580 settings_fields( 'password-protected-advanced-protected-page-content' );
581 do_settings_sections( 'password-protected&tab=advanced&sub-tab=password-protected-page-description' );
582 do_action('text_before_after_login_form', $_GET);
583 submit_button();
584 echo '</form>';
585 }
586
587 /**
588 * password protected render settings page in menu
589 */
590 public function password_protected_render_tab_content( $tab, $sub_tab ) {
591
592 switch ( $tab ) {
593 case 'general':
594 do_settings_sections( 'password-protected-help' );
595 echo '<form method="post" action="options.php">';
596 settings_fields( 'password-protected' );
597 do_settings_sections( 'password-protected' );
598 submit_button();
599 echo '</form>';
600 break;
601
602 case 'help':
603 ?>
604 <div id="help-notice">
605 <?php do_settings_sections( 'password-protected-compat' ); ?>
606 </div>
607 <?php
608 break;
609
610 case 'getpro':
611 $this->password_protected_get_pro_features();
612 break;
613
614 case $tab:
615
616 if ( ! empty( $sub_tab ) ) {
617 do_action(
618 'password_protected_subtab_' . $sub_tab . '_content',
619 $this->setting_tabs[ $tab ]['sub-tabs'][ $sub_tab ]
620 );
621 } else {
622 do_action(
623 'password_protected_tab_' . $tab . '_content',
624 $this->setting_tabs[ $tab ]
625 );
626 }
627 break;
628 }
629 }
630
631 /**
632 * Add Help Tabs
633 */
634 public function add_help_tabs() {
635
636 global $wp_version;
637
638 if ( version_compare( $wp_version, '3.3', '<' ) ) {
639 return 1;
640 }
641
642 do_action( 'password_protected_help_tabs', get_current_screen() );
643
644 }
645
646 /**
647 * Help Tabs
648 *
649 * @param object $current_screen Screen object.
650 */
651 public function help_tabs( $current_screen ) {
652
653 $current_screen->add_help_tab( array(
654 'id' => 'PASSWORD_PROTECTED_SETTINGS',
655 'title' => __( 'Password Protected', 'password-protected' ),
656 'content' => __( '<p><strong>Password Protected Status</strong><br />Turn on/off password protection.</p>', 'password-protected' )
657 . __( '<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' )
658 . __( '<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' )
659 ) );
660
661 }
662
663 /**
664 * Settings API
665 */
666 public function password_protected_settings() {
667 // general tab
668 add_settings_section(
669 'password_protected',
670 __( 'Password Protected Configuration', 'password-protected' ),
671 array( $this, 'password_protected_settings_section' ),
672 $this->options_group
673 );
674
675 add_settings_field(
676 'password_protected_status',
677 __( 'Password Protected Status', 'password-protected' ),
678 array( $this, 'password_protected_status_field' ),
679 $this->options_group,
680 'password_protected'
681 );
682
683 add_settings_field(
684 'password_protected_permissions',
685 __( 'Protected Permissions', 'password-protected' ),
686 array( $this, 'password_protected_permissions_field' ),
687 $this->options_group,
688 'password_protected'
689 );
690
691 add_settings_field(
692 'password_protected_password',
693 __( 'New Password', 'password-protected' ),
694 array( $this, 'password_protected_password_field' ),
695 $this->options_group,
696 'password_protected'
697 );
698
699 add_settings_field(
700 'password_protected_allowed_ip_addresses',
701 __( 'Allow IP Addresses', 'password-protected' ),
702 array( $this, 'password_protected_allowed_ip_addresses_field' ),
703 $this->options_group,
704 'password_protected'
705 );
706
707 add_settings_field(
708 'password_protected_remember_me',
709 __( 'Allow Remember me', 'password-protected' ),
710 array( $this, 'password_protected_remember_me_field' ),
711 $this->options_group,
712 'password_protected'
713 );
714
715 add_settings_field(
716 'password_protected_remember_me_lifetime',
717 __( 'Remember for this many days', 'password-protected' ),
718 array( $this, 'password_protected_remember_me_lifetime_field' ),
719 $this->options_group,
720 'password_protected'
721 );
722
723 // password protected advanced tab
724 add_settings_section(
725 'password-protected-advanced-tab',
726 __( 'Password Protected Page description', 'password-protected' ),
727 array( $this, 'password_protected_page_description' ),
728 'password-protected&tab=advanced&sub-tab=password-protected-page-description'
729 );
730
731 add_settings_field(
732 'text-above-password',
733 __( 'Text Above Password Field', 'password-protected' ),
734 array( $this, 'password_protected_text_above_password' ),
735 'password-protected&tab=advanced&sub-tab=password-protected-page-description',
736 'password-protected-advanced-tab'
737 );
738
739 add_settings_field(
740 'text-below-password',
741 __( 'Text Below Password Field ', 'password-protected' ),
742 array( $this, 'password_protected_text_below_password' ),
743 'password-protected&tab=advanced&sub-tab=password-protected-page-description',
744 'password-protected-advanced-tab'
745 );
746
747 add_settings_section(
748 'password-protected-advanced-tab-cache-issue',
749 __( 'Cache Issue', 'password-protected' ),
750 '__return_null',
751 'password-protected&tab=advanced&sub-tab=cache-issue'
752 );
753
754 add_settings_field(
755 'password-protected-advance-cache',
756 __( 'Problem With Cookie Cache', 'password-protected' ),
757 array( $this, 'password_protected_use_transient' ),
758 'password-protected&tab=advanced&sub-tab=cache-issue',
759 'password-protected-advanced-tab-cache-issue',
760 array(
761 'label_for' => 'password-protected-use-transient',
762 )
763 );
764
765 add_settings_field(
766 'password-protected-page-cache',
767 __( 'Problem With Page Cache', 'password-protected' ),
768 array( $this, 'password_protected_enable_dynamic_args' ),
769 'password-protected&tab=advanced&sub-tab=cache-issue',
770 'password-protected-advanced-tab-cache-issue',
771 array(
772 'label_for' => 'pp_enable_dynamic_args',
773 )
774 );
775
776 // password protected help tab
777 add_settings_section(
778 'password-protected-help',
779 '',
780 array( $this, 'password_protected_help_tab' ),
781 'password-protected-help'
782 );
783
784 if( !$this->password_protected_pro_is_installed_and_activated() ) {
785 add_settings_section(
786 'password-protected-try-pro',
787 '',
788 array( $this, 'password_protected_try_pro' ),
789 'password-protected-try-pro'
790 );
791 }
792
793 if ( ! $this->login_designer_is_installed_and_activated() ) {
794 /* add_settings_section(
795 'password-protected-login-designer',
796 '',
797 array( $this, 'password_protected_login_designer' ),
798 'password-protected-login-designer'
799 ); */
800 }
801
802 // registering settings
803 register_setting( $this->options_group, 'password_protected_status', 'intval' );
804 register_setting( $this->options_group, 'password_protected_feeds', 'intval' );
805 register_setting( $this->options_group, 'password_protected_rest', 'intval' );
806 register_setting( $this->options_group, 'password_protected_administrators', 'intval' );
807 register_setting( $this->options_group, 'password_protected_users', 'intval' );
808 register_setting( $this->options_group, 'password_protected_password', array( $this, 'sanitize_password_protected_password' ) );
809 register_setting( $this->options_group, 'password_protected_allowed_ip_addresses', array( $this, 'sanitize_ip_addresses' ) );
810 register_setting( $this->options_group, 'password_protected_remember_me', 'boolval' );
811 register_setting( $this->options_group, 'password_protected_remember_me_lifetime', 'intval' );
812
813 register_setting( 'password-protected-advanced-protected-page-content', 'password_protected_text_above_password', array( 'type' => 'string' ) );
814 register_setting( 'password-protected-advanced-protected-page-content', 'password_protected_text_below_password', array( 'type' => 'string' ) );
815
816 register_setting( 'password_protected_cache_issue', 'password_protected_use_transient' );
817 register_setting( 'password_protected_cache_issue', 'pp_enable_dynamic_args' );
818 }
819
820 /**
821 * Sanitize Password Field Input
822 *
823 * @param string $val Password.
824 * @return string Sanitized password.
825 */
826 public function sanitize_password_protected_password( $val ) {
827
828 $old_val = get_option( 'password_protected_password' );
829
830 if ( is_array( $val ) ) {
831 if ( empty( $val['new'] ) ) {
832 return $old_val;
833 } elseif ( empty( $val['confirm'] ) ) {
834 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' ) );
835 return $old_val;
836 } elseif ( $val['new'] != $val['confirm'] ) {
837 add_settings_error( 'password_protected_password', 'password_protected_password', __( 'New password not saved. Password fields did not match.', 'password-protected' ) );
838 return $old_val;
839 } elseif ( $val['new'] == $val['confirm'] ) {
840 add_settings_error( 'password_protected_password', 'password_protected_password', __( 'New password saved.', 'password-protected' ), 'updated' );
841 return $val['new'];
842 }
843 return get_option( 'password_protected_password' );
844 }
845
846
847 return $val;
848
849 }
850
851 /**
852 * Sanitize IP Addresses
853 *
854 * @param string $val IP addresses.
855 * @return string Sanitized IP addresses.
856 */
857 public function sanitize_ip_addresses( $val ) {
858 $un_sanitized_value = $val;
859
860 $ip_addresses = explode( "\n", $val );
861 $ip_addresses = array_map( 'sanitize_text_field', $ip_addresses );
862 $ip_addresses = array_map( 'trim', $ip_addresses );
863 $ip_addresses = array_map( array( $this, 'validate_ip_address' ), $ip_addresses );
864 $ip_addresses = array_filter( $ip_addresses );
865
866 $val = implode( "\n", $ip_addresses );
867
868 return apply_filters( 'password_protected__sanitize_ip_addresses', $val, $un_sanitized_value );
869
870 }
871
872 /**
873 * Validate IP Address
874 *
875 * @param string $ip_address IP Address.
876 * @return string Validated IP Address.
877 */
878 private function validate_ip_address( $ip_address ) {
879
880 return filter_var( $ip_address, FILTER_VALIDATE_IP );
881
882 }
883
884 /**
885 * Password Protected Section
886 */
887 public function password_protected_settings_section() {
888
889 return 1;
890
891 }
892
893 /**
894 * Password Protection Status Field
895 */
896 public function password_protected_status_field() {
897
898 echo '
899 <div class="pp-toggle-wrapper">
900 <input type="checkbox" name="password_protected_status" id="password_protected_status" value="1" ' . checked( 1, get_option( 'password_protected_status' ), false ) . ' />
901 <label class="pp-toggle" for="password_protected_status">
902 <span class="pp-toggle-slider"></span>
903 </label>
904 </div>
905 <p>
906 <label for="password_protected_status">' . __( 'Do you want to enable password protection for whole site?', 'password-protected' ) . '</label>
907 </p>
908 ';
909
910 }
911
912 /**
913 * Password Protection Permissions Field
914 */
915 public function password_protected_permissions_field() {
916
917 echo '<p>
918 <label for="password_protected_administrators">
919 <input type="checkbox" name="password_protected_administrators" id="password_protected_administrators" value="1" ' . checked( 1, get_option( 'password_protected_administrators' ), false ) . ' />'
920 . __( 'Allow Administrators', 'password-protected' )
921 . '</label>
922 </p>
923 <p>
924 <label for="password_protected_users">
925 <input type="checkbox" name="password_protected_users" id="password_protected_users" value="1" ' . checked( 1, get_option( 'password_protected_users' ), false ) . ' />'
926 . __( 'Allow Logged In Users', 'password-protected' )
927 . '</label>
928 </p>
929 <p>
930 <label for="password_protected_feeds">
931 <input type="checkbox" name="password_protected_feeds" id="password_protected_feeds" value="1" ' . checked( 1, get_option( 'password_protected_feeds' ), false ) . ' />'
932 . __( 'Allow RSS Feeds', 'password-protected' )
933 . '</label>
934 </p>
935 <p>
936 <label for="password_protected_rest">
937 <input type="checkbox" name="password_protected_rest" id="password_protected_rest" value="1" ' . checked( 1, get_option( 'password_protected_rest' ), false ) . ' />'
938 . __( 'Allow REST API', 'password-protected' )
939 . '</label>
940 </p>';
941
942 }
943
944 /**
945 * Password Field
946 */
947 public function password_protected_password_field() {
948
949 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>
950 <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>';
951
952 }
953
954 /**
955 * Allowed IP Addresses Field
956 */
957 public function password_protected_allowed_ip_addresses_field() {
958 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>';
959
960 echo '<p class="description">' . esc_html__( 'Enter one IP address per line.', 'password-protected' );
961 if ( isset( $_SERVER['REMOTE_ADDR'] ) ) {
962 echo ' ' . esc_html( sprintf( __( 'Your IP address is %s.', 'password-protected' ), $_SERVER['REMOTE_ADDR'] ) );
963 }
964 echo '</p>';
965
966 }
967
968 /**
969 * Remember Me Field
970 */
971 public function password_protected_remember_me_field() {
972
973 echo '<div class="pp-toggle-wrapper">
974 <input type="checkbox" name="password_protected_remember_me" id="password_protected_remember_me" value="1" ' . checked( 1, get_option( 'password_protected_remember_me' ), false ) . ' />
975 <label class="pp-toggle" for="password_protected_remember_me">
976 <span class="pp-toggle-slider"></span>
977 </label>
978 </div>
979 <p>
980 <label for="password_protected_remember_me">' . __( 'Allow Remember me', 'password-protected' ) . '</label>
981 </p>';
982
983 }
984
985 /**
986 * Remember Me lifetime field
987 */
988 public function password_protected_remember_me_lifetime_field() {
989
990 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>';
991
992 }
993
994 /**
995 * Password Protected Page description
996 */
997 public function password_protected_page_description() {
998 return 1;
999 }
1000
1001 /**
1002 * Password Protected text above passsword
1003 */
1004 public function password_protected_text_above_password() {
1005 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>';
1006 }
1007
1008 /**
1009 * Password Protected below above passsword
1010 */
1011 public function password_protected_text_below_password() {
1012 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>';
1013 }
1014
1015 public function password_protected_use_transient() {
1016 $use_transient = get_option( 'password_protected_use_transient', 'default' );
1017
1018 $cache_issue = array(
1019 array(
1020 'name' => 'default',
1021 'title' => __( 'Use default settings', 'password-protected' ),
1022 ),
1023 array(
1024 'name' => 'transient',
1025 'title' => __( 'You can enable this option if you are having trouble with cookies due to cache or server restrictions.', 'password-protected' ),
1026 'description' => __( 'Note: It uses transients, which are saved based on the user\'s IP address, unlike cookies that are tied to the specific browser. This means that once a user logs in using any browser, they can access the page from any other browser as long as they are on the same IP address.', 'password-protected' ),
1027 ),
1028 );
1029
1030 foreach ( $cache_issue as $issue ) :
1031 echo '<p>
1032 <label>
1033 <input type="radio" name="password_protected_use_transient" value="' . esc_attr( $issue['name'] ) . '" ' . checked( $use_transient, $issue['name'], false ) . ' />' . esc_html( $issue['title'] ) . '
1034 </label>
1035 </p>';
1036
1037 if ( isset( $issue['description'] ) ) :
1038 echo '<p class="desc"><strong>' . esc_attr( $issue['description'] ) . '</strong></p>';
1039 endif;
1040 endforeach;
1041 }
1042
1043 /**
1044 * Page cache: dynamic URL arguments to bust full-page cache.
1045 */
1046 public function password_protected_enable_dynamic_args() {
1047 $value = get_option( 'pp_enable_dynamic_args', false );
1048 echo '<div class="pp-toggle-wrapper">
1049 <input value="yes" type="checkbox" name="pp_enable_dynamic_args" id="pp_enable_dynamic_args" ' . checked( $value, 'yes', false ) . '>
1050 <label for="pp_enable_dynamic_args" class="pp-toggle">
1051 <span class="pp-toggle-slider"></span>
1052 </label>
1053 </div>
1054 <p class="desc">
1055 <strong>
1056 <label for="pp_enable_dynamic_args">' . esc_html__( 'Enable if page cache causes login or access issues; adds dynamic query args to URLs.', 'password-protected' ) . '</label>
1057 </strong>
1058 </p>';
1059 }
1060
1061 /**
1062 * Help Tab text field
1063 */
1064 public function password_protected_help_tab() {
1065 echo '<div class="pp-help-notice">
1066 <p>'
1067 . __( 'Password protect your web site. Users will be asked to enter a password to view the site.', 'password-protected' )
1068 . '<br />'
1069 . __( 'For more information about Password Protected settings, view the "Help" tab at the top of this page.', 'password-protected' )
1070 . '</p>
1071 </div>';
1072 }
1073
1074 /**
1075 * Try pro sideabr
1076 */
1077 public function password_protected_try_pro() {
1078 $image_url = PASSWORD_PROTECTED_URL . 'assets/images/';
1079 echo '<div class="pp-sidebar-widget">
1080 <div class="pp-container">
1081
1082 <div class="pp-sidebar-header">
1083 <div class="pp-row">
1084 <div class="pp-crown-icon">
1085 <img src="' . $image_url . 'pro-crown.png" />
1086 </div>
1087 <div>
1088 <p class="heading-2">Password</p>
1089 <div class="pp-head-wt-pro-tag">
1090 <p class="heading-2">Protected</p>
1091 <p class="pp-pro-tag">
1092 PRO
1093 </p>
1094 </div>
1095 <p class="pp-sm-txt-under-head">Level up your WordPress protection</p>
1096 </div>
1097 </div>
1098 </div>
1099
1100 <div class="pp-sidebar-body">
1101 <ul>
1102 <li>
1103 <span class="sidebar-body-image-container"><img src="' . $image_url . 'lock-2.png" alt="" /></span> <span class="sidebar-body-text-container">Protect Custom Post Types</span>
1104 </li>
1105 <li>
1106 <span class="sidebar-body-image-container"><img src="' . $image_url . 'lock-2.png" alt="" /></span> <span class="sidebar-body-text-container">Exclude Specific Page, Post & Product</span>
1107 </li>
1108 <li>
1109 <span class="sidebar-body-image-container"><img src="' . $image_url . 'lock-2.png" alt="" /></span> <span class="sidebar-body-text-container">Partial Content Protection</span>
1110 </li>
1111 <li>
1112 <span class="sidebar-body-image-container"><img src="' . $image_url . 'lock-2.png" alt="" /></span> <span class="sidebar-body-text-container">Protect Categories</span>
1113 </li>
1114 <li>
1115 <span class="sidebar-body-image-container"><img src="' . $image_url . 'lock-2.png" alt="" /></span> <span class="sidebar-body-text-container">Protect WordPress Login Page</span>
1116 </li>
1117 <li>
1118 <span class="sidebar-body-image-container"><img src="' . $image_url . 'lock-2.png" alt="" /></span> <span class="sidebar-body-text-container">Lock Specific Posts & Pages</span>
1119 </li>
1120 <li>
1121 <span class="sidebar-body-image-container"><img src="' . $image_url . 'lock-2.png" alt="" /></span> <span class="sidebar-body-text-container">Manage Unlimited Passwords</span>
1122 </li>
1123 <li>
1124 <span class="sidebar-body-image-container"><img src="' . $image_url . 'lock-2.png" alt="" /></span> <span class="sidebar-body-text-container">Set Expiration & Usage Limits</span>
1125 </li>
1126 <li>
1127 <span class="sidebar-body-image-container"><img src="' . $image_url . 'lock-2.png" alt="" /></span> <span class="sidebar-body-text-container">Limit Login Attempts</span>
1128 </li>
1129 <li>
1130 <span class="sidebar-body-image-container"><img src="' . $image_url . 'lock-2.png" alt="" /></span> <span class="sidebar-body-text-container">Create Secure Bypass Links</span>
1131 </li>
1132 <li>
1133 <span class="sidebar-body-image-container"><img src="' . $image_url . 'lock-2.png" alt="" /></span> <span class="sidebar-body-text-container">Lock Screen Customization</span>
1134 </li>
1135 <li>
1136 <span class="sidebar-body-image-container"><img src="' . $image_url . 'lock-2.png" alt="" /></span> <span class="sidebar-body-text-container">Password Access Request</span>
1137 </li>
1138 <li>
1139 <span class="sidebar-body-image-container"><img src="' . $image_url . 'lock-2.png" alt="" /></span> <span class="sidebar-body-text-container">Whitelist User Roles</span>
1140 </li>
1141 <li>
1142 <span class="sidebar-body-image-container"><img src="' . $image_url . 'lock-2.png" alt="" /></span> <span class="sidebar-body-text-container">Track Password Activity</span>
1143 </li>
1144 <li>
1145 <span class="sidebar-body-image-container"><img src="' . $image_url . 'lock-2.png" alt="" /></span> <span class="sidebar-body-text-container">hCaptcha & Cloudflare Turnstile</span>
1146 </li>
1147 </ul>
1148 </div>
1149 <div class="pp-sidebar-footer">
1150 <a target="_blank" href="https://passwordprotectedwp.com/pricing/?utm_source=plugin&utm_medium=side_banner&utm_campaign=plugin">' . esc_html__( 'Upgrade to Premium', 'password-protected' ) . '</a>
1151 </div>
1152 </div>
1153 </div>';
1154 }
1155
1156 public function password_protected_login_designer() {
1157 $search_login_designer = add_query_arg(
1158 array(
1159 's' => 'login designer',
1160 'tab' => 'search',
1161 'type' => 'term',
1162 ),
1163 admin_url( 'plugin-install.php' )
1164 );
1165 echo '<div class="pp-sidebar-widget">
1166 <div id="pp-sidebar-box">
1167 <h3>' .
1168 sprintf(
1169 __( '%1$s Now you can customize your Password Protected screen with the %3$s %2$s', 'password-protected' ),
1170 '🎨',
1171 '🌈',
1172 '<a href="' . $search_login_designer . '">' . __( 'Login Designer Plugin', 'password-protected' ) . '</a>'
1173 )
1174 . '</h3>
1175
1176 <img width="100%" src="'. PASSWORD_PROTECTED_URL .'assets/images/login-designer-demo.gif" alt="Login Designer Demo GIF">
1177
1178 <h3>
1179 <a class="pp-try button-primary" href="' . $search_login_designer . '">
1180 👉 ' . __( 'Try it now! It\'s Free', 'password-protected' ) . '
1181 </a>
1182 </h3>
1183 </div>
1184 </div>';
1185 }
1186
1187 /**
1188 * Pre-update 'password_protected_password' Option
1189 *
1190 * Before the password is saved, MD5 it!
1191 * Doing it in this way allows developers to intercept with an earlier filter if they
1192 * need to do something with the plaintext password.
1193 *
1194 * @param string $newvalue New Value.
1195 * @param string $oldvalue Old Value.
1196 * @return string Filtered new value.
1197 */
1198 public function pre_update_option_password_protected_password( $newvalue, $oldvalue ) {
1199
1200 global $Password_Protected;
1201
1202 if ( $newvalue != $oldvalue ) {
1203 $newvalue = $Password_Protected->encrypt_password( $newvalue );
1204 }
1205
1206 return $newvalue;
1207
1208 }
1209
1210 /**
1211 * Plugin Row Meta
1212 *
1213 * Adds GitHub and translate links below the plugin description on the plugins page.
1214 *
1215 * @param array $plugin_meta Plugin meta display array.
1216 * @param string $plugin_file Plugin reference.
1217 * @param array $plugin_data Plugin data.
1218 * @param string $status Plugin status.
1219 * @return array Plugin meta array.
1220 */
1221 public function plugin_row_meta( $plugin_meta, $plugin_file, $plugin_data, $status ) {
1222
1223 if ( 'password-protected/password-protected.php' == $plugin_file ) {
1224 $plugin_meta[] = sprintf( '<a href="%s">%s</a>', __( 'http://github.com/benhuson/password-protected', 'password-protected' ), __( 'GitHub', 'password-protected' ) );
1225 $plugin_meta[] = sprintf( '<a href="%s">%s</a>', __( 'https://translate.wordpress.org/projects/wp-plugins/password-protected', 'password-protected' ), __( 'Translate', 'password-protected' ) );
1226 }
1227
1228 return $plugin_meta;
1229
1230 }
1231
1232 /**
1233 * Plugin Action Links
1234 *
1235 * Adds settings link on the plugins page.
1236 *
1237 * @param array $actions Plugin action links array.
1238 * @return array Plugin action links array.
1239 */
1240 public function plugin_action_links( $actions ) {
1241
1242 $actions[] = sprintf( '<a href="%s">%s</a>', admin_url( 'admin.php?page=password-protected' ), __( 'Settings', 'password-protected' ) );
1243 return $actions;
1244
1245 }
1246
1247 /**
1248 * Password Admin Notice
1249 * Warns the user if they have enabled password protection but not entered a password
1250 */
1251 public function password_protected_admin_notices() {
1252 global $Password_Protected;
1253
1254 // Check Support
1255 $screens = $this->plugin_screen_ids( array( 'dashboard', 'plugins' ) );
1256 if ( $this->is_current_screen( $screens ) ) {
1257 $supported = $Password_Protected->is_plugin_supported();
1258
1259 if ( is_wp_error( $supported ) ) {
1260 echo $this->admin_error_display( $supported->get_error_message( $supported->get_error_code() ) );
1261 }
1262 }
1263
1264 // Settings
1265 if ( $this->is_current_screen( $this->plugin_screen_ids() ) ) {
1266 $status = get_option( 'password_protected_status' );
1267 $pwd = get_option( 'password_protected_password' );
1268
1269 if ( (bool) $status && empty( $pwd ) ) {
1270 $error_message = __( 'You have enabled password protection but not yet set a password. Please set one below.', 'password-protected' );
1271 $error = apply_filters( 'password_protected_password_status_activation', $error_message );
1272 if( !empty( $error ) ) {
1273 echo $this->admin_error_display( $error );
1274 }
1275 }
1276
1277 if ( current_user_can( 'manage_options' ) && ( (bool) get_option( 'password_protected_administrators' ) || (bool) get_option( 'password_protected_users' ) ) ) {
1278 if ( (bool) get_option( 'password_protected_administrators' ) && (bool) get_option( 'password_protected_users' ) ) {
1279 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' ) );
1280 } elseif ( (bool) get_option( 'password_protected_administrators' ) ) {
1281 if ( (bool) get_option( 'password_protected_status' ) ) {
1282 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' ) );
1283 }
1284 } elseif ( (bool) get_option( 'password_protected_users' ) ) {
1285 if ( (bool) get_option( 'password_protected_status' ) ) {
1286 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' ) );
1287 }
1288 }
1289 }
1290
1291 }
1292
1293 }
1294
1295 /**
1296 * Admin Error Display
1297 *
1298 * Returns a string wrapped in HTML to display an admin error.
1299 *
1300 * @param string $string Error string.
1301 * @return string HTML error.
1302 */
1303 private function admin_error_display( $string ) {
1304
1305 return '<div class="error"><p>' . $string . '</p></div>';
1306
1307 }
1308
1309 /**
1310 * Is Current Screen
1311 *
1312 * Checks wether the admin is displaying a specific screen.
1313 *
1314 * @param string|array $screen_id Admin screen ID(s).
1315 * @return boolean
1316 */
1317 public function is_current_screen( $screen_id ) {
1318
1319 if ( function_exists( 'get_current_screen' ) ) {
1320 $current_screen = get_current_screen();
1321 if ( ! is_array( $screen_id ) ) {
1322 $screen_id = array( $screen_id );
1323 }
1324 if ( in_array( $current_screen->id, $screen_id ) ) {
1325 return true;
1326 }
1327 }
1328
1329 return false;
1330
1331 }
1332
1333 /**
1334 * Plugin Screen IDs
1335 *
1336 * @param string|array $screen_id Additional screen IDs to add to the returned array.
1337 * @return array Screen IDs.
1338 */
1339 public function plugin_screen_ids( $screen_id = '' ) {
1340
1341 $screen_ids = array( 'options-' . $this->options_group, 'settings_page_' . $this->options_group );
1342 array_push( $screen_ids, 'toplevel_page_'.$this->options_group );
1343 if ( ! empty( $screen_id ) ) {
1344 if ( is_array( $screen_id ) ) {
1345 $screen_ids = array_merge( $screen_ids, $screen_id );
1346 } else {
1347 $screen_ids[] = $screen_id;
1348 }
1349 }
1350 // toplevel_page_password-protected
1351 return $screen_ids;
1352
1353 }
1354
1355 /**
1356 * @return bool
1357 * true if password protected pro is installed and activated otherwise false
1358 */
1359 public function password_protected_pro_is_installed_and_activated(): bool {
1360 return class_exists( 'Password_Protected_Pro' );
1361 }
1362
1363 public function login_designer_is_installed_and_activated() {
1364 return class_exists( 'Login_designer' );
1365 }
1366
1367 /**
1368 * @return void
1369 * Display Pro Features
1370 */
1371 public function password_protected_get_pro_features() {
1372 $image_url = PASSWORD_PROTECTED_URL . 'assets/images/';
1373 echo '<div class="pp-pro-banner">
1374 <div class="pp-container">
1375
1376 <div class="pp-banner-header">
1377 <div class="pp-row">
1378 <div class="pp-crown-icon">
1379 <img src="' . $image_url . 'pro-crown.png" />
1380 </div>
1381 <div>
1382 <div class="pp-head-wt-pro-tag">
1383 <p class="pp-sm-txt-heading">Unlock Premium Content Protection Features with</p>
1384 <p class="pp-pro-tag">
1385 PRO
1386 </p>
1387 </div>
1388 <p class="heading-1">Password Protected</p>
1389 </div>
1390 </div>
1391 </div>
1392
1393 <div class="pp-banner-body">
1394 <div class="pp-cols">
1395
1396 <div class="pp-features-list-banner">
1397 <img src="' . $image_url . 'pro-feature-lock.png">
1398 <p>
1399 <a target="_blank" href="https://passwordprotectedwp.com/docs/post-and-page-protection/how-to-secure-all-posts-and-pages/?utm_source=plugin&utm_medium=pro_tab">
1400 Protect Custom Post Types
1401 </a>
1402 </p>
1403 </div>
1404
1405 <div class="pp-features-list-banner">
1406 <img src="' . $image_url . 'pro-feature-lock.png">
1407 <p>
1408 <a target="_blank" href="https://passwordprotectedwp.com/docs/bypass-url/?utm_source=plugin&utm_medium=pro_tab">
1409 Create Secure Bypass Links
1410 </a>
1411 </p>
1412 </div>
1413
1414 <div class="pp-features-list-banner">
1415 <img src="' . $image_url . 'pro-feature-lock.png">
1416 <p>
1417 <a target="_blank" href="https://passwordprotectedwp.com/docs/post-and-page-protection/?utm_source=plugin&utm_medium=pro_tab">
1418 Lock Specific Posts & Pages
1419 </a>
1420 </p>
1421 </div>
1422
1423 <div class="pp-features-list-banner">
1424 <img src="' . $image_url . 'pro-feature-lock.png">
1425 <p>
1426 <a target="_blank" href="https://passwordprotectedwp.com/docs/pro/manage-multiple-websites/?utm_source=plugin&utm_medium=pro_tab">
1427 Manage Unlimited Passwords
1428 </a>
1429 </p>
1430 </div>
1431
1432 <div class="pp-features-list-banner">
1433 <img src="' . $image_url . 'pro-feature-lock.png">
1434 <p>
1435 <a target="_blank" href="https://passwordprotectedwp.com/docs/pro/limit-password-attempts-and-lockdown-time/?utm_source=plugin&utm_medium=pro_tab">
1436 Limit Login Attempts
1437 </a>
1438 </p>
1439 </div>
1440
1441 <div class="pp-features-list-banner">
1442 <img src="' . $image_url . 'pro-feature-lock.png">
1443 <p>
1444 <a target="_blank" href="https://passwordprotectedwp.com/docs/integration/?utm_source=plugin&utm_medium=pro_tab">
1445 hCaptcha & Cloudflare Turnstile
1446 </a>
1447 </p>
1448 </div>
1449
1450 <div class="pp-features-list-banner">
1451 <img src="' . $image_url . 'pro-feature-lock.png">
1452 <p>
1453 <a target="_blank" href="https://passwordprotectedwp.com/docs/pro/customize-your-password-protected-screen/?utm_source=plugin&utm_medium=pro_tab">
1454 Lock Screen Customization
1455 </a>
1456 </p>
1457 </div>
1458
1459 </div>
1460 <div class="pp-cols pp-cols-section-2">
1461
1462 <div class="pp-features-list-banner">
1463 <img src="' . $image_url . 'pro-feature-lock.png">
1464 <p>
1465 <a target="_blank" href="https://passwordprotectedwp.com/docs/pro/partial-content-protection/?utm_source=plugin&utm_medium=pro_tab">
1466 Partial Content Protection
1467 </a>
1468 </p>
1469 </div>
1470
1471 <div class="pp-features-list-banner">
1472 <img src="' . $image_url . 'pro-feature-lock.png">
1473 <p>
1474 <a target="_blank" href="https://passwordprotectedwp.com/docs/pro/password-protect-wp-admin/?utm_source=plugin&utm_medium=pro_tab">
1475 Protect WordPress Login Page
1476 </a>
1477 </p>
1478 </div>
1479
1480 <div class="pp-features-list-banner">
1481 <img src="' . $image_url . 'pro-feature-lock.png">
1482 <p>
1483 <a target="_blank" href="https://passwordprotectedwp.com/docs/pro/exclude-pages-posts-and-post-types/?utm_source=plugin&utm_medium=pro_tab">
1484 Exclude Specific Page, Post, & Product
1485 </a>
1486 </p>
1487 </div>
1488
1489 <div class="pp-features-list-banner">
1490 <img src="' . $image_url . 'pro-feature-lock.png">
1491 <p>
1492 <a target="_blank" href="https://passwordprotectedwp.com/documentation/?utm_source=plugin&utm_medium=pro_tab">
1493 Set Expiration & Usage Limits
1494 </a>
1495 </p>
1496 </div>
1497
1498 <div class="pp-features-list-banner">
1499 <img src="' . $image_url . 'pro-feature-lock.png">
1500 <p>
1501 <a target="_blank" href="https://passwordprotectedwp.com/docs/pro/whitelist-specific-user-roles/?utm_source=plugin&utm_medium=pro_tab">
1502 Whitelist User Roles
1503 </a>
1504 </p>
1505 </div>
1506
1507 <div class="pp-features-list-banner">
1508 <img src="' . $image_url . 'pro-feature-lock.png">
1509 <p>
1510 <a target="_blank" href="https://passwordprotectedwp.com/docs/pro/password-activity-logs/?utm_source=plugin&utm_medium=pro_tab">
1511 Track Password Activity
1512 </a>
1513 </p>
1514 </div>
1515
1516 <div class="pp-features-list-banner">
1517 <img src="' . $image_url . 'pro-feature-lock.png">
1518 <p>
1519 <a target="_blank" href="https://passwordprotectedwp.com/docs/pro/request-access-password/?utm_source=plugin&utm_medium=pro_tab">
1520 Password Access Request
1521 </a>
1522 </p>
1523 </div>
1524
1525 </div>
1526 </div>
1527
1528 <div class="pp-banner-footer">
1529 <a target="_blank" href="https://passwordprotectedwp.com/pricing/?utm_source=plugin&utm_medium=pro_tab&utm_campaign=plugin">' . esc_html__( 'Upgrade to Premium', 'password-protected' ) . '</a>
1530 </div>
1531 </div>
1532 </div>';
1533 }
1534
1535 public function dummy_content( $k ) {
1536 require plugin_dir_path( __FILE__ ) . '../templates/admin/dummy-content.php';
1537 }
1538
1539 public function cache_related_issue() {
1540 echo '<form action="options.php" method="post">';
1541 do_settings_sections( 'password-protected&tab=advanced&sub-tab=cache-issue' );
1542 settings_fields( 'password_protected_cache_issue' );
1543 submit_button();
1544 echo '</form>';
1545 }
1546
1547 }
1548