Created
June 13, 2012 13:59
-
-
Save davehewy/2924233 to your computer and use it in GitHub Desktop.
WP Custom Profile Fields
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
Plugin Name: Custom Profile Fields | |
Plugin URI: http://bytewire.co.uk/wordpress/plugins/custom-profile-fields/ | |
Description: Create custom fields in the WP admin back panel for users. | |
Version: 1.0 | |
Author: David Heward | |
Author URI: http://davidheward.com | |
Text Domain: custom-profile-fields | |
*/ | |
/* Copyright 2009-2012 David Heward (email : dave@bytewire.co.uk) | |
This program is free software; you can redistribute it and/or modify | |
it under the terms of the GNU General Public License as published by | |
the Free Software Foundation; either version 3 of the License, or | |
(at your option) any later version. | |
This program is distributed in the hope that it will be useful, | |
but WITHOUT ANY WARRANTY; without even the implied warranty of | |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
GNU General Public License for more details. | |
You should have received a copy of the GNU General Public License | |
along with this program; if not, write to the Free Software | |
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | |
*/ | |
add_action( 'show_user_profile', 'my_show_extra_profile_fields' ); | |
add_action( 'edit_user_profile', 'my_show_extra_profile_fields' ); | |
function my_show_extra_profile_fields( $user ) { ?> | |
<h3>Extra profile information</h3> | |
<table class="form-table"> | |
<tr> | |
<th><label for="google_plus">Google Plus Account</label></th> | |
<td> | |
<input type="text" name="google_plus" id="google_plus" value="<?php echo esc_attr( get_the_author_meta( 'google_plus', $user->ID ) ); ?>" class="regular-text" /><br /> | |
<span class="description">Please enter your Google Plus account ID eg. 111107779224038887638</span> | |
</td> | |
</tr> | |
</table> | |
<?php } | |
add_action( 'personal_options_update', 'my_save_extra_profile_fields' ); | |
add_action( 'edit_user_profile_update', 'my_save_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_usermeta( $user_id, 'google_plus', $_POST['google_plus'] ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment