• Resolved mannyotr

    (@mannyotr)


    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

    How could I accomplish that? Any help would be greatly appreciated.

Viewing 2 replies - 1 through 2 (of 2 total)
  • 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() 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 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

    (@mannyotr)

    Thank you @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.