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