mmtoledo/wordpress-request

There is no license information available for the latest version (dev-master) of this package.

Installs: 14

Dependents: 0

Suggesters: 0

Security: 0

Type:wordpress-plugin

dev-master 2018-10-11 20:00 UTC

This package is not auto-updated.

Last update: 2024-10-06 04:38:37 UTC


README

Enable caching HTTP requests for a default of 5 minutes, logs HTTP errors and request times in a performant and secure manner. Extensible via actions and filters using modern PHP standards and language features.

Installation

Here goes the information for the installation using composer.

Filters

FilterArgument(s)Description
rest_enhancer_cache_keystring $request_uri, WP_REST_Server $server, WP_REST_Request $requestAllows changing the name/key used to caching a responses
rest_enhancer_cache_control_headersarray cache_control_headersAllows to modify control cache header value
rest_enhancer_cache_expirationint secondsAllows to set a different cached expiration time (default 5 minutes)

How to use filters

  • changing the cache timeout

add_filter( 'rest_enhancer_cache_expiration', function() {

// https://codex.wordpress.org/Transients_API#Using_Time_Constants

return  30 * MINUTE_IN_SECONDS;

} );

  • changing cache key name (name used to store cached response)

add_filter( 'rest_enhancer_cache_key', function($currentKey, $server, $request) {
    return "my_custom_key";
} );

Actions

ActionArgument(s)Description
rest_enhancer_response_cachedstring $request_uri, WP_REST_Server $server, WP_REST_Request $requestFires right after the response has been cached

How to use actions


function my_custom_action($cache_key, $request_uri, $request){
    ... do some custom actions
}

add_action( 'rest_enhancer_response_cached', 'my_custom_action', 10, 3);