rn $filename; } /** * Force WP Rocket to disable its webp cache. * * @since 3.4 * * @param bool $disable_webp_cache Set to true to disable the webp cache. */ $disable_webp_cache = apply_filters( 'rocket_disable_webp_cache', false ); if ( $disable_webp_cache ) { return $filename; } $http_accept = $this->config->get_server_input( 'HTTP_ACCEPT', '' ); if ( ! $http_accept && function_exists( 'apache_request_headers' ) ) { $headers = apache_request_headers(); $http_accept = isset( $headers['Accept'] ) ? $headers['Accept'] : ''; } if ( ! $http_accept || false === strpos( $http_accept, 'webp' ) ) { if ( preg_match( '#Firefox/(?[0-9]{2})#i', $this->config->get_server_input( 'HTTP_USER_AGENT' ), $matches ) ) { if ( 66 <= (int) $matches['version'] ) { return $filename . '-webp'; } } return $filename; } return $filename . '-webp'; } /** * Modifies the filename if dynamic cookies are set * * @param string $filename Cache filename. * @param array $cookies Cookies for the request. * @return string */ private function maybe_dynamic_cookies_filename( $filename, $cookies ) { $cache_dynamic_cookies = $this->config->get_config( 'cache_dynamic_cookies' ); if ( ! $cache_dynamic_cookies ) { return $filename; } foreach ( $cache_dynamic_cookies as $key => $cookie_name ) { if ( is_array( $cookie_name ) ) { if ( isset( $_COOKIE[ $key ] ) ) { foreach ( $cookie_name as $cookie_key ) { if ( '' !== $cookies[ $key ][ $cookie_key ] ) { $cache_key = $cookies[ $key ][ $cookie_key ]; $cache_key = preg_replace( '/[^a-z0-9_\-]/i', '-', $cache_key ); $filename .= '-' . $cache_key; } } } continue; } if ( isset( $cookies[ $cookie_name ] ) && '' !== $cookies[ $cookie_name ] ) { $cache_key = $cookies[ $cookie_name ]; $cache_key = preg_replace( '/[^a-z0-9_\-]/i', '-', $cache_key ); $filename .= '-' . $cache_key; } } return $filename; } /** * Force lowercase on encoded url strings from different alphabets to prevent issues on some hostings. * * @since 3.3 * * @param array $matches Cache path. * @return string Cache path in lowercase. */ protected function reset_lowercase( $matches ) { return strtolower( $matches[0] ); } }