Our plugins contain a number of actions and filters that help extend or modify the functionality of our plugins. Code snippets would need to be added to your themes functions.php file.
wpgetapi_final_request_args
Modifies the final arguments that are sent to the API.
function wpgetapi_modify_request_args( $args, $wpgetapi ) {
$args['body']['something'] = 'something else';
return $args;
}
add_filter( 'wpgetapi_final_request_args', 'wpgetapi_modify_request_args', 10, 2 );
wpgetapi_should_we_stop
Stops the API from being called until something happens.
function wpgetapi_stop( $stop, $wpgetapi ) {
if( wait until something is true )
return true;
return $stop;
}
add_filter( 'wpgetapi_should_we_stop', 'wpgetapi_stop', 10, 2 );
wpgetapi_before_retrieve_body
Modify the response before any type of formatting.
function wpgetapi_modify_response( $response, $response_code, $wpgetapi ) {
if( $response_code == 401 )
return 'Sorry, you are not authorised.';
return $response;
}
add_filter( 'wpgetapi_before_retrieve_body', 'wpgetapi_modify_response', 10, 3 );
wpgetapi_raw_data
Modify the response after any type of formatting.
function wpgetapi_modify_output( $data, $wpgetapi ) {
if( ! $data )
return 'Sorry, no data returned.';
return $data;
}
add_filter( 'wpgetapi_raw_data', 'wpgetapi_modify_output', 10, 2 );
wpgetapi_endpoint
Modify the endpoint before sending to the API.
function wpgetapi_modify_endpoint( $endpoint, $wpgetapi ) {
$endpoint = $endpoint . '/extra_info';
return $endpoint;
}
add_filter( 'wpgetapi_endpoint', 'wpgetapi_modify_endpoint', 10, 2 );
wpgetapi_query_parameters
Modify the query parameters before sending to the API.
function wpgetapi_modify_query_params( $params, $wpgetapi ) {
$params['some_data'] = 'some value';
return $params;
}
add_filter( 'wpgetapi_query_parameters', 'wpgetapi_modify_query_params', 10, 2 );
wpgetapi_header_parameters
Modify the header parameters before sending to the API.
function wpgetapi_modify_header_params( $params, $wpgetapi ) {
$params['headers']['content-type'] = 'application/json';
return $params;
}
add_filter( 'wpgetapi_header_parameters', 'wpgetapi_modify_header_params', 10, 2 );
wpgetapi_body_parameters
Modify the body parameters before sending to the API.
function wpgetapi_modify_body_params( $params, $wpgetapi ) {
$params['user'] = '[email protected]';
return $params;
}
add_filter( 'wpgetapi_body_parameters', 'wpgetapi_modify_body_params', 10, 2 );
wpgetapi_default_request_args_parameters
This filter will modify the default arguments for the API calls such as timeout, sslverify, redirection and others. The full list of arguments can be found here – https://developer.wordpress.org/reference/classes/wp_http/request/
The filter can be used like below.
function wpgetapi_modify_arguments( $args ) {
$args['timeout'] = 30;
$args['sslverify'] = true;
return $args;
}
add_filter( 'wpgetapi_default_request_args_parameters', 'wpgetapi_modify_arguments', 10, 1 );
wpgetapi_final_url
This filter will modify the final URL that the API is calling.
function wpgetapi_modify_url( $url, $wpgetapi ) {
$url = $url . '?add=something';
return $url;
}
add_filter( 'wpgetapi_final_url', 'wpgetapi_modify_url', 10, 2 );
wpgetapi_before_retrieve_body
This filter can modify the response from the API as soon as we receive it.
function wpgetapi_modify_response( $response, $response_code, $wpgetapi ) {
$response = 'blah blah blah';
return $response;
}
add_filter( 'wpgetapi_before_retrieve_body', 'wpgetapi_modify_response', 10, 3 );