<span class="resolved" aria-label="Resolved" title="Topic is resolved."></span>How to add other variables in the API response?

[ad_1]

Replies: 1

Hello, when I make a request the response carries this information:

{
    "token": "example_token",
    "user_email": "[email protected]",
    "user_nicename": "example-pw",
    "user_display_name": "example-user",
}

I need to add user_id as a variable included in the response, I have edited in this file public/class-jwt-auth-public.php and in the line num #196 I have edited this code:

/** The token is signed, now create the object with no sensible user data to the client*/
		$data = [
			'token'             => $token,
			'user_email'        => $user->data->user_email,
			'user_nicename'     => $user->data->user_nicename,
			'user_display_name' => $user->data->display_name,
		];

to this code:

/** The token is signed, now create the object with no sensible user data to the client*/
		$data = [
			'token'             => $token,
			'user_email'        => $user->data->user_email,
			'user_nicename'     => $user->data->user_nicename,
			'user_display_name' => $user->data->display_name,
			'user_id' => $user->data->user_id,
			'userId' => $user->data->id,
		];

I have tried $user->data->user_id and $user->data->id but the code didn’t work the response back NULL in the user_id and userId

this is the response:

{
    "token": "example_token",
    "user_email": "[email protected]",
    "user_nicename": "example-pw",
    "user_display_name": "example-user",
    "user_id": null,
    "userId": null,
}

Any help please?

 

This site will teach you how to build a WordPress website for beginners. We will cover everything from installing WordPress to adding pages, posts, and images to your site. You will learn how to customize your site with themes and plugins, as well as how to market your site online.

Buy WordPress Transfer