| 1 |
<?php // phpcs:ignore WordPress.Files.FileName.InvalidClassFileName |
| 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.2.5 |
| 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 |
* Requires at least: 4.0 |
| 12 |
* Tested up to: 7.0 |
| 13 |
* License: GPLv2 or later |
| 14 |
* GitHub Plugin URI: https://github.com/WPBrigade/loginpress |
| 15 |
* |
| 16 |
* @package loginpress |
| 17 |
* @category Core |
| 18 |
* @author WPBrigade |
| 19 |
* |
| 20 |
* phpcs:disable Universal.Files.SeparateFunctionsFromOO.Mixed |
| 21 |
*/ |
| 22 |
|
| 23 |
if ( ! defined( 'ABSPATH' ) ) { |
| 24 |
exit; |
| 25 |
} |
| 26 |
|
| 27 |
|
| 28 |
// Define constants for PHPStan. |
| 29 |
if ( ! defined( 'LOGINPRESS_PLUGIN_BASENAME' ) ) { |
| 30 |
define( 'LOGINPRESS_PLUGIN_BASENAME', plugin_basename( __FILE__ ) ); |
| 31 |
} |
| 32 |
if ( ! defined( 'LOGINPRESS_DIR_PATH' ) ) { |
| 33 |
define( 'LOGINPRESS_DIR_PATH', plugin_dir_path( __FILE__ ) ); |
| 34 |
} |
| 35 |
if ( ! defined( 'LOGINPRESS_DIR_URL' ) ) { |
| 36 |
define( 'LOGINPRESS_DIR_URL', plugin_dir_url( __FILE__ ) ); |
| 37 |
} |
| 38 |
if ( ! defined( 'LOGINPRESS_ROOT_PATH' ) ) { |
| 39 |
define( 'LOGINPRESS_ROOT_PATH', __DIR__ . '/' ); |
| 40 |
} |
| 41 |
if ( ! defined( 'LOGINPRESS_ROOT_FILE' ) ) { |
| 42 |
define( 'LOGINPRESS_ROOT_FILE', __FILE__ ); |
| 43 |
} |
| 44 |
if ( ! defined( 'LOGINPRESS_VERSION' ) ) { |
| 45 |
define( 'LOGINPRESS_VERSION', '6.2.5' ); |
| 46 |
} |
| 47 |
if ( ! defined( 'LOGINPRESS_FEEDBACK_SERVER' ) ) { |
| 48 |
define( 'LOGINPRESS_FEEDBACK_SERVER', 'https://wpbrigade.com/' ); |
| 49 |
} |
| 50 |
if ( ! defined( 'LOGINPRESS_REST_NAMESPACE' ) ) { |
| 51 |
define( 'LOGINPRESS_REST_NAMESPACE', 'loginpress/v1' ); |
| 52 |
} |
| 53 |
|
| 54 |
if ( ! function_exists( 'loginpress_wpb53407382' ) ) { |
| 55 |
/** |
| 56 |
* Create a helper function for easy SDK access. |
| 57 |
* |
| 58 |
* @return mixed |
| 59 |
*/ |
| 60 |
function loginpress_wpb53407382() { |
| 61 |
global $loginpress_wpb53407382; |
| 62 |
|
| 63 |
if ( ! isset( $loginpress_wpb53407382 ) || ! is_array( $loginpress_wpb53407382 ) ) { |
| 64 |
require_once __DIR__ . '/lib/wpb-sdk/start.php'; |
| 65 |
|
| 66 |
/** |
| 67 |
* Initialize WPB SDK. |
| 68 |
* |
| 69 |
* @phpstan-ignore-next-line |
| 70 |
*/ |
| 71 |
$loginpress_wpb53407382 = wpb_sdk_dynamic_init( |
| 72 |
array( |
| 73 |
'id' => '6', |
| 74 |
'slug' => 'loginpress', |
| 75 |
'type' => 'plugin', |
| 76 |
'plugin_file' => __FILE__, |
| 77 |
'sdk_views_dir' => __DIR__ . '/lib/wpb-sdk/views', |
| 78 |
'public_key' => '1|4aOA8EuyIN4pi2miMvC23LLpnHbBZFNki9R9pVmwd673d3c8', |
| 79 |
'secret_key' => 'sk_b36c525848fee035', |
| 80 |
'is_premium' => false, |
| 81 |
'has_addons' => false, |
| 82 |
'has_paid_plans' => false, |
| 83 |
'optin_user_meta' => array( |
| 84 |
'token' => '_loginpress_verification_token', |
| 85 |
'email_verified' => '_loginpress_email_verified', |
| 86 |
), |
| 87 |
'optin' => array( |
| 88 |
'verify_query_arg' => 'loginpress_optin_verify', |
| 89 |
'option_name' => '_loginpress_optin', |
| 90 |
'settings_page' => 'loginpress-settings', |
| 91 |
'optin_page' => 'loginpress-optin', |
| 92 |
), |
| 93 |
'menu' => array( |
| 94 |
'slug' => 'loginpress', |
| 95 |
'account' => false, |
| 96 |
'support' => false, |
| 97 |
), |
| 98 |
'settings' => array( |
| 99 |
'loginpress_customization' => '', |
| 100 |
'loginpress_setting' => '', |
| 101 |
'loginpress_addon_active_time' => '', |
| 102 |
'loginpress_addon_dismiss_1' => '', |
| 103 |
'loginpress_review_dismiss' => '', |
| 104 |
'loginpress_active_time' => '', |
| 105 |
'_loginpress_optin' => '', |
| 106 |
'wpb_sdk_loginpress' => '', |
| 107 |
'wpb_sdk_loginpress_fallback_verify_token' => '', |
| 108 |
'wpb_sdk_loginpress_initial_log_sent' => '', |
| 109 |
'loginpress_friday_sale_active_time' => '', |
| 110 |
'loginpress_friday_sale_dismiss' => '', |
| 111 |
'loginpress_friday_21_sale_dismiss' => '', |
| 112 |
), |
| 113 |
) |
| 114 |
); |
| 115 |
} |
| 116 |
|
| 117 |
return $loginpress_wpb53407382; |
| 118 |
} |
| 119 |
|
| 120 |
loginpress_wpb53407382(); |
| 121 |
do_action( 'loginpress_wpb53407382_loaded' ); |
| 122 |
} |
| 123 |
|
| 124 |
if ( ! class_exists( 'LoginPress' ) ) : |
| 125 |
// REST endpoints moved into a trait to keep main file slimmer. |
| 126 |
require_once plugin_dir_path( __FILE__ ) . 'classes/traits/loginpress-rest-trait.php'; |
| 127 |
|
| 128 |
/** |
| 129 |
* LoginPress Main Class |
| 130 |
* |
| 131 |
* Main LoginPress plugin class. |
| 132 |
* |
| 133 |
* @package LoginPress |
| 134 |
* @since 1.0.0 |
| 135 |
* @version 6.2.5 |
| 136 |
*/ |
| 137 |
final class LoginPress { |
| 138 |
use LoginPress_Rest_Trait; |
| 139 |
|
| 140 |
/** |
| 141 |
* Plugin version number. |
| 142 |
* |
| 143 |
* @var string Current version of the LoginPress plugin. |
| 144 |
*/ |
| 145 |
public $version = '6.2.5'; |
| 146 |
|
| 147 |
/** |
| 148 |
* The single instance of the LoginPress class. |
| 149 |
* |
| 150 |
* @var LoginPress|null Singleton instance of the LoginPress class. |
| 151 |
* @since 1.0.0 |
| 152 |
* |
| 153 |
* phpcs:disable PSR2.Classes.PropertyDeclaration.Underscore |
| 154 |
*/ |
| 155 |
protected static $_instance = null; |
| 156 |
|
| 157 |
/** |
| 158 |
* Session data storage. |
| 159 |
* |
| 160 |
* @var mixed WordPress session data or null if not set. |
| 161 |
*/ |
| 162 |
public $session = null; |
| 163 |
|
| 164 |
/** |
| 165 |
* Database query object. |
| 166 |
* |
| 167 |
* @var mixed WordPress database query object or null if not set. |
| 168 |
*/ |
| 169 |
public $query = null; |
| 170 |
|
| 171 |
/** |
| 172 |
* Countries data for forms. |
| 173 |
* |
| 174 |
* @var mixed Array of countries data or null if not loaded. |
| 175 |
*/ |
| 176 |
public $countries = null; |
| 177 |
|
| 178 |
/** |
| 179 |
* Class Constructor. |
| 180 |
* |
| 181 |
* @since 1.0.0 |
| 182 |
* @version 6.0.0 |
| 183 |
* @return void |
| 184 |
*/ |
| 185 |
public function __construct() { |
| 186 |
$this->define_constants(); |
| 187 |
$this->includes(); |
| 188 |
$this->_hooks(); |
| 189 |
} |
| 190 |
|
| 191 |
/** |
| 192 |
* Define LoginPress Constants. |
| 193 |
* |
| 194 |
* @return void |
| 195 |
*/ |
| 196 |
private function define_constants() { |
| 197 |
|
| 198 |
$this->define( 'LOGINPRESS_PLUGIN_BASENAME', plugin_basename( __FILE__ ) ); |
| 199 |
$this->define( 'LOGINPRESS_DIR_PATH', plugin_dir_path( __FILE__ ) ); |
| 200 |
$this->define( 'LOGINPRESS_DIR_URL', plugin_dir_url( __FILE__ ) ); |
| 201 |
$this->define( 'LOGINPRESS_ROOT_PATH', __DIR__ . '/' ); |
| 202 |
$this->define( 'LOGINPRESS_ROOT_FILE', __FILE__ ); |
| 203 |
$this->define( 'LOGINPRESS_VERSION', $this->version ); |
| 204 |
$this->define( 'LOGINPRESS_FEEDBACK_SERVER', 'https://wpbrigade.com/' ); |
| 205 |
$this->define( 'LOGINPRESS_REST_NAMESPACE', 'loginpress/v1' ); |
| 206 |
} |
| 207 |
|
| 208 |
/** |
| 209 |
* Include required core files used in admin and on the frontend. |
| 210 |
* |
| 211 |
* @since 1.0.0 |
| 212 |
* @version 3.0.0 |
| 213 |
* @return void |
| 214 |
*/ |
| 215 |
public function includes() { |
| 216 |
|
| 217 |
include_once LOGINPRESS_DIR_PATH . 'include/class-loginpress-compatibility.php'; |
| 218 |
include_once LOGINPRESS_DIR_PATH . 'include/class-loginpress-domains.php'; |
| 219 |
include_once LOGINPRESS_DIR_PATH . 'classes/customizer/class-loginpress-customizer.php'; |
| 220 |
include_once LOGINPRESS_DIR_PATH . 'classes/class-loginpress-setup.php'; |
| 221 |
include_once LOGINPRESS_DIR_PATH . 'classes/class-loginpress-ajax.php'; |
| 222 |
include_once LOGINPRESS_DIR_PATH . 'classes/class-loginpress-developer-hooks.php'; |
| 223 |
include_once LOGINPRESS_DIR_PATH . 'classes/class-loginpress-notifications.php'; |
| 224 |
include_once LOGINPRESS_DIR_PATH . 'include/loginpress-utilities.php'; |
| 225 |
if ( is_multisite() ) { |
| 226 |
require_once LOGINPRESS_DIR_PATH . 'include/class-loginpress-theme-template.php'; |
| 227 |
} |
| 228 |
|
| 229 |
$loginpress_setting = get_option( 'loginpress_setting' ); |
| 230 |
|
| 231 |
$loginpress_privacy_policy = isset( $loginpress_setting['enable_privacy_policy'] ) ? $loginpress_setting['enable_privacy_policy'] : 'off'; |
| 232 |
if ( 'off' !== $loginpress_privacy_policy ) { |
| 233 |
include_once LOGINPRESS_DIR_PATH . 'include/privacy-policy.php'; |
| 234 |
} |
| 235 |
|
| 236 |
$login_with_email = isset( $loginpress_setting['login_order'] ) ? $loginpress_setting['login_order'] : 'default'; |
| 237 |
if ( 'default' !== $login_with_email ) { |
| 238 |
include_once LOGINPRESS_DIR_PATH . 'classes/class-loginpress-login-order.php'; |
| 239 |
new LoginPress_Login_Order(); |
| 240 |
} |
| 241 |
|
| 242 |
$enable_reg_pass_field = isset( $loginpress_setting['enable_reg_pass_field'] ) ? $loginpress_setting['enable_reg_pass_field'] : 'off'; |
| 243 |
if ( 'off' !== $enable_reg_pass_field ) { |
| 244 |
include_once LOGINPRESS_DIR_PATH . 'classes/class-loginpress-custom-password.php'; |
| 245 |
new LoginPress_Custom_Password(); |
| 246 |
include_once LOGINPRESS_DIR_PATH . 'classes/class-loginpress-password-strength.php'; |
| 247 |
new LoginPress_Password_Strength(); |
| 248 |
} |
| 249 |
$loginpress_password_reset_time_limit = isset( $loginpress_setting['loginpress_password_reset_time_limit'] ) ? $loginpress_setting['loginpress_password_reset_time_limit'] : 'off'; |
| 250 |
if ( 'off' !== $loginpress_password_reset_time_limit ) { |
| 251 |
include_once LOGINPRESS_DIR_PATH . 'classes/class-loginpress-force-password-reset.php'; |
| 252 |
new LoginPress_Force_Password_Reset(); |
| 253 |
} |
| 254 |
} |
| 255 |
|
| 256 |
/** |
| 257 |
* Hook into actions and filters |
| 258 |
* |
| 259 |
* @since 1.0.0 |
| 260 |
* @version 3.0.0 |
| 261 |
* @return void |
| 262 |
* |
| 263 |
* phpcs:disable PSR2.Methods.MethodDeclaration.Underscore |
| 264 |
*/ |
| 265 |
private function _hooks() { |
| 266 |
add_action( 'rest_api_init', array( $this, 'loginpress_register_routes' ) ); |
| 267 |
add_action( 'admin_menu', array( $this, 'register_options_page' ) ); |
| 268 |
add_action( 'init', array( $this, 'textdomain' ) ); |
| 269 |
add_filter( 'plugin_row_meta', array( $this, '_row_meta' ), 10, 2 ); |
| 270 |
add_action( 'admin_enqueue_scripts', array( $this, '_admin_scripts' ) ); |
| 271 |
add_filter( 'plugin_action_links', array( $this, 'loginpress_action_links' ), 10, 2 ); |
| 272 |
add_action( 'admin_init', array( $this, 'redirect_optin' ) ); |
| 273 |
add_filter( 'auth_cookie_expiration', array( $this, '_change_auth_cookie_expiration' ), 10, 3 ); |
| 274 |
add_action( 'wp_wpb_sdk_after_uninstall', array( $this, 'plugin_uninstallation' ) ); |
| 275 |
if ( is_multisite() ) { |
| 276 |
add_action( 'admin_init', array( $this, 'redirect_loginpress_edit_page' ) ); |
| 277 |
add_action( 'admin_init', array( $this, 'check_loginpress_page' ) ); |
| 278 |
// Makes sure the plugin is defined before trying to use it. |
| 279 |
if ( ! function_exists( 'is_plugin_active_for_network' ) || ! function_exists( 'is_plugin_active' ) ) { |
| 280 |
/** |
| 281 |
* Include plugin functions. |
| 282 |
* |
| 283 |
* @phpstan-ignore-next-line |
| 284 |
*/ |
| 285 |
require_once ABSPATH . '/wp-admin/includes/plugin.php'; |
| 286 |
if ( is_plugin_active_for_network( 'wordpress-seo/wp-seo.php' ) ) { |
| 287 |
/** |
| 288 |
* This filters the ID of the page/post which you want to remove from the sitemap XML. |
| 289 |
* |
| 290 |
* @since 1.5.14 |
| 291 |
* |
| 292 |
* @documentation https://developer.yoast.com/features/xml-sitemaps/api/ |
| 293 |
*/ |
| 294 |
add_filter( 'wpseo_exclude_from_sitemap_by_post_ids', array( $this, 'loginpress_exclude_from_sitemap' ) ); |
| 295 |
} |
| 296 |
} |
| 297 |
} |
| 298 |
} |
| 299 |
|
| 300 |
/** |
| 301 |
* Callback function to exclude LoginPress page from sitemap. |
| 302 |
* |
| 303 |
* @return array<int>|false Exclude page/s or post/s. |
| 304 |
* @since 1.5.14 |
| 305 |
* @version 1.6.3 |
| 306 |
*/ |
| 307 |
public function loginpress_exclude_from_sitemap() { |
| 308 |
|
| 309 |
$page = get_page_by_path( 'loginpress' ); |
| 310 |
if ( is_object( $page ) ) { |
| 311 |
// This is used as a filter callback, so we need to return the array |
| 312 |
// even though the action expects void return. |
| 313 |
return array( $page->ID ); |
| 314 |
} |
| 315 |
return false; |
| 316 |
} |
| 317 |
|
| 318 |
/** |
| 319 |
* Redirect to Optin page. |
| 320 |
* |
| 321 |
* @since 1.0.15 |
| 322 |
* @return void |
| 323 |
*/ |
| 324 |
public function redirect_optin() { |
| 325 |
if ( ! current_user_can( 'manage_options' ) ) { |
| 326 |
return; |
| 327 |
} |
| 328 |
|
| 329 |
// phpcs:disable WordPress.Security.NonceVerification.Recommended -- Read-only `page` admin query arg for redirect routing (not POST form data). |
| 330 |
$page = isset( $_GET['page'] ) ? sanitize_text_field( wp_unslash( (string) $_GET['page'] ) ) : ''; |
| 331 |
|
| 332 |
if ( |
| 333 |
$page |
| 334 |
&& in_array( $page, array( 'loginpress-settings', 'loginpress', 'abw' ), true ) |
| 335 |
&& ! get_option( '_loginpress_optin' ) |
| 336 |
) { |
| 337 |
$page_redirect = 'loginpress' === $page ? 'loginpress' : 'loginpress-settings'; |
| 338 |
wp_safe_redirect( admin_url( 'admin.php?page=loginpress-optin&redirect-page=' . rawurlencode( $page_redirect ) ) ); |
| 339 |
exit; |
| 340 |
} |
| 341 |
|
| 342 |
if ( |
| 343 |
get_option( '_loginpress_optin' ) |
| 344 |
&& 'yes' === get_option( '_loginpress_optin' ) |
| 345 |
&& isset( $_GET['page'] ) |
| 346 |
&& 'loginpress-optin' === sanitize_text_field( wp_unslash( (string) $_GET['page'] ) ) |
| 347 |
) { |
| 348 |
wp_safe_redirect( admin_url( 'admin.php?page=loginpress-settings' ) ); |
| 349 |
exit; |
| 350 |
} |
| 351 |
// phpcs:enable WordPress.Security.NonceVerification.Recommended |
| 352 |
} |
| 353 |
|
| 354 |
/** |
| 355 |
* Main Instance. |
| 356 |
* |
| 357 |
* @since 1.0.0 |
| 358 |
* @static |
| 359 |
* @see loginpress_loader() |
| 360 |
* @return LoginPress instance |
| 361 |
*/ |
| 362 |
public static function instance() { |
| 363 |
if ( is_null( self::$_instance ) ) { |
| 364 |
self::$_instance = new self(); |
| 365 |
} |
| 366 |
return self::$_instance; |
| 367 |
} |
| 368 |
|
| 369 |
/** |
| 370 |
* Load Languages. |
| 371 |
* |
| 372 |
* @since 1.0.0 |
| 373 |
* @return void |
| 374 |
*/ |
| 375 |
public function textdomain() { |
| 376 |
|
| 377 |
$plugin_dir = dirname( plugin_basename( __FILE__ ) ); |
| 378 |
load_plugin_textdomain( 'loginpress', false, $plugin_dir . '/languages/' ); |
| 379 |
} |
| 380 |
|
| 381 |
/** |
| 382 |
* Define constant if not already set. |
| 383 |
* |
| 384 |
* @param string $name The constant name to define. |
| 385 |
* @param string|bool $value The constant value to set. |
| 386 |
* @return void |
| 387 |
*/ |
| 388 |
private function define( $name, $value ) { |
| 389 |
if ( ! defined( $name ) ) { |
| 390 |
define( $name, $value ); |
| 391 |
} |
| 392 |
} |
| 393 |
|
| 394 |
/** |
| 395 |
* Init WPBrigade when WordPress Initializes. |
| 396 |
* |
| 397 |
* @return void |
| 398 |
*/ |
| 399 |
public function init() { |
| 400 |
// Before init action. |
| 401 |
} |
| 402 |
|
| 403 |
/** |
| 404 |
* Create LoginPress Page Template. |
| 405 |
* |
| 406 |
* @since 1.1.3 |
| 407 |
* @return void |
| 408 |
*/ |
| 409 |
public function check_loginpress_page() { |
| 410 |
|
| 411 |
// Retrieve the LoginPress admin page option, that was created during the activation process. |
| 412 |
$option = $this->get_loginpress_page(); |
| 413 |
|
| 414 |
include LOGINPRESS_DIR_PATH . 'include/class-loginpress-page-create.php'; |
| 415 |
// Retrieve the status of the page, if the option is available. |
| 416 |
if ( $option ) { |
| 417 |
$page = get_post( $option ); |
| 418 |
$status = $page ? $page->post_status : null; |
| 419 |
} else { |
| 420 |
$status = null; |
| 421 |
} |
| 422 |
|
| 423 |
// Check the status of the page. Let's fix it, if the page is missing or in the trash. |
| 424 |
if ( empty( $status ) || 'trash' === $status ) { |
| 425 |
new LoginPress_Page_Create(); |
| 426 |
} |
| 427 |
} |
| 428 |
|
| 429 |
/** |
| 430 |
* Function for redirect the LoginPress page on editing. |
| 431 |
* |
| 432 |
* @since 1.1.3 |
| 433 |
* @return void |
| 434 |
*/ |
| 435 |
public function redirect_loginpress_edit_page() { |
| 436 |
global $pagenow; |
| 437 |
|
| 438 |
$page = $this->get_loginpress_page(); |
| 439 |
|
| 440 |
if ( ! $page ) { |
| 441 |
return; |
| 442 |
} |
| 443 |
|
| 444 |
$page_url = get_permalink( $page ); |
| 445 |
$page_id = $page->ID; |
| 446 |
|
| 447 |
// Generate the redirect url. |
| 448 |
$url = add_query_arg( |
| 449 |
array( |
| 450 |
'autofocus[section]' => 'loginpress_panel', |
| 451 |
'url' => rawurlencode( $page_url ? $page_url : '' ), |
| 452 |
), |
| 453 |
admin_url( 'customize.php' ) |
| 454 |
); |
| 455 |
|
| 456 |
// Check current admin page (read-only GET `post` compare for redirect). |
| 457 |
// phpcs:disable WordPress.Security.NonceVerification.Recommended |
| 458 |
if ( 'post.php' === $pagenow && isset( $_GET['post'] ) && absint( wp_unslash( $_GET['post'] ) ) === $page_id ) { |
| 459 |
wp_safe_redirect( $url ); |
| 460 |
} |
| 461 |
// phpcs:enable WordPress.Security.NonceVerification.Recommended |
| 462 |
} |
| 463 |
|
| 464 |
/** |
| 465 |
* Add new page in Appearance to customize Login Page. |
| 466 |
* |
| 467 |
* @version 3.0.0 |
| 468 |
* @return void |
| 469 |
*/ |
| 470 |
public function register_options_page() { |
| 471 |
|
| 472 |
add_submenu_page( 'LoginPress', __( 'Activate', 'loginpress' ), __( 'Activate', 'loginpress' ), 'manage_options', 'loginpress-optin', array( $this, 'render_optin' ) ); |
| 473 |
|
| 474 |
add_theme_page( __( 'LoginPress', 'loginpress' ), __( 'LoginPress', 'loginpress' ), 'manage_options', 'abw', '__return_null' ); |
| 475 |
} |
| 476 |
|
| 477 |
|
| 478 |
/** |
| 479 |
* Show Opt-in Page. |
| 480 |
* |
| 481 |
* @since 1.0.15 |
| 482 |
* @return void |
| 483 |
*/ |
| 484 |
public function render_optin() { |
| 485 |
include LOGINPRESS_DIR_PATH . 'lib/wpb-sdk/views/loginpress-optin-form.php'; |
| 486 |
} |
| 487 |
|
| 488 |
/** |
| 489 |
* Session Expiration. |
| 490 |
* |
| 491 |
* @since 1.0.18 |
| 492 |
* @version 6.2.3 |
| 493 |
* @param int $expiration Default expiration time in seconds. |
| 494 |
* @param int $user_id The user ID. |
| 495 |
* @param bool $remember Whether to remember the user. |
| 496 |
* @return int Modified expiration time in seconds. |
| 497 |
* |
| 498 |
* phpcs:disable PSR2.Methods.MethodDeclaration.Underscore |
| 499 |
* phpcs:disable Generic.CodeAnalysis.UnusedFunctionParameter.FoundAfterLastUsed |
| 500 |
*/ |
| 501 |
public function _change_auth_cookie_expiration( $expiration, $user_id, $remember ) { |
| 502 |
$loginpress_setting = get_option( 'loginpress_setting' ); |
| 503 |
$expiration_time = isset( $loginpress_setting['session_expiration'] ) ? absint( $loginpress_setting['session_expiration'] ) : 0; |
| 504 |
$expiration_max = loginpress_session_expiration_max(); |
| 505 |
|
| 506 |
if ( $expiration_time > $expiration_max ) { |
| 507 |
$expiration_time = $expiration_max; |
| 508 |
} |
| 509 |
|
| 510 |
/** |
| 511 |
* Return the WordPress default $expiration time if LoginPress Session Expiration time set 0 or empty. |
| 512 |
* |
| 513 |
* @since 1.0.18 |
| 514 |
*/ |
| 515 |
// @phpstan-ignore-next-line |
| 516 |
if ( empty( $expiration_time ) || '0' === $expiration_time ) { |
| 517 |
return $expiration; |
| 518 |
} |
| 519 |
|
| 520 |
/** |
| 521 |
* $filter_role Use filter `loginpress_exclude_role_session` for return the role. |
| 522 |
* By default it's false and $expiration time will apply on all user. |
| 523 |
* |
| 524 |
* @return string|array|false role name. |
| 525 |
* @since 1.3.2 |
| 526 |
*/ |
| 527 |
$filter_role = apply_filters( 'loginpress_exclude_role_session', false ); |
| 528 |
|
| 529 |
if ( $filter_role ) { |
| 530 |
$user_data = get_userdata( $user_id ); |
| 531 |
if ( ! $user_data ) { |
| 532 |
return $expiration; |
| 533 |
} |
| 534 |
$user_roles = $user_data->roles; |
| 535 |
|
| 536 |
// if $filter_role is array, return the default $expiration for each defined role. |
| 537 |
if ( is_array( $filter_role ) ) { |
| 538 |
foreach ( $filter_role as $role ) { |
| 539 |
if ( in_array( $role, $user_roles, true ) ) { |
| 540 |
return $expiration; |
| 541 |
} |
| 542 |
} |
| 543 |
} elseif ( in_array( $filter_role, $user_roles, true ) ) { |
| 544 |
return $expiration; |
| 545 |
} |
| 546 |
} |
| 547 |
|
| 548 |
// Convert Duration (minutes) of the expiration period in seconds. |
| 549 |
$expiration = $expiration_time * 60; |
| 550 |
|
| 551 |
return $expiration; |
| 552 |
} |
| 553 |
|
| 554 |
/** |
| 555 |
* Load JS or CSS files at admin side and enqueue them. |
| 556 |
* |
| 557 |
* @param string $hook The current admin page hook identifier. |
| 558 |
* @return void |
| 559 |
* @version 6.2.3 |
| 560 |
* |
| 561 |
* phpcs:disable PSR2.Methods.MethodDeclaration.Underscore |
| 562 |
*/ |
| 563 |
public function _admin_scripts( $hook ) { |
| 564 |
if ( 'toplevel_page_loginpress-settings' === $hook ) { |
| 565 |
wp_enqueue_script( 'youtube-api', 'https://www.youtube.com/iframe_api', array(), LOGINPRESS_VERSION, true ); |
| 566 |
|
| 567 |
$js_code = ' |
| 568 |
var ytPlayers = {}; |
| 569 |
|
| 570 |
function onYouTubeIframeAPIReady() { |
| 571 |
var iframes = document.querySelectorAll("iframe.loginPress-feature-video"); |
| 572 |
|
| 573 |
Array.prototype.forEach.call(iframes, function(iframe) { |
| 574 |
// Assign a unique ID if not present |
| 575 |
if (!iframe.id) { |
| 576 |
iframe.id = "yt-player-" + Math.random().toString(36).substring(2, 15); |
| 577 |
} |
| 578 |
|
| 579 |
var id = iframe.id; |
| 580 |
|
| 581 |
ytPlayers[id] = new YT.Player(id, { |
| 582 |
events: { |
| 583 |
"onStateChange": function(event) { |
| 584 |
handleStateChange(event, id); |
| 585 |
} |
| 586 |
} |
| 587 |
}); |
| 588 |
}); |
| 589 |
} |
| 590 |
|
| 591 |
function handleStateChange(event, currentId) { |
| 592 |
if (event.data === YT.PlayerState.PLAYING) { |
| 593 |
for (var id in ytPlayers) { |
| 594 |
if (ytPlayers.hasOwnProperty(id) && id !== currentId) { |
| 595 |
var player = ytPlayers[id]; |
| 596 |
if (typeof player.pauseVideo === "function") { |
| 597 |
player.pauseVideo(); |
| 598 |
} |
| 599 |
} |
| 600 |
} |
| 601 |
} |
| 602 |
} |
| 603 |
'; |
| 604 |
|
| 605 |
wp_add_inline_script( 'youtube-api', $js_code ); |
| 606 |
} |
| 607 |
|
| 608 |
$should_load = ( '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' === $hook ); |
| 609 |
|
| 610 |
if ( version_compare( LOGINPRESS_VERSION, '6.0.0', '>=' ) ) { |
| 611 |
if ( $should_load || 'users.php' == $hook ) { // phpcs:ignore |
| 612 |
// Register script first with all parameters. |
| 613 |
wp_register_script( 'loginpress-react-settings', LOGINPRESS_DIR_URL . 'build/index.js', array( 'wp-element', 'wp-i18n', 'wp-api-fetch' ), LOGINPRESS_VERSION, true ); |
| 614 |
|
| 615 |
// Enqueue the registered script. |
| 616 |
wp_enqueue_script( 'loginpress-react-settings' ); |
| 617 |
wp_enqueue_style( 'loginpress_style_react', plugins_url( 'build/index.css', __FILE__ ), array(), LOGINPRESS_VERSION ); |
| 618 |
|
| 619 |
// Set translations. |
| 620 |
wp_set_script_translations( 'loginpress-react-settings', 'loginpress', LOGINPRESS_DIR_PATH . 'languages' ); |
| 621 |
|
| 622 |
// Localize script data. |
| 623 |
$is_pro_active = is_plugin_active( 'loginpress-pro/loginpress-pro.php' ); |
| 624 |
|
| 625 |
$is_license_activated = false; |
| 626 |
if ( $is_pro_active && class_exists( 'LoginPress_Pro' ) && is_callable( array( 'LoginPress_Pro', 'is_activated' ) ) ) { |
| 627 |
$is_license_activated = LoginPress_Pro::is_activated(); |
| 628 |
} |
| 629 |
|
| 630 |
$license_tab_url = admin_url( 'admin.php?page=loginpress-settings&tab=loginpress_pro_license' ); |
| 631 |
|
| 632 |
/** |
| 633 |
* Filters the purchase / pricing URL in the license sticky notice. |
| 634 |
* |
| 635 |
* @since 6.2.3 |
| 636 |
* |
| 637 |
* @param string $url Pricing page URL. |
| 638 |
*/ |
| 639 |
$purchase_license_url = apply_filters( |
| 640 |
'loginpress_license_sticky_purchase_url', |
| 641 |
'https://loginpress.pro/pricing/?utm_source=loginpress-pro&utm_medium=license-sticky-notice&utm_campaign=pro-upgrade&utm_content=Purchase+New+License' |
| 642 |
); |
| 643 |
|
| 644 |
$languages = ! empty( get_available_languages() ); |
| 645 |
|
| 646 |
wp_localize_script( |
| 647 |
'loginpress-react-settings', |
| 648 |
'loginpressReactData', |
| 649 |
array( |
| 650 |
'ajaxUrl' => admin_url( 'admin-ajax.php' ), |
| 651 |
'isProActive' => $is_pro_active, |
| 652 |
'isLicenseActivated' => $is_license_activated, |
| 653 |
'licenseTabUrl' => esc_url( $license_tab_url ), |
| 654 |
'purchaseLicenseUrl' => esc_url( $purchase_license_url ), |
| 655 |
'licenseStickyInCore' => true, |
| 656 |
'wp_login_url' => wp_login_url(), |
| 657 |
'language_switcher' => $languages, |
| 658 |
'sessionExpirationMax' => loginpress_session_expiration_max(), |
| 659 |
) |
| 660 |
); |
| 661 |
} |
| 662 |
} |
| 663 |
|
| 664 |
if ( $should_load ) { |
| 665 |
wp_enqueue_style( 'loginpress_style', plugins_url( 'css/style.css', __FILE__ ), array(), LOGINPRESS_VERSION ); |
| 666 |
wp_enqueue_script( 'loginpress_js', plugins_url( 'js/admin-custom.js', __FILE__ ), array(), LOGINPRESS_VERSION, false ); |
| 667 |
|
| 668 |
// Array for localize. |
| 669 |
$loginpress_localize = array( |
| 670 |
'plugin_url' => plugins_url(), |
| 671 |
'localize_translations' => array( |
| 672 |
_x( 'Name', 'Login Redirect Roles', 'loginpress' ), |
| 673 |
), |
| 674 |
'help_nonce' => wp_create_nonce( 'loginpress-log-nonce' ), |
| 675 |
|
| 676 |
); |
| 677 |
|
| 678 |
wp_localize_script( 'loginpress_js', 'loginpress_script', $loginpress_localize ); |
| 679 |
} |
| 680 |
wp_enqueue_script( 'lp_outside_plugin_admin', plugins_url( 'js/outside-plugin-admin.js', __FILE__ ), array(), LOGINPRESS_VERSION, false ); |
| 681 |
} |
| 682 |
|
| 683 |
/** |
| 684 |
* Add rating icon on plugins page. |
| 685 |
* |
| 686 |
* @since 1.0.9 |
| 687 |
* @version 1.1.22 |
| 688 |
* @param array<string> $meta_fields Array of existing meta fields. |
| 689 |
* @param string $file Plugin file path. |
| 690 |
* @return array<string> Modified meta fields array. |
| 691 |
* |
| 692 |
* phpcs:disable PSR2.Methods.MethodDeclaration.Underscore |
| 693 |
*/ |
| 694 |
public function _row_meta( $meta_fields, $file ) { |
| 695 |
|
| 696 |
if ( 'loginpress/loginpress.php' !== $file ) { |
| 697 |
return $meta_fields; |
| 698 |
} |
| 699 |
|
| 700 |
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>'; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
| 701 |
|
| 702 |
$plugin_rate = 'https://wordpress.org/support/plugin/loginpress/reviews/?rate=5#rate-response'; |
| 703 |
$plugin_filter = 'https://wordpress.org/support/plugin/loginpress/reviews/?filter=5'; |
| 704 |
$svg_xmlns = 'https://www.w3.org/2000/svg'; |
| 705 |
$svg_icon = ''; |
| 706 |
|
| 707 |
for ( $i = 0; $i < 5; $i++ ) { |
| 708 |
$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>"; |
| 709 |
} |
| 710 |
|
| 711 |
// Set icon for thumbs up. |
| 712 |
$meta_fields[] = '<a href="' . esc_url( $plugin_filter ) . '" target="_blank"><span class="dashicons dashicons-thumbs-up"></span>' . esc_html__( 'Vote!', 'loginpress' ) . '</a>'; |
| 713 |
|
| 714 |
// Set icon for 5-star reviews, v1.1.22. |
| 715 |
$meta_fields[] = "<a href='" . esc_url( $plugin_rate ) . "' target='_blank' title='" . esc_html__( 'Rate', 'loginpress' ) . "'><i class='loginpress-rate-stars'>" . $svg_icon . '</i></a>'; |
| 716 |
|
| 717 |
return $meta_fields; |
| 718 |
} |
| 719 |
|
| 720 |
/** |
| 721 |
* Plugin activation. |
| 722 |
* |
| 723 |
* @since 1.0.15 |
| 724 |
* @version 1.0.22 |
| 725 |
* @return void |
| 726 |
*/ |
| 727 |
public static function plugin_activation() { |
| 728 |
|
| 729 |
$loginpress_key = get_option( 'loginpress_customization' ); |
| 730 |
$loginpress_setting = get_option( 'loginpress_setting' ); |
| 731 |
|
| 732 |
// Create a key 'loginpress_customization' with empty array. |
| 733 |
if ( ! $loginpress_key ) { |
| 734 |
update_option( 'loginpress_customization', array() ); |
| 735 |
} |
| 736 |
|
| 737 |
// Create a key 'loginpress_setting' with empty array. |
| 738 |
if ( ! $loginpress_setting ) { |
| 739 |
update_option( 'loginpress_setting', array() ); |
| 740 |
} |
| 741 |
} |
| 742 |
|
| 743 |
/** |
| 744 |
* Plugin uninstallation. |
| 745 |
* |
| 746 |
* @return void |
| 747 |
*/ |
| 748 |
public function plugin_uninstallation() { |
| 749 |
include_once LOGINPRESS_DIR_PATH . 'include/uninstall.php'; |
| 750 |
} |
| 751 |
|
| 752 |
|
| 753 |
/** |
| 754 |
* Pull the LoginPress page from options. |
| 755 |
* |
| 756 |
* @access public |
| 757 |
* @since 1.1.3 |
| 758 |
* @version 1.1.7 |
| 759 |
* @return mixed |
| 760 |
*/ |
| 761 |
public function get_loginpress_page() { |
| 762 |
|
| 763 |
$loginpress_setting = get_option( 'loginpress_setting', array() ); |
| 764 |
if ( ! is_array( $loginpress_setting ) && empty( $loginpress_setting ) ) { |
| 765 |
$loginpress_setting = array(); |
| 766 |
} |
| 767 |
$page = array_key_exists( 'loginpress_page', $loginpress_setting ) ? get_post( $loginpress_setting['loginpress_page'] ) : false; |
| 768 |
|
| 769 |
return $page; |
| 770 |
} |
| 771 |
} // End Of Class. |
| 772 |
endif; |
| 773 |
|
| 774 |
|
| 775 |
/** |
| 776 |
* Returns the main instance of WP to prevent the need to use globals. |
| 777 |
* |
| 778 |
* @since 1.0.0 |
| 779 |
* @return LoginPress |
| 780 |
*/ |
| 781 |
function loginpress_loader() { |
| 782 |
return LoginPress::instance(); |
| 783 |
} |
| 784 |
|
| 785 |
// Call the function. |
| 786 |
loginpress_loader(); |
| 787 |
|
| 788 |
/** |
| 789 |
* Create the Object of Custom Login Entities and Settings. |
| 790 |
* |
| 791 |
* @since 1.0.0 |
| 792 |
*/ |
| 793 |
new LoginPress_Customizer(); |
| 794 |
new LoginPress_Settings(); |
| 795 |
|
| 796 |
/** |
| 797 |
* Create the Object of Remote Notification. |
| 798 |
* |
| 799 |
* @since 1.0.9 |
| 800 |
*/ |
| 801 |
if ( ! class_exists( 'TAV_Remote_Notification_Client' ) ) { |
| 802 |
require LOGINPRESS_ROOT_PATH . 'include/class-remote-notification-client.php'; |
| 803 |
} |
| 804 |
$notification = new TAV_Remote_Notification_Client( 125, '16765c0902705d62', 'https://wpbrigade.com?post_type=notification' ); |
| 805 |
|
| 806 |
register_activation_hook( __FILE__, array( 'LoginPress', 'plugin_activation' ) ); |
| 807 |
|