add_node( [ 'id' => 'accessmate-scan', /* translators: Admin bar button label. */ 'title' => '♿ ' . esc_html__( 'Scan Page', 'accessmate' ), 'href' => '#', 'meta' => [ 'class' => 'accessmate-adminbar-btn', /* translators: Admin bar button tooltip. */ 'title' => esc_attr__( 'Run accessmate.ai accessibility scan on this page', 'accessmate' ), ], ] ); } /** * Injects a small inline style for the admin bar node (frontend only). */ public static function enqueue_adminbar_style(): void { if ( ! current_user_can( 'manage_options' ) ) return; if ( ! is_admin_bar_showing() ) return; $css = '#wp-admin-bar-accessmate-scan > .ab-item { cursor: pointer; } #wp-admin-bar-accessmate-scan > .ab-item:hover { color: #3858e9 !important; }'; wp_add_inline_style( 'admin-bar', $css ); } /** * Outputs the overlay config object and loads overlay.js via wp_footer. * Only on frontend pages, only for admins, only when the bundle exists. */ public static function inject_overlay(): void { if ( ! current_user_can( 'manage_options' ) ) return; if ( is_admin() ) return; if ( ! file_exists( ACCESSMATE_PATH . 'assets/overlay.js' ) ) return; // Build the current page URL, stripping the ?aai_scan param used for iframe mode. // trailingslashit() ensures the URL matches get_permalink() output (which always includes // a trailing slash for pretty-permalink pages/posts). global $wp; $page_url = trailingslashit( remove_query_arg( 'aai_scan', home_url( add_query_arg( [], $wp->request ) ) ) ); $config = [ 'nonce' => wp_create_nonce( 'wp_rest' ), 'restBase' => rest_url( 'accessmate/v1' ), 'pageUrl' => esc_url_raw( $page_url ), ]; wp_register_script( 'accessmate-overlay', ACCESSMATE_URL . 'assets/overlay.js', [], ACCESSMATE_VERSION, true ); wp_add_inline_script( 'accessmate-overlay', 'window.accessmateOverlayConfig=' . wp_json_encode( $config ) . ';', 'before' ); wp_enqueue_script( 'accessmate-overlay' ); } }