| 1 |
<?php |
| 2 |
|
| 3 |
namespace StoreEngine\Shortcode; |
| 4 |
|
| 5 |
if ( ! defined( 'ABSPATH' ) ) { |
| 6 |
exit; |
| 7 |
} |
| 8 |
|
| 9 |
use StoreEngine\Utils\Helper; |
| 10 |
use StoreEngine\Utils\Template; |
| 11 |
|
| 12 |
class Login { |
| 13 |
|
| 14 |
|
| 15 |
public function __construct() { |
| 16 |
add_shortcode( 'storeengine_login_form', array( $this, 'login_form' ) ); |
| 17 |
} |
| 18 |
|
| 19 |
public function login_form( $atts ) { |
| 20 |
$attributes = shortcode_atts( [ |
| 21 |
'form_title' => __( 'Log In into your Account', 'storeengine' ), |
| 22 |
'username_label' => __( 'Username or Email Address', 'storeengine' ), |
| 23 |
'username_placeholder' => __( 'Username or Email Address', 'storeengine' ), |
| 24 |
'password_label' => __( 'Password', 'storeengine' ), |
| 25 |
'password_placeholder' => __( 'Password', 'storeengine' ), |
| 26 |
'remember_label' => __( 'Remember me', 'storeengine' ), |
| 27 |
'login_button_label' => __( 'Log in Now', 'storeengine' ), |
| 28 |
'reset_password_label' => __( 'Reset password', 'storeengine' ), |
| 29 |
'show_logged_in_message' => true, |
| 30 |
// Link directly to our in-dashboard register endpoint rather than |
| 31 |
// going through wp_registration_url() (which returns wp-login.php). |
| 32 |
// We intentionally don't filter `register_url` globally — only the |
| 33 |
// StoreEngine login template should route to the branded form. |
| 34 |
'register_url' => Helper::get_account_endpoint_url( 'register' ), |
| 35 |
'login_redirect_url' => Helper::get_page_permalink( 'dashboard_page' ), |
| 36 |
'logout_redirect_url' => get_the_permalink(), |
| 37 |
], $atts ); |
| 38 |
|
| 39 |
ob_start(); |
| 40 |
|
| 41 |
if ( apply_filters( 'storeengine/shortcode/login_form_is_user_logged_in', is_user_logged_in() ) ) { |
| 42 |
if ( filter_var( $attributes['show_logged_in_message'], FILTER_VALIDATE_BOOLEAN ) ) { |
| 43 |
Template::get_template( 'shortcode/logged-in-user.php', [ |
| 44 |
'logout_redirect_url' => $attributes['logout_redirect_url'], |
| 45 |
] ); |
| 46 |
} |
| 47 |
} else { |
| 48 |
Template::get_template( 'shortcode/login.php', $attributes ); |
| 49 |
} |
| 50 |
|
| 51 |
return apply_filters( 'storeengine/templates/shortcode/login', ob_get_clean() ); |
| 52 |
} |
| 53 |
} |
| 54 |
|