results = $results; $this->capabilities = $capabilities; } public function render( bool $connected ): void { $this->render_notice(); $this->render_cron_notice(); $this->render_url_preview(); if ( ! $connected ) { return; } $this->render_run_action(); $this->render_error(); $summary = $this->results->last(); if ( $summary instanceof RunSummary ) { $this->render_summary( $summary ); } } private function render_cron_notice(): void { if ( ! defined( 'DISABLE_WP_CRON' ) || ! DISABLE_WP_CRON ) { return; } echo '

'; esc_html_e( 'WP-Cron is disabled. Configure a system cron request to wp-cron.php so 2UA checks can run and refresh.', '2ua-seo-release-guard' ); echo '

'; } private function render_notice(): void { $status = filter_input( INPUT_GET, 'two_ua_run', FILTER_SANITIZE_SPECIAL_CHARS ); if ( 'scheduled' === $status ) { echo '

'; esc_html_e( 'The SEO check was scheduled. WordPress Cron will start it shortly.', '2ua-seo-release-guard' ); echo '

'; } } private function render_url_preview(): void { echo '

'; esc_html_e( 'Monitored URL preview', '2ua-seo-release-guard' ); echo '

' . esc_html( home_url( '/' ) ) . ' '; $this->render_device_badge( 'desktop' ); echo '

'; esc_html_e( 'Published posts, pages, and products are added to their release event automatically.', '2ua-seo-release-guard' ); echo '

'; } private function render_run_action(): void { echo '
'; echo ''; wp_nonce_field( 'two_ua_release_guard_run' ); submit_button( esc_html__( 'Run SEO check now', '2ua-seo-release-guard' ), 'primary', 'submit', false ); echo '
'; } private function render_error(): void { $message = $this->error_message( $this->results->last_error() ); if ( '' === $message ) { return; } echo '

' . esc_html( $message ) . '

'; } private function render_summary( RunSummary $summary ): void { echo '

' . esc_html__( 'Latest check', '2ua-seo-release-guard' ) . '

'; echo '

' . esc_html__( 'Status:', '2ua-seo-release-guard' ) . ' '; echo esc_html( $this->label( $summary->state->status ) ) . ' · '; echo '' . esc_html__( 'Verdict:', '2ua-seo-release-guard' ) . ' '; echo esc_html( $this->label( $summary->state->verdict ) ) . '

'; $this->render_counts( $summary->findings->counts ); $this->render_findings( $summary->findings ); $this->render_handoff( $summary ); if ( ! $summary->is_terminal() ) { echo '

'; esc_html_e( '2UA is processing this check in the background. Refresh this page for the latest status.', '2ua-seo-release-guard' ); echo '

'; } } private function render_handoff( RunSummary $summary ): void { $capabilities = $this->capabilities->get(); $error_code = $this->results->last_error(); if ( ApiException::LIMIT === $error_code ) { $this->render_handoff_form( $summary->state->public_id, 'upgrade', __( 'Upgrade on 2UA', '2ua-seo-release-guard' ) ); return; } if ( $capabilities instanceof RunCapabilities && $capabilities->account->connected ) { $this->render_handoff_form( $summary->state->public_id, 'view_full_result', __( 'Open this result on 2UA', '2ua-seo-release-guard' ) ); return; } $this->render_handoff_form( $summary->state->public_id, 'connect_account', __( 'Email me and keep watching', '2ua-seo-release-guard' ) ); } private function render_handoff_form( string $run_id, string $purpose, string $label ): void { echo '
'; echo ''; echo ''; echo ''; wp_nonce_field( 'two_ua_release_guard_handoff' ); submit_button( esc_html( $label ), 'secondary', 'submit', false ); echo '
'; } private function render_counts( RunFindingCounts $counts ): void { echo '

'; echo esc_html__( 'Critical:', '2ua-seo-release-guard' ) . ' ' . esc_html( (string) $counts->critical ); echo ' · ' . esc_html__( 'Warnings:', '2ua-seo-release-guard' ) . ' '; echo esc_html( (string) $counts->warning ); echo ' · ' . esc_html__( 'Information:', '2ua-seo-release-guard' ) . ' '; echo esc_html( (string) $counts->info ) . '

'; } private function render_findings( RunFindings $findings ): void { if ( array() === $findings->items ) { return; } echo ''; foreach ( $findings->items as $finding ) { $this->render_finding( $finding ); } echo '
'; echo esc_html__( 'Severity', '2ua-seo-release-guard' ) . ''; echo esc_html__( 'Finding', '2ua-seo-release-guard' ) . ''; echo esc_html__( 'URL and profile', '2ua-seo-release-guard' ) . '
'; } private function render_finding( RunFinding $finding ): void { echo '' . esc_html( $this->label( $finding->severity ) ) . ''; echo esc_html( $finding->message ) . '' . esc_html( $finding->location->url ) . ' '; $this->render_device_badge( $finding->location->device_profile ); echo ''; } private function render_device_badge( string $profile ): void { echo ''; echo esc_html( $this->label( $profile ) ) . ''; } private function label( string $value ): string { return ucwords( str_replace( '_', ' ', $value ) ); } private function error_message( string $error_code ): string { $messages = array( ApiException::AUTHENTICATION => __( '2UA authentication failed. Rotate the connection secret or reconnect this site.', '2ua-seo-release-guard' ), ApiException::LIMIT => __( 'The current 2UA plan limit prevented this check.', '2ua-seo-release-guard' ), ApiException::QUEUE => __( '2UA could not queue this check. Please run it again.', '2ua-seo-release-guard' ), ApiException::REMOTE_FETCH => __( '2UA could not refresh the check result. WordPress Cron will retry.', '2ua-seo-release-guard' ), ); return $messages[ $error_code ] ?? ''; } }