canonical_query( $parts['query'] ) : ''; $origin = $scheme . '://' . $host . ( $port ? ':' . $port : '' ); ksort( $variants ); $source = $origin . '|' . $path . '|' . $query . '|' . wp_json_encode( $variants ); $hash = hash( 'sha256', $source ); return $host . '/' . substr( $hash, 0, 2 ) . '/' . $hash; } /** * Build the final cache file path. * * @param string $cache_root Cache root. * @param string $key Cache key. * @return string */ public function path( $cache_root, $key ) { $root = wp_normalize_path( untrailingslashit( $cache_root ) ); $segments = array_map( array( Sanitization::class, 'cache_segment' ), explode( '/', $key ) ); $candidate = wp_normalize_path( $root . '/' . implode( '/', $segments ) . '/index.html' ); if ( 0 !== strpos( $candidate, $root . '/' ) ) { return ''; } return $candidate; } /** * Remove tracking parameters and sort remaining query parameters. * * @param string $query Query string. * @return string */ public function canonical_query( $query ) { parse_str( $query, $parameters ); $ignored = (array) apply_filters( 'nbh_performance_ignored_query_parameters', array( 'utm_source', 'utm_medium', 'utm_campaign', 'utm_term', 'utm_content', 'gclid', 'fbclid', 'msclkid' ) ); foreach ( $ignored as $key ) { unset( $parameters[ $key ] ); } ksort( $parameters ); return http_build_query( $parameters, '', '&', PHP_QUERY_RFC3986 ); } }