Skip to content
Docs
Get RestroPress

Filter

rp_api_token_generate_data

Updated
On this page

Filters the claims array used to build a REST API JWT token.

Runs when a token is generated, either by the token endpoint of the REST auth controller or by the rp_build_user_api_token() helper. The array holds the standard claims iat, jti, iss, aud, nbf and an optional exp, plus a data array with api_key and user_id. The token is signed with HS512. The filter must return an array; any other value aborts generation with an error.

Parameters#

ParameterTypeDescription
$dataarrayJWT claims for the token.

Return value#

array. The token claims. A non-array makes token generation fail.

Example#

function my_token_claims( $data ) {
	$data['data']['site_id'] = get_current_blog_id();
	return $data;
}
add_filter( 'rp_api_token_generate_data', 'my_token_claims' );

Notes#

Fired from both the REST auth controller and rp_build_user_api_token(); the data is identical in shape.

Source#

Applied in:

  • includes/rest-api/Controllers/Version1/class-rp-rest-auth-v1-controller.php (line 151), in RP_REST_Auth_V1_Controller::get_token()
  • includes/user-functions.php (line 1044), in rp_build_user_api_token()

See also#

Was this page helpful?