WP_Http_Encoding::accept_encoding( string $url, array $args ): string

In this article

What encoding types to accept and their priority values.

Parameters

$urlstringrequired
$argsarrayrequired

Return

string Types of encoding to accept.

Source

public static function accept_encoding( $url, $args ) {
	$type                = array();
	$compression_enabled = self::is_available();

	if ( ! $args['decompress'] ) { // Decompression specifically disabled.
		$compression_enabled = false;
	} elseif ( $args['stream'] ) { // Disable when streaming to file.
		$compression_enabled = false;
	} elseif ( isset( $args['limit_response_size'] ) ) { // If only partial content is being requested, we won't be able to decompress it.
		$compression_enabled = false;
	}

	if ( $compression_enabled ) {
		if ( function_exists( 'gzinflate' ) ) {
			$type[] = 'deflate;q=1.0';
		}

		if ( function_exists( 'gzuncompress' ) ) {
			$type[] = 'compress;q=0.5';
		}

		if ( function_exists( 'gzdecode' ) ) {
			$type[] = 'gzip;q=0.5';
		}
	}

	/**
	 * Filters the allowed encoding types.
	 *
	 * @since 3.6.0
	 *
	 * @param string[] $type Array of what encoding types to accept and their priority values.
	 * @param string   $url  URL of the HTTP request.
	 * @param array    $args HTTP request arguments.
	 */
	$type = apply_filters( 'wp_http_accept_encoding', $type, $url, $args );

	return implode( ', ', $type );
}

Hooks

apply_filters( ‘wp_http_accept_encoding’, string[] $type, string $url, array $args )

Filters the allowed encoding types.

Changelog

VersionDescription
2.8.0Introduced.

User Contributed Notes

You must log in before being able to contribute a note or feedback.