mardi 31 mars 2015

Adding Extra Fields to the WordPress User Profile

I have a strange problem. I have added custom field to User Profile and used the_author_meta() function for display fields content. Yeasterday works everything great. But today it doesn't work.


Custom field is in User Profile. When I click update profile - the content of fields remains in place (so information should be saved). But on authors page where I have <?php the_author_meta( 'skills' ); ?> happens nothing.


I followed this tutorial when I was creating my own custom field: http://ift.tt/1reTxAH


And this one when I tried to find the error in my code: http://ift.tt/1xUQBy8


They both are similar. I worked with page templates since yesterday, so it maybe caused the problem. So I deleted everything what I've added since yesterday. But nothing changed.


Here is my code:



// CUSTOM FIELD IN USER ADMIN - SAVE
add_action( 'personal_options_update', 'my_save_extra_profile_fields' );
add_action( 'edit_user_profile_update', 'my_save_extra_profile_fields' );


function my_show_extra_profile_fields( $user ) { ?>

<h3>Skills - Färdigheter</h3>

<table class="form-table">

<tr>
<th><label for="skills">Skills</label></th>

<td>
<textarea type="text" name="skills" rows="4" cols="50" id="skills" class="regular-text"><?php echo esc_attr( get_the_author_meta( 'skills', $user->ID ) ); ?></textarea><br>
<span class="description">Please enter your skills.</span>
</td>
</tr>

</table>
<?php }

// CUSTOM FIELD IN USER ADMIN
add_action( 'show_user_profile', 'my_show_extra_profile_fields' );
add_action( 'edit_user_profile', 'my_show_extra_profile_fields' );

function my_save_extra_profile_fields( $user_id ) {

if ( !current_user_can( 'edit_user', $user_id ) )
{return false;}

/* Copy and paste this line for additional fields. Make sure to change 'twitter' to the field ID. */
update_user_meta( $user_id, 'skills', $_POST['skills'] );
}

Aucun commentaire:

Enregistrer un commentaire