$urls List of canonical URLs to include. * @param string $key IndexNow key. * @param string|null $key_location Optional fully-qualified URL pointing to the key file. * @return array */ public static function build( string $host, array $urls, string $key, ?string $key_location = null ): array { $filtered = array_values( array_unique( array_filter( array_map( static function ( $url ): string { return trim( (string) $url ); }, $urls ), static function ( string $url ): bool { return '' !== $url; } ) ) ); $payload = array( 'host' => strtolower( $host ), 'key' => $key, 'urlList' => $filtered, ); if ( $key_location ) { $payload['keyLocation'] = $key_location; } return $payload; } }