'none' ) before the first one. * * @return array|WP_Error */ public static function current() { $scan_id = (string) State::get( 'verification_scan_id' ); if ( '' === $scan_id ) { return array( 'status' => 'none' ); } $cached = get_transient( self::CACHE ); if ( is_array( $cached ) && isset( $cached['scan_id'] ) && $cached['scan_id'] === $scan_id ) { return $cached; } $response = ( new ConsivaClient() )->get_scan( $scan_id ); if ( is_wp_error( $response ) ) { return $response; } $view = self::view( $response['body'], $scan_id ); if ( $view['done'] ) { set_transient( self::CACHE, $view, self::CACHE_TTL ); // A finished verification never changes. } return $view; } /** * @return void */ public static function clear_cache() { delete_transient( self::CACHE ); } /** * Allowlisted view of a verification scan. * * @param array $scan Decoded scan response. * @param string $scan_id Scan ID. * @return array */ public static function view( array $scan, $scan_id ) { $status = isset( $scan['status'] ) && in_array( $scan['status'], ScanProgress::STATUSES, true ) ? $scan['status'] : 'queued'; $results = array(); $counts = array_fill_keys( self::STATES, 0 ); foreach ( isset( $scan['verification'] ) && is_array( $scan['verification'] ) ? $scan['verification'] : array() as $row ) { if ( ! is_array( $row ) || ! isset( $row['state'] ) || ! in_array( $row['state'], self::STATES, true ) ) { continue; } $pages = array(); foreach ( isset( $row['pages'] ) && is_array( $row['pages'] ) ? array_slice( $row['pages'], 0, 10 ) : array() as $path ) { // Paths only: the admin screen links them to this site, never to another host. if ( is_string( $path ) && '/' === substr( $path, 0, 1 ) && '//' !== substr( $path, 0, 2 ) ) { $pages[] = sanitize_text_field( $path ); } } $results[] = array( 'technology' => isset( $row['technology'] ) && is_string( $row['technology'] ) ? sanitize_text_field( $row['technology'] ) : __( 'Unknown technology', 'consiva-ai' ), 'category' => isset( $row['category'] ) ? sanitize_key( (string) $row['category'] ) : '', 'state' => $row['state'], 'pages' => $pages, 'note' => isset( $row['note'] ) && is_string( $row['note'] ) ? sanitize_text_field( $row['note'] ) : '', ); ++$counts[ $row['state'] ]; } // Conflicts first: they are the reason this screen exists. usort( $results, static function ( $a, $b ) { $by_state = array_search( $a['state'], self::STATES, true ) - array_search( $b['state'], self::STATES, true ); return 0 !== $by_state ? $by_state : strcasecmp( $a['technology'], $b['technology'] ); } ); return array( 'scan_id' => $scan_id, 'status' => $status, 'done' => in_array( $status, ScanProgress::DONE_STATUSES, true ), 'completed_at' => isset( $scan['completed_at'] ) && is_string( $scan['completed_at'] ) ? sanitize_text_field( $scan['completed_at'] ) : '', 'detailed' => isset( $scan['verification'] ) && is_array( $scan['verification'] ), 'results' => $results, 'counts' => $counts, ); } }