$agent_name, 'page' => $page, ]); $scrapper = new LFZW_Fr_Scrapper(); $response = $scrapper->make_request( $api_url ); $json = json_decode( $response, true ); if ( ! isset( $json['agents'] ) || ! is_array( $json['agents'] ) ) { return []; } $agents = []; foreach ( $json['agents'] as $agent ) { $agents[] = $this->format_agent( $agent ); } return $agents; } /** * Normalize a single agent record from the API response. * * @since 1.0.0 * @param array $agent Raw agent record. * @return array Normalized agent record. */ private function format_agent( $agent ) { return [ 'name' => isset( $agent['name'] ) ? sanitize_text_field( $agent['name'] ) : '', 'username' => isset( $agent['username'] ) ? wp_strip_all_tags( trim( $agent['username'] ) ) : '', 'link' => isset( $agent['link'] ) ? esc_url_raw( $agent['link'] ) : '', 'encoded_zuid' => isset( $agent['encodedZuid'] ) ? sanitize_text_field( $agent['encodedZuid'] ) : '', 'image_url' => isset( $agent['imageUrl'] ) ? esc_url_raw( $agent['imageUrl'] ) : '', 'is_top_agent' => ! empty( $agent['isTopAgent'] ), 'rating' => isset( $agent['reviewInformation']['rating'] ) ? sanitize_text_field( $agent['reviewInformation']['rating'] ) : '', 'total_reviews' => isset( $agent['reviewInformation']['totalReviews'] ) ? sanitize_text_field( $agent['reviewInformation']['totalReviews'] ) : '', ]; } }