| 1 |
<?php |
| 2 |
/** |
| 3 |
* OpenStation — Station Home native-window registration. |
| 4 |
* |
| 5 |
* The normal WordPress Dashboard menu item keeps its existing `index.php` |
| 6 |
* URL. The shell's native URL-remap registry claims that URL and opens this |
| 7 |
* window, which means every existing menu, shortcut, portal, and default- |
| 8 |
* window path keeps working without a second Dashboard tile. |
| 9 |
* |
| 10 |
* @package OpenStation |
| 11 |
*/ |
| 12 |
|
| 13 |
defined( 'ABSPATH' ) || exit; |
| 14 |
|
| 15 |
/** Stable native-window id used by the Dashboard URL remap. */ |
| 16 |
const OPENSTATION_STATION_HOME_WINDOW_ID = 'desktop-mode-dashboard'; |
| 17 |
|
| 18 |
/** |
| 19 |
* Render the declarative Station Home frame cloned before the bundle mounts. |
| 20 |
*/ |
| 21 |
function openstation_station_home_render_template() { |
| 22 |
ob_start(); |
| 23 |
?> |
| 24 |
<div class="desktop-mode-station-home" data-os-station-home-root data-state="loading"> |
| 25 |
<div class="os-station-home__layout"> |
| 26 |
<aside class="os-station-home__rail" aria-label="<?php esc_attr_e( 'Station Home', 'desktop-mode' ); ?>"> |
| 27 |
<div class="os-station-home__brand"> |
| 28 |
<img |
| 29 |
class="os-station-home__brand-mark" |
| 30 |
src="<?php echo esc_url( OPENSTATION_URL . 'assets/images/openstation-mark.svg' ); ?>" |
| 31 |
alt="" |
| 32 |
width="36" |
| 33 |
height="36" |
| 34 |
/> |
| 35 |
<span>OpenStation</span> |
| 36 |
</div> |
| 37 |
<div class="os-station-home__location" aria-current="page"> |
| 38 |
<span aria-hidden="true"></span> |
| 39 |
<?php esc_html_e( 'Station Home', 'desktop-mode' ); ?> |
| 40 |
</div> |
| 41 |
<div class="os-station-home__mesh" aria-hidden="true"></div> |
| 42 |
<nav |
| 43 |
class="os-station-home__actions" |
| 44 |
data-os-station-home-actions |
| 45 |
aria-label="<?php esc_attr_e( 'Quick actions', 'desktop-mode' ); ?>" |
| 46 |
></nav> |
| 47 |
</aside> |
| 48 |
|
| 49 |
<main class="os-station-home__main"> |
| 50 |
<header class="os-station-home__intro"> |
| 51 |
<div> |
| 52 |
<h1 id="os-station-home-title" data-os-station-home-greeting> |
| 53 |
<?php esc_html_e( 'Station Home', 'desktop-mode' ); ?> |
| 54 |
</h1> |
| 55 |
<p data-os-station-home-summary><?php esc_html_e( 'Your site at a glance.', 'desktop-mode' ); ?></p> |
| 56 |
</div> |
| 57 |
<os-button |
| 58 |
class="os-station-home__refresh" |
| 59 |
variant="ghost" |
| 60 |
data-os-station-home-refresh |
| 61 |
aria-label="<?php esc_attr_e( 'Refresh Station Home', 'desktop-mode' ); ?>" |
| 62 |
title="<?php esc_attr_e( 'Refresh', 'desktop-mode' ); ?>" |
| 63 |
> |
| 64 |
<span class="dashicons dashicons-update" aria-hidden="true"></span> |
| 65 |
</os-button> |
| 66 |
</header> |
| 67 |
|
| 68 |
<div class="os-station-home__error" data-os-station-home-error role="alert" hidden></div> |
| 69 |
|
| 70 |
<section class="os-station-home__section" aria-labelledby="os-station-home-work-heading"> |
| 71 |
<h2 id="os-station-home-work-heading"><?php esc_html_e( 'Continue working', 'desktop-mode' ); ?></h2> |
| 72 |
<div class="os-station-home__work" data-os-station-home-work></div> |
| 73 |
</section> |
| 74 |
|
| 75 |
<section class="os-station-home__section" aria-labelledby="os-station-home-pulse-heading"> |
| 76 |
<h2 id="os-station-home-pulse-heading"><?php esc_html_e( 'Site pulse', 'desktop-mode' ); ?></h2> |
| 77 |
<div class="os-station-home__pulse" data-os-station-home-pulse></div> |
| 78 |
</section> |
| 79 |
|
| 80 |
<section class="os-station-home__section" aria-labelledby="os-station-home-attention-heading"> |
| 81 |
<h2 id="os-station-home-attention-heading"><?php esc_html_e( 'Needs attention', 'desktop-mode' ); ?></h2> |
| 82 |
<div class="os-station-home__attention" data-os-station-home-attention></div> |
| 83 |
</section> |
| 84 |
|
| 85 |
<section |
| 86 |
class="os-station-home__section os-station-home__cards-section" |
| 87 |
data-os-station-home-cards-section |
| 88 |
aria-labelledby="os-station-home-cards-heading" |
| 89 |
hidden |
| 90 |
> |
| 91 |
<div class="os-station-home__section-heading"> |
| 92 |
<h2 id="os-station-home-cards-heading"><?php esc_html_e( 'From your plugins', 'desktop-mode' ); ?></h2> |
| 93 |
<os-button variant="ghost" size="sm" data-os-station-home-customize> |
| 94 |
<span class="dashicons dashicons-admin-generic" aria-hidden="true"></span> |
| 95 |
<?php esc_html_e( 'Customize', 'desktop-mode' ); ?> |
| 96 |
</os-button> |
| 97 |
</div> |
| 98 |
<div class="os-station-home__cards" data-os-station-home-cards></div> |
| 99 |
</section> |
| 100 |
</main> |
| 101 |
</div> |
| 102 |
|
| 103 |
<os-modal |
| 104 |
class="os-station-home__card-modal" |
| 105 |
data-os-station-home-card-modal |
| 106 |
title="<?php esc_attr_e( 'Customize Station Home', 'desktop-mode' ); ?>" |
| 107 |
size="md" |
| 108 |
> |
| 109 |
<p class="os-station-home__card-modal-intro"> |
| 110 |
<?php esc_html_e( 'Choose which plugin cards can show information on your Station Home.', 'desktop-mode' ); ?> |
| 111 |
</p> |
| 112 |
<div class="os-station-home__card-preferences" data-os-station-home-card-preferences></div> |
| 113 |
</os-modal> |
| 114 |
|
| 115 |
<div class="os-station-home__loading" data-os-station-home-loading role="status"> |
| 116 |
<os-spinner></os-spinner> |
| 117 |
<span><?php esc_html_e( 'Preparing your station…', 'desktop-mode' ); ?></span> |
| 118 |
</div> |
| 119 |
</div> |
| 120 |
<?php |
| 121 |
$html = (string) ob_get_clean(); |
| 122 |
|
| 123 |
if ( function_exists( 'openstation_kses_native_window_template' ) ) { |
| 124 |
echo openstation_kses_native_window_template( $html ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- helper kses-escapes. |
| 125 |
return; |
| 126 |
} |
| 127 |
|
| 128 |
echo wp_kses( $html, wp_kses_allowed_html( 'post' ) ); |
| 129 |
} |
| 130 |
|
| 131 |
/** |
| 132 |
* Register Station Home for every OpenStation user with admin-read access. |
| 133 |
*/ |
| 134 |
function openstation_station_home_register_window() { |
| 135 |
if ( ! current_user_can( 'read' ) ) { |
| 136 |
return; |
| 137 |
} |
| 138 |
|
| 139 |
$registered = openstation_register_window( |
| 140 |
OPENSTATION_STATION_HOME_WINDOW_ID, |
| 141 |
array( |
| 142 |
'title' => __( 'Station Home', 'desktop-mode' ), |
| 143 |
'icon' => 'dashicons-dashboard', |
| 144 |
'template' => 'openstation_station_home_render_template', |
| 145 |
'script' => 'os-station-home', |
| 146 |
'style' => 'os-station-home', |
| 147 |
'width' => 1240, |
| 148 |
'height' => 760, |
| 149 |
'min_width' => 640, |
| 150 |
'min_height' => 480, |
| 151 |
'placement' => 'none', |
| 152 |
'main_tab_padding' => 0, |
| 153 |
'capabilities' => array( 'read' ), |
| 154 |
'config' => array( |
| 155 |
'endpoint' => esc_url_raw( rest_url( 'desktop-mode/v1/station-home' ) ), |
| 156 |
'cardsEndpoint' => esc_url_raw( rest_url( 'desktop-mode/v1/station-home/cards' ) ), |
| 157 |
), |
| 158 |
) |
| 159 |
); |
| 160 |
|
| 161 |
if ( is_wp_error( $registered ) ) { |
| 162 |
// phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_error_log |
| 163 |
error_log( '[openstation] Station Home registration failed: ' . $registered->get_error_message() ); |
| 164 |
} |
| 165 |
} |
| 166 |
add_action( 'init', 'openstation_station_home_register_window', 20 ); |
| 167 |
|