- Navigate to the ch2-private-item-text folder of the WordPress plugin directory of your development installation.
- Open the ch2-private-item-text.php file 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' );
add_action( 'profile_update', 'ch2pit_save_user_data' );
- Add the following block of code to provide an implementation for the ch2pit_save_user_data function:
function ch2pit_save_user_data( $user_id ) {
global $user_levels;
if ( isset( $_POST['user_level'] ) &&
!empty( $_POST['user_level'] ) &&
array_key_exists( $_POST['user_level'],
$user_levels ) ) {
update_user_meta( $user_id, 'user_level',
$_POST['user_level'] );
} else {
update_user_meta( $user_id, 'user_level', 'regular' );
}
}
- Save and close the plugin file.
- Edit one of the existing users on the site or create a new one to see that the user level value is saved.