// SPDX-License-Identifier: AGPL-3.0-or-later declare(strict_types=1); namespace Novamira\GhostMode; use WP_Error; if (!defined('ABSPATH')) { exit(); } const PAGE_SLUG = 'novamira-ghost-mode'; const DISABLE_ACTION = 'novamira_ghost_mode_disable'; const PANEL_HOOK = 'novamira_ghost_mode_panel'; function page_url(): string { return admin_url('admin.php?page=' . PAGE_SLUG); } function register_menu(): void { add_submenu_page( parent_slug: 'novamira-connect', page_title: __('Ghost Mode', domain: 'novamira'), menu_title: __('Ghost Mode', domain: 'novamira'), capability: \novamira_manage_capability(), menu_slug: PAGE_SLUG, callback: __NAMESPACE__ . '\\render_page', ); } function enqueue_page_assets(string $hook): void { if ($hook !== 'novamira_page_' . PAGE_SLUG) { return; } $path = __DIR__ . '/assets/page.css'; $version = defined('WP_DEBUG') && constant('WP_DEBUG') === true && is_file($path) ? (string) filemtime($path) : NOVAMIRA_VERSION; wp_enqueue_style( 'novamira-ghost-mode', (string) NOVAMIRA_PLUGIN_URL . 'includes/ghost-mode/assets/page.css', [], $version, ); } function render_page(): void { if (!\novamira_current_user_can_manage() || !ui_visible()) { wp_die(esc_html__('Sorry, you are not allowed to access this page.', domain: 'default'), args: [ 'response' => 403, ]); } if (has_action(PANEL_HOOK)) { do_action(PANEL_HOOK); return; } $status = status(); \novamira_render_admin_header(); ?>


render_presentation(), default => render_status($status), }; ?>
'success', ]); } function render_presentation(): void { ?>

, ignored_ids: list, malformed: int, fail_closed: bool, updated_at: int, updated_by: int, source: string} $status */ function render_status(array $status): void { $alert = $status['state'] === 'unreadable' || $status['fail_closed']; ?>

, ignored_ids: list, malformed: int, fail_closed: bool, updated_at: int, updated_by: int, source: string} $status */ function render_status_details(array $status): void { $ignored = count($status['ignored_ids']) + $status['malformed']; ?>

0): ?>

403, ]); } check_admin_referer(DISABLE_ACTION); if (!array_key_exists('confirm', $_POST)) { wp_die(esc_html__('Confirm that every administrator will see Novamira again.', domain: 'novamira'), args: [ 'response' => 400, ]); } $error = disable(get_current_user_id(), \novamira_pro_is_active() ? 'pro' : 'free-ui'); if ($error instanceof WP_Error) { wp_die(esc_html($error->get_error_message()), args: ['response' => 500]); } $query = ['novamira_ghost_mode' => 'disabled']; wp_safe_redirect(add_query_arg($query, page_url())); exit(); } function describe_user(int $user_id): string { $user = get_userdata($user_id); if ($user === false) { /* translators: %d: user ID. */ return sprintf(__('User #%d', domain: 'novamira'), $user_id); } if ($user->display_name === '' || $user->display_name === $user->user_login) { return $user->user_login; } return sprintf('%s (%s)', $user->display_name, $user->user_login); }