Title: access object json data post after create_user trigger
Last modified: November 11, 2020

---

# access object json data post after create_user trigger

 *  Resolved [r123ze](https://wordpress.org/support/users/r123ze/)
 * (@r123ze)
 * [5 years, 7 months ago](https://wordpress.org/support/topic/access-object-json-data-post-after-create_user-trigger/)
 * can someone help me, i want to access the value after trigger create_user
 * i have url in WP webhooks like this.
 * [http://localhost/api/call.php](http://localhost/api/call.php)
 * once new user register, i want to put his email in txt file.
    ** call.php file
 *     ```
       $data = json_decode( file_get_contents('php://input'), true);
       $email = $data->data->email;
       $file = "emails.txt";
       file_put_contents($file, $email);
       ```
   
 * i think **$data->data->email** is null, how to get data, i tried also foreach
   but not working.. any help?
 * The page I need help with: _[[log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fwordpress.org%2Fsupport%2Ftopic%2Faccess-object-json-data-post-after-create_user-trigger%2F%3Foutput_format%3Dmd&locale=en_US)
   to see the link]_

Viewing 5 replies - 1 through 5 (of 5 total)

 *  Thread Starter [r123ze](https://wordpress.org/support/users/r123ze/)
 * (@r123ze)
 * [5 years, 7 months ago](https://wordpress.org/support/topic/access-object-json-data-post-after-create_user-trigger/#post-13650179)
 * i forget, the file txt is created but always empty.
 *  Plugin Contributor [Ironikus](https://wordpress.org/support/users/ironikus/)
 * (@ironikus)
 * [5 years, 6 months ago](https://wordpress.org/support/topic/access-object-json-data-post-after-create_user-trigger/#post-13651339)
 * Hey [@r123ze](https://wordpress.org/support/users/r123ze/) – thank you for reaching
   out. 🙂
 * Since the code you provided above is completely independent of our plugin, I 
   will provide you an example based on your requirements.
    Since you want to fire
   the code after the **create_user** action was fired, I suggest you using the **
   do_action** argument. This allows you to fire custom code directly after the 
   user was created. Here’s what you need to to:
    1. Set the **do_action** argument and as a value, please include **add_txt_file**
    2. Once that’s done, please include the following code into your functions.php 
       file:
    3.     ```
           add_action( 'add_txt_file', 'add_custom_txt_file', 10, 2 );
           function add_custom_txt_file( $user_data, $user_id ){
       
           	//Get the response body from the incoming request
           	$response_body = WPWHPRO()->helpers->get_response_body();
       
           	//Grab the email from the incoming request
           	$email = WPWHPRO()->helpers->validate_request_value( $response_body['content'], 'user_email' );
       
           	//Fire your custom logic
           	$file = "emails.txt";
           	file_put_contents( $file, $email );
           }
           ```
       
 * This code will grab the email from the first layer of the payload, that is sent
   over to the webhook endpoint, and adds it to the file.
    **Please note:** In case
   the key in which you store the email is different than **user_email**, please
   adjust it within the `validate_request_value()` function.
 * I hope this helps you so far. Feel free to let me know in case you have further
   questions. 🙂
    -  This reply was modified 5 years, 6 months ago by [Ironikus](https://wordpress.org/support/users/ironikus/).
 *  Thread Starter [r123ze](https://wordpress.org/support/users/r123ze/)
 * (@r123ze)
 * [5 years, 6 months ago](https://wordpress.org/support/topic/access-object-json-data-post-after-create_user-trigger/#post-13652633)
 * Hi [@ironikus](https://wordpress.org/support/users/ironikus/),
 * thanks for your quick reply.
 * The problem is that i don’t want to do it in wordpress, but in another external
   url wich i put in wp webhooks plugin.
 * I think wpwh plugin fired once registered because it created the emails.txt file,
   but i don’t get the email to store it in txt file.
 * When tried my first code above, i find always the email.txt is empty. But when
   I change it to this.
 *     ```
       $data =  file_get_contents('php://input');
       $file = "emails.txt";
       file_put_contents($file, $data);
       ```
   
 * I get all data in file like this format, but I want only to get email or username
   of the registered user..
 * `{"data":{"ID":"36","user_login":"r123ze","user_pass":"$P$BXnUKsyaZXj3tVBgZ00Wbb9E6HHfK0.","
   user_nicename":"r123ze","user_email":"r1z23@gmail.com","user_url":"","user_registered":"
   2020-11-12 08:48:04",....`
 * If removed json_decode, the create_user fired and create file txt with this data,
   but if i put json_decode, it does not create txt file and not working.. can you
   tell me how to fix this please?
 * Thanks so much! 🙂
 *  Thread Starter [r123ze](https://wordpress.org/support/users/r123ze/)
 * (@r123ze)
 * [5 years, 6 months ago](https://wordpress.org/support/topic/access-object-json-data-post-after-create_user-trigger/#post-13652715)
 * According to outgoing value, the json format is:
 *     ```
       Array
       (
           [data] => Array
               (
                   [ID] => 1
                   [user_login] => admin
                   [user_pass] => $P$BVbptZxEcZV2xDLyYeN.O4ZeG8225d.
                   [user_nicename] => admin
                   [user_email] => admin@ironikus.dev
                   [user_url] => 
                   [user_registered] => 2018-11-06 14:19:18
                   [user_activation_key] => 
                   [user_status] => 0
                   [display_name] => admin
               )
       ...
       ```
   
 * So, if i want to access it, do i need to use oop or Multidimensional php array?
 * `$json->data->user_email;`
    or `$json['data']['user_email']`
 * i want to access it like object oop $json->data->user_email;
 *  Plugin Contributor [Ironikus](https://wordpress.org/support/users/ironikus/)
 * (@ironikus)
 * [5 years, 6 months ago](https://wordpress.org/support/topic/access-object-json-data-post-after-create_user-trigger/#post-13653546)
 * Hey [@r123ze](https://wordpress.org/support/users/r123ze/)
 * With the example given, you format the decoded JSON to be an array (that’s what
   the second parameter is for. Please see [https://www.php.net/manual/de/function.json-decode.php](https://www.php.net/manual/de/function.json-decode.php)
   for that.
 * If you use `$data = json_decode( file_get_contents('php://input'), true);`, then
   you need to access the data using `$json['data']['user_email']`
 * If you access it via `json_decode( file_get_contents('php://input'));`, then 
   you can access it via `$json->data->user_email;`
    -  This reply was modified 5 years, 6 months ago by [Ironikus](https://wordpress.org/support/users/ironikus/).

Viewing 5 replies - 1 through 5 (of 5 total)

The topic ‘access object json data post after create_user trigger’ is closed to 
new replies.

 * ![](https://ps.w.org/wp-webhooks/assets/icon-256x256.jpg?rev=2656397)
 * [WP Webhooks - Automate repetitive tasks by creating powerful automation workflows directly within WordPress](https://wordpress.org/plugins/wp-webhooks/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/wp-webhooks/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/wp-webhooks/)
 * [Active Topics](https://wordpress.org/support/plugin/wp-webhooks/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/wp-webhooks/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/wp-webhooks/reviews/)

## Tags

 * [api](https://wordpress.org/support/topic-tag/api/)
 * [php](https://wordpress.org/support/topic-tag/php/)
 * [webhook](https://wordpress.org/support/topic-tag/webhook/)

 * 5 replies
 * 2 participants
 * Last reply from: [Ironikus](https://wordpress.org/support/users/ironikus/)
 * Last activity: [5 years, 6 months ago](https://wordpress.org/support/topic/access-object-json-data-post-after-create_user-trigger/#post-13653546)
 * Status: resolved