` markup.
*/
function desktop_mode_games_icon_svg() {
return '';
}
/**
* Whether the current user can use desktop games.
*
* @return bool
*/
function desktop_mode_games_user_can_use() {
$can = is_user_logged_in() && current_user_can( 'read' );
/**
* Filter whether the current user can see the Games window,
* icon, and play games.
*
* @param bool $can Default: logged-in + `read` capability.
*/
return (bool) apply_filters( 'desktop_mode_games_user_can_use', $can );
}
/**
* Echoes the Games window's template body.
*
* The `data-desktop-mode-games-*` hooks are the contract the JS
* render callback relies on — keep them intact (or rename via the
* filter) when customizing the layout.
*/
function desktop_mode_games_render_template() {
ob_start();
?>
__( 'Games', 'desktop-mode' ),
'icon' => $icon_uri,
'template' => 'desktop_mode_games_render_template',
'script' => 'desktop-mode-games',
'width' => 900,
'height' => 600,
'min_width' => 560,
'min_height' => 400,
'placement' => 'dock',
);
/**
* Filter the args used to register the Games native window.
*
* @param array $window_args Args passed to `desktop_mode_register_window()`.
*/
$window_args = (array) apply_filters( 'desktop_mode_games_window_args', $window_args );
$registered = desktop_mode_register_window( 'desktop-mode-games', $window_args );
if ( is_wp_error( $registered ) ) {
// phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_error_log
error_log( '[desktop-mode] Games window registration failed: ' . $registered->get_error_message() );
return;
}
$icon_args = array(
'title' => __( 'Games', 'desktop-mode' ),
'icon_svg' => desktop_mode_games_icon_svg(),
'window' => 'desktop-mode-games',
'position' => 85,
);
/**
* Filter the args used to register the Games desktop icon.
*
* @param array $icon_args Args passed to `desktop_mode_register_icon()`.
*/
$icon_args = (array) apply_filters( 'desktop_mode_games_icon_args', $icon_args );
desktop_mode_register_icon( 'desktop-mode-games', $icon_args );
}
add_action( 'init', 'desktop_mode_games_register_window', 20 );
/**
* Localize REST endpoints for the JS bundle.
*
* The bundle reads its config off `window.desktopModeGamesConfig`
* and never hardcodes URLs.
*/
function desktop_mode_games_localize_config() {
if ( ! desktop_mode_games_user_can_use() ) {
return;
}
wp_localize_script(
'desktop-mode-games',
'desktopModeGamesConfig',
array(
'restNonce' => wp_create_nonce( 'wp_rest' ),
'gamesUrlBase' => esc_url_raw( rest_url( 'desktop-mode/v1/games' ) ),
'challengesUrl' => esc_url_raw( rest_url( 'desktop-mode/v1/games/challenges' ) ),
'usersSearchUrl' => esc_url_raw( rest_url( 'desktop-mode/v1/games/users/search' ) ),
)
);
wp_enqueue_style( 'desktop-mode-games' );
}
add_action( 'admin_enqueue_scripts', 'desktop_mode_games_localize_config', 30 );