'fetch', 'label' => $label, 'request' => array( 'url' => $url, 'method' => 'GET', ), ); if ( is_wp_error( $response ) ) { $step['finding'] = array( 'outcome' => 'negative', 'summary' => 'Request failed: ' . $response->get_error_message(), ); return $step; } $code = (int) wp_remote_retrieve_response_code( $response ); $headers = array(); foreach ( self::HEADER_ALLOWLIST as $name ) { $value = wp_remote_retrieve_header( $response, $name ); if ( is_array( $value ) ) { $value = implode( ', ', $value ); } if ( is_string( $value ) && '' !== $value ) { $headers[ $name ] = $value; } } $body = (string) wp_remote_retrieve_body( $response ); $preview = mb_substr( $body, 0, self::BODY_PREVIEW_LIMIT ); $step['response'] = array( 'status' => $code, 'statusText' => (string) wp_remote_retrieve_response_message( $response ), 'headers' => $headers, 'bodyPreview' => $preview, ); if ( '' !== $summary ) { $step['finding'] = array( 'outcome' => $outcome ? $outcome : 'neutral', 'summary' => $summary, ); } return $step; } /** * Build a parse/validate step. * * @param string $label Step label. * @param string $outcome positive|negative|neutral. * @param string $summary One-line finding. * @return array */ public static function parse( string $label, string $outcome, string $summary ): array { return array( 'action' => 'parse', 'label' => $label, 'finding' => array( 'outcome' => $outcome, 'summary' => $summary, ), ); } /** * Build the terminal conclusion step. * * @param string $outcome positive|negative|neutral. * @param string $summary Conclusion text (usually the result message). * @return array */ public static function conclude( string $outcome, string $summary ): array { return array( 'action' => 'conclude', 'label' => 'Conclusion', 'finding' => array( 'outcome' => $outcome, 'summary' => $summary, ), ); } }