| 1 |
<?php |
| 2 |
|
| 3 |
declare(strict_types=1); |
| 4 |
|
| 5 |
namespace Yatra\Shortcodes; |
| 6 |
|
| 7 |
/** |
| 8 |
* My Account Shortcode |
| 9 |
* |
| 10 |
* Renders the same React account UI as the virtual account route (see AccountPageHandler + account-page.php). |
| 11 |
* Use [yatra_my_account] on any page; legacy attributes are accepted for compatibility but do not change the React UI. |
| 12 |
*/ |
| 13 |
class MyAccountShortcode extends BaseShortcode |
| 14 |
{ |
| 15 |
public function __construct() |
| 16 |
{ |
| 17 |
parent::__construct('yatra_my_account', [ |
| 18 |
'show_bookings' => 'yes', |
| 19 |
'show_profile' => 'yes', |
| 20 |
'show_wishlist' => 'yes', |
| 21 |
'bookings_limit' => '10', |
| 22 |
]); |
| 23 |
} |
| 24 |
|
| 25 |
/** |
| 26 |
* Render the my account shortcode content (React mount only; same app as /account URL). |
| 27 |
*/ |
| 28 |
protected function renderContent(array $atts): string |
| 29 |
{ |
| 30 |
shortcode_atts($this->default_attributes, $atts, $this->tag); |
| 31 |
|
| 32 |
if (!is_user_logged_in()) { |
| 33 |
return $this->renderLoginForm(); |
| 34 |
} |
| 35 |
|
| 36 |
$yatra_account_react_embed = true; |
| 37 |
ob_start(); |
| 38 |
require YATRA_PLUGIN_PATH . 'templates/partials/account-react-root.php'; |
| 39 |
|
| 40 |
return (string) ob_get_clean(); |
| 41 |
} |
| 42 |
|
| 43 |
/** |
| 44 |
* Render login form for non-logged in users |
| 45 |
*/ |
| 46 |
private function renderLoginForm(): string |
| 47 |
{ |
| 48 |
$login_url = wp_login_url(get_permalink()); |
| 49 |
$register_url = wp_registration_url(); |
| 50 |
|
| 51 |
ob_start(); |
| 52 |
?> |
| 53 |
<div class="yatra-my-account-login"> |
| 54 |
<div class="yatra-login-prompt"> |
| 55 |
<h3><?php esc_html_e('Login to Your Account', 'yatra'); ?></h3> |
| 56 |
<p><?php esc_html_e('Please login to access your account dashboard, view bookings, and manage your wishlist.', 'yatra'); ?></p> |
| 57 |
|
| 58 |
<div class="yatra-login-actions"> |
| 59 |
<a href="<?php echo esc_url($login_url); ?>" class="yatra-btn yatra-btn-primary"> |
| 60 |
<?php esc_html_e('Login', 'yatra'); ?> |
| 61 |
</a> |
| 62 |
<?php if (get_option('users_can_register')): ?> |
| 63 |
<a href="<?php echo esc_url($register_url); ?>" class="yatra-btn yatra-btn-secondary"> |
| 64 |
<?php esc_html_e('Register', 'yatra'); ?> |
| 65 |
</a> |
| 66 |
<?php endif; ?> |
| 67 |
</div> |
| 68 |
</div> |
| 69 |
</div> |
| 70 |
<?php |
| 71 |
|
| 72 |
return (string) ob_get_clean(); |
| 73 |
} |
| 74 |
} |
| 75 |
|