I asked here how to create virtual pages with information from the user meta profile fields using an external class. I got a good answer and also I have implemented it successfully (thanks to @g-m!). At the same time, the author of answer suggested me that what I want can be done "in a lot simpler and more performant way", using the core WP functions, just creating a real post type: registering a CPT, maybe not public (so no UI is showed on dashboard), and on user profile saving/updating just created/updated CPT entry.
This is how I created and saved initially some extra user profile fields:
/* Add Extra Fields to the User Profile */
add_action( 'show_user_profile', 'extra_user_profile_fields' );
add_action( 'edit_user_profile', 'extra_user_profile_fields' );
function extra_user_profile_fields( $user ) { ?>
<h3><?php _e("Academic", "blank"); ?></h3>
<table class="form-table">
<!-- Teaching position -->
<tr>
<th><label for="teaching_position"><?php _e("Teaching position"); ?></label></th>
<td>
<input type="text" name="teaching_position" id="teaching_position" value="<?php echo esc_attr( get_the_author_meta( 'teaching_position', $user->ID ) ); ?>" class="regular-text" /><br />
<span class="description"><?php _e("Put here your teaching position"); ?></span>
</td>
</tr>
</table>
}
/* Save Extra User Profile Fields */
add_action( 'personal_options_update', 'save_extra_user_profile_fields' );
add_action( 'edit_user_profile_update', 'save_extra_user_profile_fields' );
function save_extra_user_profile_fields( $user_id ) {
if ( !current_user_can( 'edit_user', $user_id ) ) { return false; }
update_user_meta( $user_id, 'teaching_position', $_POST['teaching_position'] );
}
What I want, is to put on my site a list of department members with links to their personal pages (e.g. example.com/users/user_nicename) with some content from their profiles. Pages must be created automatically, so I do not have to create manually a personal page for each new member. How can this be achieved (except the cited solution)?