As user profiles are created or updated, WordPress offers an easy way to register a callback to save custom user data in the site's database. This recipe shows how to use this action hook.
You should have already followed the Adding custom fields to the user editor recipe to have a starting point for this recipe and the resulting plugin should still be active in your development site. Alternatively, you can get the resulting code (
Chapter 7/ch2-private-item-text/ch2-private-item-text-v3.php) from the downloaded code bundle, renaming it as
- Navigate to the
ch2-private-item-textfolder of the WordPress plugin directory of your development installation.
- Open the
ch2-private-item-text.phpfile in a text editor.
- Add the following lines of code at the end of the file to register functions to be called when user data is stored upon initial creation or when a user is updated:
add_action( 'user_register', 'ch2pit_save_user_data...