I am experimenting with showing selected data from an API response in a form submission confirmation in wordpress. This will be with POST in reality but have used GET for testing. I have the following which works for showing a single value from the JSON response ('id' in this case). I want to know how to write the print_r instruction to print 2 or 3 of the values (by name rather than position). For example show the 'id' and the 'login' values. I've used github api for demo.
add_filter( 'gform_confirmation_4', 'custom_confirmation', 10, 4 );
function custom_confirmation( $confirmation, $form, $entry, $ajax ) {
$response = wp_remote_get( 'https://api.github.com/users/someuser' );
if ( is_wp_error( $response ) ) {
echo 'An error happened';
} else {
$body = wp_remote_retrieve_body( $response );
$data = json_decode( $body );
}
$confirmation .= print_r( $data->id, true );
return $confirmation;
}
I was assuming something like
$confirmation .= print nl2br(print_r($data->id, true), ($data->login, true));
but finding how to print_r multiple specific values with this '->' format is something I don't see in the manuals or forums.
between the " " generates the new line in this example. Brilliant. – edindubai Jan 02 '20 at 10:58