PluginProbe
LoginPress | wp-login Custom Login Page Customizer / 6.0.0
LoginPress | wp-login Custom Login Page Customizer v6.0.0
6.2.5 6.2.4 6.2.3 6.2.2 6.2.1 trunk 1.0.0 1.0.1 1.0.10 1.0.11 1.0.12 1.0.13 1.0.14 1.0.15 1.0.16 1.0.17 1.0.18 1.0.19 1.0.2 1.0.20 1.0.21 1.0.22 1.0.23 1.0.3 1.0.4 All 118 releases
loginpress / loginpress.php

loginpress.php in LoginPress | wp-login Custom Login Page Customizer 6.0.0, at loginpress.php

923 lines 29.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Plugin Name: LoginPress
4 * Plugin URI: https://loginpress.pro?utm_source=loginpress-lite&utm_medium=plugin-header&utm_campaign=pro-upgrade&utm_content=plugin-uri
5 * Description: LoginPress is the best <code>wp-login</code> Login Page Customizer plugin by <a href="https://wpbrigade.com/?utm_source=loginpress-lite&utm_medium=plugins&utm_campaign=wpbrigade-home&utm_content=WPBrigade-text-link">WPBrigade</a> which allows you to completely change the layout of login, register and forgot password forms.
6 * Version: 6.0.0
7 * Author: LoginPress
8 * Author URI: https://loginpress.pro?utm_source=loginpress-lite&utm_medium=plugin-header&utm_campaign=pro-upgrade&utm_content=author-uri
9 * Text Domain: loginpress
10 * Domain Path: /languages
11 * GitHub Plugin URI: https://github.com/WPBrigade/loginpress
12 *
13 * @package loginpress
14 * @category Core
15 * @author WPBrigade
16 */
17
18
19 if ( ! function_exists( 'loginpress_wpb53407382' ) ) {
20 // Create a helper function for easy SDK access.
21 function loginpress_wpb53407382() {
22 global $loginpress_wpb53407382;
23
24 if ( ! isset( $loginpress_wpb53407382 ) ) {
25 // Include Telemetry SDK.
26 require_once __DIR__ . '/lib/wpb-sdk/start.php';
27
28 $loginpress_wpb53407382 = wpb_dynamic_init(
29 array(
30 'id' => '6',
31 'slug' => 'loginpress',
32 'type' => 'plugin',
33 'public_key' => '1|4aOA8EuyIN4pi2miMvC23LLpnHbBZFNki9R9pVmwd673d3c8',
34 'secret_key' => 'sk_b36c525848fee035',
35 'is_premium' => false,
36 'has_addons' => false,
37 'has_paid_plans' => false,
38 'menu' => array(
39 'slug' => 'loginpress',
40 'account' => false,
41 'support' => false,
42 ),
43 'settings' => array(
44 'loginpress_customization' => '',
45 'loginpress_setting' => '',
46 'loginpress_addon_active_time' => '',
47 'loginpress_addon_dismiss_1' => '',
48 'loginpress_review_dismiss' => '',
49 'loginpress_active_time' => '',
50 '_loginpress_optin' => '',
51 'loginpress_friday_sale_active_time' => '',
52 'loginpress_friday_sale_dismiss' => '',
53 'loginpress_friday_21_sale_dismiss' => '',
54 ),
55 )
56 );
57 }
58
59 return $loginpress_wpb53407382;
60 }
61
62 // Init Telemetry.
63 loginpress_wpb53407382();
64 // Signal that SDK was initiated.
65 do_action( 'loginpress_wpb53407382_loaded' );
66 }
67
68 if ( ! class_exists( 'LoginPress' ) ) :
69
70 final class LoginPress {
71
72 /**
73 * @var string
74 */
75 public $version = '6.0.0';
76
77 /**
78 * @var The single instance of the class
79 * @since 1.0.0
80 */
81 protected static $_instance = null;
82
83 /**
84 * @var WP_Session session
85 */
86 public $session = null;
87
88 /**
89 * @var WP_Query $query
90 */
91 public $query = null;
92
93 /**
94 * @var WP_Countries $countries
95 */
96 public $countries = null;
97
98 /**
99 * Class Constructor.
100 */
101 public function __construct() {
102
103 $this->define_constants();
104 $this->includes();
105 $this->_hooks();
106 }
107
108 /**
109 * Define LoginPress Constants
110 */
111 private function define_constants() {
112
113 $this->define( 'LOGINPRESS_PLUGIN_BASENAME', plugin_basename( __FILE__ ) );
114 $this->define( 'LOGINPRESS_DIR_PATH', plugin_dir_path( __FILE__ ) );
115 $this->define( 'LOGINPRESS_DIR_URL', plugin_dir_url( __FILE__ ) );
116 $this->define( 'LOGINPRESS_ROOT_PATH', __DIR__ . '/' );
117 $this->define( 'LOGINPRESS_ROOT_FILE', __FILE__ );
118 $this->define( 'LOGINPRESS_VERSION', $this->version );
119 $this->define( 'LOGINPRESS_FEEDBACK_SERVER', 'https://wpbrigade.com/' );
120 $this->define( 'LOGINPRESS_REST_NAMESPACE', 'loginpress/v1' );
121 }
122
123 /**
124 * Include required core files used in admin and on the frontend.
125 *
126 * @since 1.0.0
127 * @version 3.0.0
128 */
129 public function includes() {
130
131 include_once LOGINPRESS_DIR_PATH . 'include/compatibility.php';
132 include_once LOGINPRESS_DIR_PATH . 'include/loginpress-allow-domain.php';
133 include_once LOGINPRESS_DIR_PATH . 'custom.php';
134 include_once LOGINPRESS_DIR_PATH . 'classes/class-loginpress-setup.php';
135 include_once LOGINPRESS_DIR_PATH . 'classes/class-loginpress-ajax.php';
136 // include_once( LOGINPRESS_DIR_PATH . 'classes/class-loginpress-filter-plugin.php' );
137 include_once LOGINPRESS_DIR_PATH . 'classes/class-loginpress-developer-hooks.php';
138 include_once LOGINPRESS_DIR_PATH . 'classes/class-loginpress-notifications.php';
139 include_once LOGINPRESS_DIR_PATH . 'include/loginpress-utilities.php';
140 if ( is_multisite() ) {
141 require_once LOGINPRESS_DIR_PATH . 'include/class-loginpress-theme-template.php';
142 }
143
144 $loginpress_setting = get_option( 'loginpress_setting' );
145
146 $loginpress_privacy_policy = isset( $loginpress_setting['enable_privacy_policy'] ) ? $loginpress_setting['enable_privacy_policy'] : 'off';
147 if ( 'off' != $loginpress_privacy_policy ) {
148 include_once LOGINPRESS_DIR_PATH . 'include/privacy-policy.php';
149 }
150
151 $login_with_email = isset( $loginpress_setting['login_order'] ) ? $loginpress_setting['login_order'] : 'default';
152 if ( 'default' != $login_with_email ) {
153 include_once LOGINPRESS_DIR_PATH . 'classes/class-loginpress-login-order.php';
154 new LoginPress_Login_Order();
155 }
156
157 $enable_reg_pass_field = isset( $loginpress_setting['enable_reg_pass_field'] ) ? $loginpress_setting['enable_reg_pass_field'] : 'off';
158 if ( 'off' != $enable_reg_pass_field ) {
159 include_once LOGINPRESS_DIR_PATH . 'classes/class-loginpress-custom-password.php';
160 new LoginPress_Custom_Password();
161 include_once LOGINPRESS_DIR_PATH . 'classes/class-loginpress-pass-strength.php';
162 new LoginPress_Password_Strength();
163 }
164 $loginpress_password_reset_time_limit = isset( $loginpress_setting['loginpress_password_reset_time_limit'] ) ? $loginpress_setting['loginpress_password_reset_time_limit'] : 'off';
165 if ( 'off' != $loginpress_password_reset_time_limit ) {
166 include_once LOGINPRESS_DIR_PATH . 'classes/class-loginpress-force-reset-pass.php';
167 new LoginPress_Force_Password_Reset();
168 }
169 }
170
171 /**
172 * Hook into actions and filters
173 *
174 * @since 1.0.0
175 * @version 3.0.0
176 */
177 private function _hooks() {
178
179 add_action( 'rest_api_init', array( $this, 'loginpress_register_routes' ) );
180 add_action( 'admin_menu', array( $this, 'register_options_page' ) );
181 add_action( 'init', array( $this, 'textdomain' ) );
182 add_filter( 'plugin_row_meta', array( $this, '_row_meta' ), 10, 2 );
183 add_action( 'admin_enqueue_scripts', array( $this, '_admin_scripts' ) );
184 add_action( 'admin_footer', array( $this, 'add_deactivate_modal' ) );
185 add_action( 'plugin_action_links', array( $this, 'loginpress_action_links' ), 10, 2 );
186 add_action( 'admin_init', array( $this, 'redirect_optin' ) );
187 add_filter( 'auth_cookie_expiration', array( $this, '_change_auth_cookie_expiration' ), 10, 3 );
188 add_action( 'wp_wpb_sdk_after_uninstall', array( $this, 'plugin_uninstallation' ) );
189 // add_filter( 'plugins_api', array( $this, 'get_addon_info_' ) , 100, 3 );
190 if ( is_multisite() ) {
191 add_action( 'admin_init', array( $this, 'redirect_loginpress_edit_page' ) );
192 add_action( 'admin_init', array( $this, 'check_loginpress_page' ) );
193 // Makes sure the plugin is defined before trying to use it
194 if ( ! function_exists( 'is_plugin_active_for_network' ) || ! function_exists( 'is_plugin_active' ) ) {
195 require_once ABSPATH . '/wp-admin/includes/plugin.php';
196 if ( is_plugin_active_for_network( 'wordpress-seo/wp-seo.php' ) ) {
197 /**
198 * This filters the ID of the page/post which you want to remove from the sitemap XML.
199 *
200 * @since 1.5.14
201 *
202 * @documentation https://developer.yoast.com/features/xml-sitemaps/api/
203 */
204 add_filter( 'wpseo_exclude_from_sitemap_by_post_ids', array( $this, 'loginpress_exclude_from_sitemap' ) );
205 }
206 }
207 }
208 }
209 /**
210 * Register the rest routes
211 *
212 * @since 6.0.0
213 */
214 public function loginpress_register_routes() {
215 register_rest_route(
216 LOGINPRESS_REST_NAMESPACE,
217 '/settings',
218 array(
219 'methods' => 'GET',
220 'callback' => array( $this, 'loginpress_get_settings' ),
221 'permission_callback' => array( $this, 'loginpress_rest_can_manage_options' ),
222 )
223 );
224
225 register_rest_route(
226 LOGINPRESS_REST_NAMESPACE,
227 '/settings',
228 array(
229 'methods' => 'POST',
230 'callback' => array( $this, 'loginpress_update_settings' ),
231 'permission_callback' => array( $this, 'loginpress_rest_can_manage_options' ),
232 )
233 );
234 }
235
236 /**
237 * Get loginpress settings
238 *
239 * @since 6.0.0
240 */
241 public function loginpress_get_settings( WP_REST_Request $request ) {
242 $settings = get_option( 'loginpress_setting', array() );
243
244 // Convert restrict_domains_textarea from array back to string for frontend
245 if ( isset( $settings['restrict_domains_textarea'] ) ) {
246 if ( is_array( $settings['restrict_domains_textarea'] ) ) {
247 $settings['restrict_domains_textarea'] = implode( "\n", $settings['restrict_domains_textarea'] );
248 }
249 }
250
251 return array(
252 'settings' => $settings,
253 'userRoles' => wp_roles()->roles,
254 'upgradeLink' => loginpress_admin_upgrade_link( 'settings-tab' ),
255 );
256 }
257
258 /**
259 * Update loginpress settings
260 *
261 * @since 6.0.0
262 */
263 public function loginpress_update_settings( WP_REST_Request $request ) {
264 $settings = $request->get_json_params();
265
266 // Process restrict_domains_textarea to convert string to array
267 if ( isset( $settings['restrict_domains_textarea'] ) && is_string( $settings['restrict_domains_textarea'] ) ) {
268 $domains_string = $settings['restrict_domains_textarea'];
269 $domains_array = array();
270
271 // Split by newlines and process each domain
272 $domains = explode( "\n", $domains_string );
273 foreach ( $domains as $domain ) {
274 $domain = trim( $domain );
275 if ( ! empty( $domain ) ) {
276 // Ensure domain starts with @ (compatible with PHP < 8)
277 if ( function_exists( 'str_starts_with' ) ) {
278 if ( ! str_starts_with( $domain, '@' ) ) {
279 $domain = '@' . $domain;
280 }
281 } else {
282 if ( substr( $domain, 0, 1 ) !== '@' ) {
283 $domain = '@' . $domain;
284 }
285 }
286 $domains_array[] = $domain;
287 }
288 }
289
290 // Save as array instead of string
291 $settings['restrict_domains_textarea'] = $domains_array;
292 }
293
294 if ( isset( $settings['reset_settings'] ) && 'on' == $settings['reset_settings'] ) {
295 $loginpress_last_reset = array( 'last_reset_on' => date( 'Y-m-d' ) );
296 update_option( 'loginpress_customization', $loginpress_last_reset );
297 update_option( 'customize_presets_settings', 'minimalist' );
298 $settings['reset_settings'] = 'off';
299 add_action( 'admin_notices', array( $this, 'settings_reset_message' ) );
300 }
301 update_option( 'loginpress_setting', $settings );
302
303 return array( 'success' => true );
304 }
305
306 /**
307 * Check user permissions
308 *
309 * @since 6.0.0
310 */
311 function loginpress_rest_can_manage_options() {
312 return current_user_can( 'manage_options' );
313 }
314
315 /**
316 * Callback function to exclude LoginPress page from sitemap.
317 *
318 * @return bool Exclude page/s or post/s.
319 * @since 1.5.14
320 * @version 1.6.3
321 */
322 public function loginpress_exclude_from_sitemap() {
323
324 $page = get_page_by_path( 'loginpress' );
325 if ( is_object( $page ) ) {
326 return array( $page->ID );
327 }
328 }
329
330 /**
331 * Redirect to Optin page.
332 *
333 * @since 1.0.15
334 */
335 function redirect_optin() {
336
337 /**
338 * Fix the Broken Access Control (BAC) security fix.
339 *
340 * @since 1.6.3
341 */
342 if ( current_user_can( 'manage_options' ) ) {
343 if ( isset( $_POST['loginpress-submit-optout'] ) ) {
344 if ( ! wp_verify_nonce( sanitize_text_field( $_POST['loginpress_submit_optin_nonce'] ), 'loginpress_submit_optin_nonce' ) ) {
345 return;
346 }
347 update_option( '_loginpress_optin', 'no' );
348 // Retrieve WPB SDK existing option and set user_skip
349 $sdk_data = json_decode( get_option( 'wpb_sdk_loginpress' ), true );
350 $sdk_data['user_skip'] = '1';
351 $sdk_data_json = json_encode( $sdk_data );
352 update_option( 'wpb_sdk_loginpress', $sdk_data_json );
353 } elseif ( isset( $_POST['loginpress-submit-optin'] ) ) {
354 if ( ! wp_verify_nonce( sanitize_text_field( $_POST['loginpress_submit_optin_nonce'] ), 'loginpress_submit_optin_nonce' ) ) {
355 return;
356 }
357 update_option( '_loginpress_optin', 'yes' );
358 // WPB SDK OPT IN OPTIONS
359 $sdk_data = array(
360 'communication' => '1',
361 'diagnostic_info' => '1',
362 'extensions' => '1',
363 'user_skip' => '0',
364 );
365 $sdk_data_json = json_encode( $sdk_data );
366 update_option( 'wpb_sdk_loginpress', $sdk_data_json );
367 } elseif ( ! get_option( '_loginpress_optin' ) && isset( $_GET['page'] ) && ( $_GET['page'] === 'loginpress-settings' || $_GET['page'] === 'loginpress' || $_GET['page'] === 'abw' ) ) {
368
369 /**
370 * XSS Attack vector found and fixed.
371 *
372 * @since 1.5.11
373 */
374 $page_redirect = $_GET['page'] === 'loginpress' ? 'loginpress' : 'loginpress-settings';
375 wp_redirect( admin_url( 'admin.php?page=loginpress-optin&redirect-page=' . $page_redirect ) );
376 exit;
377
378 } elseif ( get_option( '_loginpress_optin' ) && ( get_option( '_loginpress_optin' ) == 'yes' ) && isset( $_GET['page'] ) && $_GET['page'] === 'loginpress-optin' ) {
379 wp_redirect( admin_url( 'admin.php?page=loginpress-settings' ) );
380 exit;
381 }
382 }
383 }
384
385 /**
386 * Main Instance
387 *
388 * @since 1.0.0
389 * @static
390 * @see loginPress_loader()
391 * @return Main instance
392 */
393 public static function instance() {
394 if ( is_null( self::$_instance ) ) {
395 self::$_instance = new self();
396 }
397 return self::$_instance;
398 }
399
400 /**
401 * Load Languages
402 *
403 * @since 1.0.0
404 */
405 public function textdomain() {
406
407 $plugin_dir = dirname( plugin_basename( __FILE__ ) );
408 load_plugin_textdomain( 'loginpress', false, $plugin_dir . '/languages/' );
409 }
410
411 /**
412 * Define constant if not already set
413 *
414 * @param string $name
415 * @param string|bool $value
416 */
417 private function define( $name, $value ) {
418 if ( ! defined( $name ) ) {
419 define( $name, $value );
420 }
421 }
422
423 /**
424 * Init WPBrigade when WordPress Initializes.
425 */
426 public function init() {
427 // Before init action
428 }
429
430 /**
431 * Create LoginPress Page Template.
432 *
433 * @since 1.1.3
434 */
435 public function check_loginpress_page() {
436
437 // Retrieve the LoginPress admin page option, that was created during the activation process.
438 $option = $this->get_loginpress_page();
439
440 include LOGINPRESS_DIR_PATH . 'include/create-loginpress-page.php';
441 // Retrieve the status of the page, if the option is available.
442 if ( $option ) {
443 $page = get_post( $option );
444 $status = $page->post_status;
445 } else {
446 $status = null;
447 }
448
449 // Check the status of the page. Let's fix it, if the page is missing or in the trash.
450 if ( empty( $status ) || 'trash' === $status ) {
451 new LoginPress_Page_Create();
452 }
453 }
454
455 /**
456 * function for redirect the LoginPress page on editing.
457 *
458 * @since 1.1.3
459 */
460 public function redirect_loginpress_edit_page() {
461 global $pagenow;
462
463 $page = $this->get_loginpress_page();
464
465 if ( ! $page ) {
466 return;
467 }
468
469 $page_url = get_permalink( $page );
470 $page_id = get_post( $page );
471 $page_id = $page->ID;
472
473 // Generate the redirect url.
474 $url = add_query_arg(
475 array(
476 'autofocus[section]' => 'loginpress_panel',
477 'url' => rawurlencode( $page_url ),
478 ),
479 admin_url( 'customize.php' )
480 );
481
482 /* Check current admin page. */
483 if ( $pagenow == 'post.php' && isset( $_GET['post'] ) && $_GET['post'] == $page_id ) {
484 wp_safe_redirect( $url );
485 }
486 }
487
488 /**
489 * Add new page in Appearance to customize Login Page.
490 *
491 * @version 3.0.0
492 */
493 public function register_options_page() {
494
495 add_submenu_page( 'LoginPress', __( 'Activate', 'loginpress' ), __( 'Activate', 'loginpress' ), 'manage_options', 'loginpress-optin', array( $this, 'render_optin' ) );
496
497 add_theme_page( __( 'LoginPress', 'loginpress' ), __( 'LoginPress', 'loginpress' ), 'manage_options', 'abw', '__return_null' );
498 }
499
500
501 /**
502 * Show Opt-in Page.
503 *
504 * @since 1.0.15
505 */
506 function render_optin() {
507 include LOGINPRESS_DIR_PATH . 'include/loginpress-optin-form.php';
508 }
509
510 /**
511 * Session Expiration
512 *
513 * @since 1.0.18
514 * @version 1.3.2
515 */
516 function _change_auth_cookie_expiration( $expiration, $user_id, $remember ) {
517
518 $loginpress_setting = get_option( 'loginpress_setting' );
519 $_expiration = isset( $loginpress_setting['session_expiration'] ) ? intval( $loginpress_setting['session_expiration'] ) : '';
520
521 /**
522 * return the WordPress default $expiration time if LoginPress Session Expiration time set 0 or empty.
523 *
524 * @since 1.0.18
525 */
526 if ( empty( $_expiration ) || '0' == $_expiration ) {
527 return $expiration;
528 }
529
530 /**
531 * $filter_role Use filter `loginpress_exclude_role_session` for return the role.
532 * By default it's false and $expiration time will apply on all user.
533 *
534 * @return string/array role name.
535 * @since 1.3.2
536 */
537 $filter_role = apply_filters( 'loginpress_exclude_role_session', false );
538
539 if ( $filter_role ) {
540 $user_roles = get_userdata( $user_id )->roles;
541
542 // if $filter_role is array, return the default $expiration for each defined role.
543 if ( is_array( $filter_role ) ) {
544 foreach ( $filter_role as $role ) {
545 if ( in_array( $role, $user_roles ) ) {
546 return $expiration;
547 }
548 }
549 } elseif ( in_array( $filter_role, $user_roles ) ) {
550 return $expiration;
551 }
552 }
553
554 // Convert Duration (minutes) of the expiration period in seconds.
555 $expiration = $_expiration * 60;
556
557 return $expiration;
558 }
559
560 /**
561 * Load JS or CSS files at admin side and enqueue them
562 *
563 * @param string tell you the Page ID
564 * @return void
565 * @version 3.0.0
566 */
567 function _admin_scripts( $hook ) {
568 if ( $hook === 'toplevel_page_loginpress-settings' ) {
569 wp_enqueue_script( 'youtube-api', 'https://www.youtube.com/iframe_api', array(), null, true );
570
571 $js_code = '
572 var ytPlayers = {};
573
574 function onYouTubeIframeAPIReady() {
575 var iframes = document.querySelectorAll("iframe.loginPress-feature-video");
576
577 Array.prototype.forEach.call(iframes, function(iframe) {
578 // Assign a unique ID if not present
579 if (!iframe.id) {
580 iframe.id = "yt-player-" + Math.random().toString(36).substring(2, 15);
581 }
582
583 var id = iframe.id;
584
585 ytPlayers[id] = new YT.Player(id, {
586 events: {
587 "onStateChange": function(event) {
588 handleStateChange(event, id);
589 }
590 }
591 });
592 });
593 }
594
595 function handleStateChange(event, currentId) {
596 if (event.data === YT.PlayerState.PLAYING) {
597 for (var id in ytPlayers) {
598 if (ytPlayers.hasOwnProperty(id) && id !== currentId) {
599 var player = ytPlayers[id];
600 if (typeof player.pauseVideo === "function") {
601 player.pauseVideo();
602 }
603 }
604 }
605 }
606 }
607 ';
608
609 wp_add_inline_script( 'youtube-api', $js_code );
610 }
611
612 $should_load = ( $hook == 'toplevel_page_loginpress-settings' || $hook == 'loginpress_page_loginpress-addons' || $hook == 'loginpress_page_loginpress-help' || $hook == 'loginpress_page_loginpress-import-export' || $hook == 'loginpress_page_loginpress-license' || $hook == 'admin_page_loginpress-optin' );
613
614 if ( version_compare( LOGINPRESS_VERSION, '6.0.0', '>=' ) ) {
615 if ( $should_load || 'users.php' == $hook ) {
616 // Register script first with all parameters
617 wp_register_script( 'loginpress-react-settings', LOGINPRESS_DIR_URL . 'build/index.js', array( 'wp-element', 'wp-i18n', 'wp-api-fetch' ), LOGINPRESS_VERSION, true );
618
619 // Enqueue the registered script
620 wp_enqueue_script( 'loginpress-react-settings' );
621 wp_enqueue_style( 'loginpress_style_react', plugins_url( 'build/index.css', __FILE__ ), array(), LOGINPRESS_VERSION );
622
623 // Set translations
624 wp_set_script_translations( 'loginpress-react-settings', 'loginpress', LOGINPRESS_DIR_PATH . 'languages' );
625
626 // Localize script data
627 $is_pro_active = false;
628 if ( is_plugin_active( 'loginpress-pro/loginpress-pro.php' ) ) {
629 $is_pro_active = true;
630 }
631 $languages = ! empty( get_available_languages() );
632
633 wp_localize_script(
634 'loginpress-react-settings',
635 'loginpressReactData',
636 array(
637 'ajaxUrl' => admin_url( 'admin-ajax.php' ),
638 'isProActive' => $is_pro_active,
639 'wp_login_url' => wp_login_url(),
640 'language_switcher' => $languages,
641 )
642 );
643 }
644 }
645
646 if ( $should_load ) {
647 wp_enqueue_style( 'loginpress_style', plugins_url( 'css/style.css', __FILE__ ), array(), LOGINPRESS_VERSION );
648 wp_enqueue_script( 'loginpress_js', plugins_url( 'js/admin-custom.js', __FILE__ ), array(), LOGINPRESS_VERSION );
649
650 // Array for localize.
651 $loginpress_localize = array(
652 'plugin_url' => plugins_url(),
653 'localize_translations' => array(
654 _x( 'Name', 'Login Redirect Roles', 'loginpress' ),
655 ),
656 'help_nonce' => wp_create_nonce( 'loginpress-log-nonce' ),
657
658 );
659
660 wp_localize_script( 'loginpress_js', 'loginpress_script', $loginpress_localize );
661 }
662 }
663
664 /**
665 * Add rating icon on plugins page.
666 *
667 * @since 1.0.9
668 * @version 1.1.22
669 */
670 public function _row_meta( $meta_fields, $file ) {
671
672 if ( $file != 'loginpress/loginpress.php' ) {
673 return $meta_fields;
674 }
675
676 echo '<style>.loginpress-rate-stars { display: inline-block; color: #ffb900; position: relative; top: 3px; }.loginpress-rate-stars svg{ fill:#ffb900; } .loginpress-rate-stars svg:hover{ fill:#ffb900 } .loginpress-rate-stars svg:hover ~ svg{ fill:none; } </style>';
677
678 $plugin_rate = 'https://wordpress.org/support/plugin/loginpress/reviews/?rate=5#rate-response';
679 $plugin_filter = 'https://wordpress.org/support/plugin/loginpress/reviews/?filter=5';
680 $svg_xmlns = 'https://www.w3.org/2000/svg';
681 $svg_icon = '';
682
683 for ( $i = 0; $i < 5; $i++ ) {
684 $svg_icon .= "<svg xmlns='" . esc_url( $svg_xmlns ) . "' width='15' height='15' viewBox='0 0 24 24' fill='none' stroke='currentColor' stroke-width='2' stroke-linecap='round' stroke-linejoin='round' class='feather feather-star'><polygon points='12 2 15.09 8.26 22 9.27 17 14.14 18.18 21.02 12 17.77 5.82 21.02 7 14.14 2 9.27 8.91 8.26 12 2'/></svg>";
685 }
686
687 // Set icon for thumbs up.
688 $meta_fields[] = '<a href="' . esc_url( $plugin_filter ) . '" target="_blank"><span class="dashicons dashicons-thumbs-up"></span>' . __( 'Vote!', 'loginpress' ) . '</a>';
689
690 // Set icon for 5-star reviews. v1.1.22
691 $meta_fields[] = "<a href='" . esc_url( $plugin_rate ) . "' target='_blank' title='" . esc_html__( 'Rate', 'loginpress' ) . "'><i class='loginpress-rate-stars'>" . $svg_icon . '</i></a>';
692
693 return $meta_fields;
694 }
695
696 /**
697 * Add deactivate modal layout.
698 */
699 function add_deactivate_modal() {
700 global $pagenow;
701
702 if ( 'plugins.php' !== $pagenow ) {
703 return;
704 }
705
706 include LOGINPRESS_DIR_PATH . 'include/loginpress-optout-form.php';
707 }
708
709 /**
710 * Plugin activation
711 *
712 * @since 1.0.15
713 * @version 1.0.22
714 */
715 static function plugin_activation() {
716
717 $loginpress_key = get_option( 'loginpress_customization' );
718 $loginpress_setting = get_option( 'loginpress_setting' );
719
720 // Create a key 'loginpress_customization' with empty array.
721 if ( ! $loginpress_key ) {
722 update_option( 'loginpress_customization', array() );
723 }
724
725 // Create a key 'loginpress_setting' with empty array.
726 if ( ! $loginpress_setting ) {
727 update_option( 'loginpress_setting', array() );
728 }
729 }
730
731 function plugin_uninstallation() {
732 include_once LOGINPRESS_DIR_PATH . 'include/uninstall.php';
733 }
734
735
736 /**
737 * Pull the LoginPress page from options.
738 *
739 * @access public
740 * @since 1.1.3
741 * @version 1.1.7
742 */
743 public function get_loginpress_page() {
744
745 $loginpress_setting = get_option( 'loginpress_setting', array() );
746 if ( ! is_array( $loginpress_setting ) && empty( $loginpress_setting ) ) {
747 $loginpress_setting = array();
748 }
749 $page = array_key_exists( 'loginpress_page', $loginpress_setting ) ? get_post( $loginpress_setting['loginpress_page'] ) : false;
750
751 return $page;
752 }
753
754
755 /**
756 * Add a link to the settings page to the plugins list
757 *
758 * @since 1.0.11
759 * @version 3.0.8
760 */
761 public function loginpress_action_links( $links, $file ) {
762
763 static $this_plugin;
764
765 if ( empty( $this_plugin ) ) {
766 $this_plugin = 'loginpress/loginpress.php';
767 }
768
769 if ( $file == $this_plugin ) {
770 // Build the initial settings and customize links
771 $settings_link = sprintf(
772 // translators: Build links
773 esc_html__( '%1$s Settings %2$s | %3$s Customize %4$s', 'loginpress' ),
774 '<a href="' . admin_url( 'admin.php?page=loginpress-settings' ) . '">',
775 '</a>',
776 '<a href="' . admin_url( 'admin.php?page=loginpress' ) . '">',
777 '</a>'
778 );
779
780 // Retrieve WPB SDK Opt Out options
781 $sdk_data = json_decode( get_option( 'wpb_sdk_loginpress' ), true );
782
783 // Set default values for options
784 $communication = isset( $sdk_data['communication'] ) ? $sdk_data['communication'] : false;
785 $diagnostic_info = isset( $sdk_data['diagnostic_info'] ) ? $sdk_data['diagnostic_info'] : false;
786 $extensions = isset( $sdk_data['extensions'] ) ? $sdk_data['extensions'] : false;
787
788 // Determine the opt-in state and whether all options are false
789 $is_optin = 'yes' == get_option( '_loginpress_optin' );
790 $all_options_false = $communication === false && $diagnostic_info === false && $extensions === false;
791
792 // Build the settings link based on the option states
793 if ( $communication || $diagnostic_info || $extensions ) {
794 $settings_link .= sprintf(
795 // translators: links based on opt in
796 esc_html__( ' | %1$s Opt Out %2$s ', 'loginpress' ),
797 '<a class="opt-out" href="' . admin_url( 'admin.php?page=loginpress-settings' ) . '">',
798 '</a>'
799 );
800 } elseif ( $is_optin ) {
801 if ( $all_options_false ) {
802 // Case 1: Old users without any settings (meaning all options are false)
803 // Ensure old users remain fully opted in by setting all options to true.
804 $sdk_data = json_encode(
805 array(
806 'communication' => '1',
807 'diagnostic_info' => '1',
808 'extensions' => '1',
809 'user_skip' => '0',
810 )
811 );
812 update_option( 'wpb_sdk_loginpress', $sdk_data );
813 $settings_link .= sprintf(
814 // translators: setting link when opted out
815 esc_html__( ' | %1$s Opt Out %2$s ', 'loginpress' ),
816 '<a class="opt-out" href="' . admin_url( 'admin.php?page=loginpress-settings' ) . '">',
817 '</a>'
818 );
819 } else {
820 // If opted in and not all options are false, update the opt-in state
821 update_option( '_loginpress_optin', 'no' );
822 // Display opt-in link
823 $settings_link .= sprintf(
824 // translators: Update opt-in state
825 esc_html__( ' | %1$s Opt In %2$s ', 'loginpress' ),
826 '<a href="' . admin_url( 'admin.php?page=loginpress-optin&redirect-page=loginpress-settings' ) . '">',
827 '</a>'
828 );
829 }
830
831 // Display opt-out link
832 } else {
833 $settings_link .= sprintf(
834 // translators: Opt-out link
835 esc_html__( ' | %1$s Opt In %2$s ', 'loginpress' ),
836 '<a href="' . admin_url( 'admin.php?page=loginpress-optin&redirect-page=loginpress-settings' ) . '">',
837 '</a>'
838 );
839 }
840
841 // Add the settings link to the array
842 array_unshift( $links, $settings_link );
843
844 // Add Pro upgrade link if not already present
845 if ( ! has_action( 'loginpress_pro_add_template' ) ) {
846 $pro_link = sprintf(
847 // translators: Pro upgrade link
848 esc_html__( '%1$s %3$s Upgrade Pro %4$s %2$s', 'loginpress' ),
849 '<a href="https://loginpress.pro/lite/?utm_source=loginpress-lite&utm_medium=plugins&utm_campaign=pro-upgrade&utm_content=Upgrade+Pro" target="_blank">',
850 '</a>',
851 '<span class="loginpress-dashboard-pro-link">',
852 '</span>'
853 );
854 array_push( $links, $pro_link );
855 }
856 }
857
858 return $links;
859 }
860
861 // function get_addon_info_( $api, $action, $args ) {
862
863 // if ( $action == 'plugin_information' && empty( $api ) && ( ! empty( $_GET['lgp'] ) ) ) {
864
865 // $raw_response = wp_remote_post( 'https://wpbrigade.com/loginpress-api/search.php', array(
866 // 'body' => array(
867 // 'slug' => $args->slug
868 // ) )
869 // );
870
871 // if ( is_wp_error( $raw_response ) || $raw_response['response']['code'] != 200 ) {
872 // return false;
873 // }
874
875 // $plugin = unserialize( $raw_response['body'] );
876
877 // $api = new stdClass();
878 // $api->name = $plugin['title'];
879 // $api->version = $plugin['version'];
880 // $api->download_link = $plugin['download_url'];
881 // $api->tested = '10.0';
882
883 // }
884
885 // return $api;
886 // }
887 } // End Of Class.
888 endif;
889
890
891 /**
892 * Returns the main instance of WP to prevent the need to use globals.
893 *
894 * @since 1.0.0
895 * @return LoginPress
896 */
897 function loginPress_loader() {
898 return LoginPress::instance();
899 }
900
901 // Call the function
902 loginPress_loader();
903
904 /**
905 * Create the Object of Custom Login Entities and Settings.
906 *
907 * @since 1.0.0
908 */
909 new LoginPress_Entities();
910 new LoginPress_Settings();
911
912 /**
913 * Create the Object of Remote Notification.
914 *
915 * @since 1.0.9
916 */
917 if ( ! class_exists( 'TAV_Remote_Notification_Client' ) ) {
918 require LOGINPRESS_ROOT_PATH . 'include/class-remote-notification-client.php';
919 }
920 $notification = new TAV_Remote_Notification_Client( 125, '16765c0902705d62', 'https://wpbrigade.com?post_type=notification' );
921
922 register_activation_hook( __FILE__, array( 'LoginPress', 'plugin_activation' ) );
923