| 1 |
<?php |
| 2 |
|
| 3 |
namespace StoreEngine\Shortcode; |
| 4 |
|
| 5 |
use StoreEngine\Utils\Helper; |
| 6 |
|
| 7 |
if ( ! defined( 'ABSPATH' ) ) { |
| 8 |
exit(); |
| 9 |
} |
| 10 |
|
| 11 |
class FrontendDashboard { |
| 12 |
public function __construct() { |
| 13 |
add_shortcode( 'storeengine_dashboard', array( $this, 'frontend_dashboard' ) ); |
| 14 |
} |
| 15 |
public function frontend_dashboard() { |
| 16 |
ob_start(); |
| 17 |
|
| 18 |
do_action( 'storeengine/shortcode/before_storeengine_dashboard' ); |
| 19 |
|
| 20 |
if ( ! is_user_logged_in() ) { |
| 21 |
// Some endpoints (e.g. `forgot-password`) are intentionally |
| 22 |
// reachable by logged-out visitors and need their own template |
| 23 |
// to render — falling back to the login form here would |
| 24 |
// effectively hijack those URLs. |
| 25 |
// |
| 26 |
// sanitize_key() before splicing into the action name: even |
| 27 |
// though the array lookup already constrains $endpoint to known |
| 28 |
// menu keys, feeding an unsanitized query var into do_action()'s |
| 29 |
// hook name is fragile (a weird query string could produce a |
| 30 |
// hook name with quotes/whitespace). Same defensive treatment |
| 31 |
// the standard router applies in functions.php:794. |
| 32 |
$endpoint = sanitize_key( (string) get_query_var( 'storeengine_dashboard_page' ) ); |
| 33 |
$items = Helper::get_frontend_dashboard_menu_items(); |
| 34 |
if ( $endpoint && ! empty( $items[ $endpoint ]['guest_accessible'] ) ) { |
| 35 |
do_action( 'storeengine/frontend/dashboard_' . $endpoint . '_endpoint', get_query_var( 'storeengine_dashboard_sub_page' ) ); |
| 36 |
} else { |
| 37 |
echo do_shortcode( '[storeengine_login_form]' ); |
| 38 |
} |
| 39 |
} else { |
| 40 |
Helper::get_template( 'shortcode/frontend-dashboard.php' ); |
| 41 |
} |
| 42 |
|
| 43 |
do_action( 'storeengine/shortcode/after_storeengine_dashboard' ); |
| 44 |
|
| 45 |
return apply_filters( 'storeengine/templates/shortcode/dashboard', Helper::remove_tag_space( Helper::remove_line_break( ob_get_clean() ) ) ); |
| 46 |
} |
| 47 |
} |
| 48 |
|