I'm adding an extra textarea into the WordPress profile, the issue I'm having is that once saved it won't displayed. I've seen a bunch of posts about it, even copy and pasted it in to my functions and no go, is there anything I am missing here?
Old code:
add_action( 'show_user_profile', 'xtra_field' );
add_action( 'edit_user_profile', 'xtra_field' );
function xtra_field( $user ) { ?>
<h3>Teacher Information</h3>
<table class="form-table">
<tr>
<th><label for="teach_year">Year</label></th>
<td>
<input type="number" name="teach_year" id="teach_year" min="1" max="7" value="<?php echo esc_attr( get_the_author_meta( 'teach_year', $user->ID ) ); ?>" class="regular-text" /><br />
<span style="line-height: 42px;" class="description">What year do you teach?</span>
</td>
</tr>
<tr>
<th><label for="class_intro">Class Introduction</label></th>
<td>
<textarea type="text" name="class_intro" id="class_intro" rows="5" cols="30" class="regular-text" value="<?php echo esc_attr( get_the_author_meta( 'class_intro', $user->ID ) ); ?>"></textarea><br/>
<span class="description">Introduce your class.</span>
</td>
</tr>
</table>
<?php }
add_action( 'personal_options_update', 'xtra_save_field' );
add_action( 'edit_user_profile_update', 'xtra_save_field' );
function xtra_save_field( $user_id ) {
if ( !current_user_can( 'edit_user', $user_id ))
return false;
update_user_meta($user_id, 'teach_year', $_POST['teach_year']);
update_user_meta($user_id, 'class_intro', $_POST['class_intro']);
}
Someone offline hinted at echoing out the author meta, this appears to have worked and I've updated the code.
New Code:
add_action( 'show_user_profile', 'xtra_field' );
add_action( 'edit_user_profile', 'xtra_field' );
function xtra_field( $user ) { ?>
<h3>Teacher Information</h3>
<table class="form-table">
<tr>
<th><label for="teach_year">Year</label></th>
<td>
<input type="number" name="teach_year" id="teach_year" min="1" max="7" value="<?php echo esc_attr(get_the_author_meta('teach_year', $user->ID)); ?>" class="regular-text" /><br />
<span style="line-height: 42px;" class="description">What year do you teach?</span>
</td>
</tr>
<tr>
<th><label for="class_intro">Class Introduction</label></th>
<td>
<textarea type="text" name="class_intro" id="class_intro" rows="5" cols="30" class="regular-text"><?php echo esc_html(get_the_author_meta('class_intro', $user->ID) ); ?></textarea>
<br/>
<span class="description">Provide your class with an introduction.</span>
</td>
</tr>
</table>
<?php }
add_action( 'personal_options_update', 'xtra_save_field' );
add_action( 'edit_user_profile_update', 'xtra_save_field' );
function xtra_save_field( $user_id ) {
if ( !current_user_can( 'edit_user', $user_id ))
return false;
update_user_meta($user_id, 'teach_year', $_POST['teach_year']);
update_user_meta($user_id, 'class_intro', $_POST['class_intro']);
}