Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Add new Google+ field to WordPress profiles
<?php
/*
* Add Google field to WordPress profile
* Kudos to Justin Tadlock
* http://justintadlock.com/archives/2009/09/10/adding-and-using-custom-user-profile-fields
*/
// Display the new field
function werewp_googleplus_field( $user ) { ?>
<h3>Extra profile information</h3>
<table class="form-table">
<tr>
<th><label for="googleplus">Google +</label></th>
<td>
<input type="text" name="googleplus" id="googleplus" value="<?php echo esc_attr( get_the_author_meta( 'googleplus', $user->ID ) ); ?>" class="regular-text" /><br />
<span class="description">Please enter your Google+ profile ID</span>
</td>
</tr>
</table>
<?php }
add_action( 'show_user_profile', 'werewp_googleplus_field' );
add_action( 'edit_user_profile', 'werewp_googleplus_field' );
// Save Google+ field
function werewp_save_googleplus_field( $user_id ) {
if ( !current_user_can( 'edit_user', $user_id ) )
return false;
update_usermeta( $user_id, 'googleplus', $_POST['googleplus'] );
}
add_action( 'personal_options_update', 'werewp_save_googleplus_field' );
add_action( 'edit_user_profile_update', 'werewp_save_googleplus_field' );
// Add paragraph with link to Google Profile, by inserting the function werewp_author_bio in your template files
function werewp_author_bio() {
if ( get_the_author_meta( 'googleplus' ) ) { ?>
<p class="googleplus">
<a rel="author" href="https://plus.google.com/<?php the_author_meta( 'googleplus' ); ?>/about" title="Circle me on Google+">Circle me on Google+</a>
</p>
<?php }
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.