Title: Function call from table trigger
Last modified: September 17, 2020

---

# Function call from table trigger

 *  Resolved [mannyotr](https://wordpress.org/support/users/mannyotr/)
 * (@mannyotr)
 * [5 years, 8 months ago](https://wordpress.org/support/topic/function-call-from-table-trigger/)
 * Hello. I would like to create a trigger on the WP_USERS table that calls one 
   of the custom functions in my child theme’s functions.php. I need to call this
   function after insert of a new user and pass it the new user’s ID and USER_EMAIL.
 * Basically this is what I would like to do…
 * [Screen Shot](https://i.imgur.com/JdweR16.png)
 * How could I accomplish that? Any help would be greatly appreciated.

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

 *  [Howdy_McGee](https://wordpress.org/support/users/howdy_mcgee/)
 * (@howdy_mcgee)
 * [5 years, 8 months ago](https://wordpress.org/support/topic/function-call-from-table-trigger/#post-13421757)
 * Not _exactly_ what you’re looking for but I don’t see a reason why you can’t 
   use WordPress hooks to accomplish whatever you want to do. You could put it in
   a theme or plugin. For example, if we look at the [`wp_insert_user()`](https://developer.wordpress.org/reference/functions/wp_insert_user/)
   function, which is called whenever a new user is created, we have a few hooks
   to work with:
 * The [`wp_pre_insert_user_data` filter hook](https://developer.wordpress.org/reference/hooks/wp_pre_insert_user_data/)
   allows you to modify any user data before it’s inserted into the database.
 * The `user_register` action hook allows you to fire additional actions right after
   a new user has registered to your website. For example:
 *     ```
       /**
        * Do XYZ after a new user registers.
        *
        * @param Integer $user_id
        *
        * @return void
        */
       function wp13420698_user_registered( $user_id ) {
   
       	$user = get_user_by( 'ID', $user_id );	// User Object
   
       	// Do something with the userdata
       	error_log( $user->user_email );
       	error_log( $user->first_name );
   
       	// Get some other metadata
       	$additional_meta = get_user_meta( $usr_id, 'my_key', true );
   
       	// Call a function
       	my_function_call( $user );
   
       	// Create a new object
       	$thing = new Thing( $user );
   
       	// Trigger another action
       	do_action( 'my_user_registered_action', $user, $thing );
   
       }
       add_action( 
       	'user_register',				// Hook Name
       	'wp13420698_user_registered',	// Callback
       	10,								// Priority
       	1								// Arguments
       );
       ```
   
 * Hopefully the above helps!
 *  Thread Starter [mannyotr](https://wordpress.org/support/users/mannyotr/)
 * (@mannyotr)
 * [5 years, 7 months ago](https://wordpress.org/support/topic/function-call-from-table-trigger/#post-13439501)
 * Thank you [@howdy_mcgee](https://wordpress.org/support/users/howdy_mcgee/) this
   worked like a charm!

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

The topic ‘Function call from table trigger’ is closed to new replies.

## Tags

 * [triggers](https://wordpress.org/support/topic-tag/triggers/)

 * In: [Developing with WordPress](https://wordpress.org/support/forum/wp-advanced/)
 * 2 replies
 * 2 participants
 * Last reply from: [mannyotr](https://wordpress.org/support/users/mannyotr/)
 * Last activity: [5 years, 7 months ago](https://wordpress.org/support/topic/function-call-from-table-trigger/#post-13439501)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
