With the below two functions I can add a textarea custom user meta field named 'publications' to the user profile and save/update it:
add_action( 'show_user_profile', 'extra_user_profile_fields' );
add_action( 'edit_user_profile', 'extra_user_profile_fields' );
function extra_user_profile_fields( $user ) { ?>
<textarea rows="10" cols="450" name="publications" id="publications" class="regular-text" />
<?php echo esc_attr( get_the_author_meta( 'publications', $user->ID ) ); ?></textarea>
<?php }
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, 'publications', $_POST['publications'] );
}
With the next function I can display the meta data from the field created above on an user page, with a shortcode [USER_META user_id=2 meta="publications"]
:
add_shortcode('USER_META', 'user_meta_shortcode_handler');
function user_meta_shortcode_handler($atts,$content=null){
return esc_html(get_user_meta($atts['user_id'], $atts['meta'], true));
}
The problem is that in the textarea I can format the text with simple paragraphs, but when it is displayed on front-end the paragraphs disappear and I see only a simple text flow. How to solve this?
I have Wordpress 3.5, Twenty Twelve Theme.
user_meta
instead ofUSER_META
.