). */ class Ui { /** * Admin page slugs that load the Orbitstem UI assets. * * @return string[] */ public static function pages() { return array( Admin::SLUG, IssuesPage::SLUG, RepairPage::SLUG, RedirectsPage::SLUG, GuardianPage::SLUG, MonitorPage::SLUG, BulkEditor::SLUG, ImportPage::SLUG, Admin::SETTINGS_SLUG, SetupPage::SLUG, ); } /** * Registers asset loading and the body class. */ public static function register() { add_action( 'admin_enqueue_scripts', array( __CLASS__, 'enqueue' ) ); add_filter( 'admin_body_class', array( __CLASS__, 'body_class' ) ); } /** * Whether the current admin request is an Orbitstem screen. * * @return bool */ public static function is_screen() { return in_array( self::current_page(), self::pages(), true ); } /** * The admin page slug of the current request ('' when none). * * @return string */ private static function current_page() { // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- screen detection only. return isset( $_GET['page'] ) ? sanitize_key( wp_unslash( $_GET['page'] ) ) : ''; } /** * Loads the stylesheet and script on Orbitstem screens only. */ public static function enqueue() { if ( ! self::is_screen() ) { return; } wp_enqueue_style( 'orbitstem-seo-admin', ORBITSTEM_SEO_URL . 'assets/admin.css', array(), ORBITSTEM_SEO_VERSION ); wp_enqueue_script( 'orbitstem-seo-admin', ORBITSTEM_SEO_URL . 'assets/admin.js', array(), ORBITSTEM_SEO_VERSION, true ); } /** * Adds a body class for full-width brand styling. * * @param string $classes Classes. * @return string */ public static function body_class( $classes ) { return self::is_screen() ? $classes . ' os-screen' : $classes; } /** * Navigation items: slug => [label, dashicon]. * * @return array */ private static function nav() { return array( Admin::SLUG => array( __( 'Dashboard', 'orbitstem-seo' ), 'dashicons-dashboard' ), IssuesPage::SLUG => array( __( 'Issues', 'orbitstem-seo' ), 'dashicons-warning' ), RepairPage::SLUG => array( __( 'Repair', 'orbitstem-seo' ), 'dashicons-admin-tools' ), RedirectsPage::SLUG => array( __( 'Redirects', 'orbitstem-seo' ), 'dashicons-randomize' ), GuardianPage::SLUG => array( __( 'Guardian', 'orbitstem-seo' ), 'dashicons-shield' ), MonitorPage::SLUG => array( __( 'Monitor', 'orbitstem-seo' ), 'dashicons-chart-line' ), BulkEditor::SLUG => array( __( 'Bulk Editor', 'orbitstem-seo' ), 'dashicons-editor-table' ), ImportPage::SLUG => array( __( 'Import', 'orbitstem-seo' ), 'dashicons-database-import' ), Admin::SETTINGS_SLUG => array( __( 'Settings', 'orbitstem-seo' ), 'dashicons-admin-generic' ), ); } /** * Opens a screen: wrapper, brand header with title, navigation. * * @param string $current Current page slug. * @param string $title Screen title (plain text). * @param string $subtitle Optional one-line description (plain text). * @param string $actions Optional header actions (trusted HTML built by the caller with escaping). */ public static function open( $current, $title, $subtitle = '', $actions = '' ) { $plugin = Plugin::instance(); $errors = 0; if ( $plugin && $plugin->issues && current_user_can( Admin::capability() ) ) { $summary = $plugin->issues->summary(); $errors = isset( $summary['groups'] ) ? (int) $summary['groups']['error'] : (int) $summary['error']; } $items = current_user_can( Admin::capability() ) ? self::nav() : array_intersect_key( self::nav(), array( GuardianPage::SLUG => true ) ); ?>


', esc_html( $tag ), esc_attr( $tone ), '' !== $url ? ' href="' . esc_url( $url ) . '"' : '' ); printf( '%s%s', esc_html( $value ), esc_html( $label ) ); if ( '' !== $note ) { printf( '%s', esc_html( $note ) ); } printf( '', esc_html( $tag ) ); } /** * A severity badge. * * @param string $severity error|warning|notice|success|neutral. * @param string $label Text. * @return string HTML. */ public static function badge( $severity, $label ) { return sprintf( '%2$s', esc_attr( $severity ), esc_html( $label ) ); } /** * A progress bar with an accessible label. * * @param int $done Done. * @param int $total Total. * @param string $label Accessible label. * @return string HTML. */ public static function meter( $done, $total, $label ) { $percent = $total > 0 ? (int) round( 100 * $done / $total ) : 0; return sprintf( '%1$d%%', $percent, esc_attr( $label ) ); } /** * An empty state: icon, title and text. * * @param string $icon Dashicon class. * @param string $title Title. * @param string $text Text. */ public static function empty_state( $icon, $title, $text ) { printf( '
%2$s

%3$s

', esc_attr( $icon ), esc_html( $title ), esc_html( $text ) ); } }