WP_REST_Pattern_Directory_Controller::get_transient_key()protectedWP 6.0.0

Include a hash of the query args, so that different requests are stored in separate caches.

MD5 is chosen for its speed, low-collision rate, universal availability, and to stay under the character limit for _site_transient_timeout_{...} keys.

Method of the class: WP_REST_Pattern_Directory_Controller{}

No Hooks.

Return

String. Transient key.

Usage

// protected - for code of main (parent) or child class
$result = $this->get_transient_key( $query_args );
$query_args(array) (required)
Query arguments to generate a transient key from.

Changelog

Since 6.0.0 Introduced.

WP_REST_Pattern_Directory_Controller::get_transient_key() code WP 6.7.2

protected function get_transient_key( $query_args ) {

	if ( isset( $query_args['slug'] ) ) {
		// This is an additional precaution because the "sort" function expects an array.
		$query_args['slug'] = wp_parse_list( $query_args['slug'] );

		// Empty arrays should not affect the transient key.
		if ( empty( $query_args['slug'] ) ) {
			unset( $query_args['slug'] );
		} else {
			// Sort the array so that the transient key doesn't depend on the order of slugs.
			sort( $query_args['slug'] );
		}
	}

	return 'wp_remote_block_patterns_' . md5( serialize( $query_args ) );
}