Bellow is how I currently add, save and display an extra user meta field:
/* Add Extra Fields to the User Profile */
function extra_user_profile_fields( $user ) {
?>
<table class="form-table">
<tr>
<th><label for="publications"><?php _e("Publications"); ?></label></th>
<td>
<textarea rows="10" cols="450" name="publications" id="publications" class="regular-text" />
<?php echo esc_attr( get_the_author_meta( 'publications', $user->ID ) ); ?>
</textarea><br />
</td>
</tr>
</table>
<?php
}
add_action( 'personal_options_update', 'save_extra_user_profile_fields' );
add_action( 'edit_user_profile_update', 'save_extra_user_profile_fields' );
/* 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, 'publications', $_POST['publications'] );
}
/* Display the selected user meta data with a shortcode */
add_shortcode('user_meta', 'user_meta_shortcode_handler');
/* usage: [user_meta user_id=1] */
function user_meta_shortcode_handler($atts,$content=null){ ?>
<?php
echo '<h3>Publicații</h3>';
echo wpautop(get_user_meta($atts['user_id'], 'publications', true));
?>
<?php
}
In this way, with only one shortcode I can display multiple metadata at the same time. Now I want to modify this code to be able to save also a label for each user meta field and to display it/them later together with the corresponding value. How to do this with my code?