Adding custom profile fields in WordPress made easy through action hooks. .Most of the solutions available on internet tell you about adding custom fields on “Edit User” screen, in this tutorial I will tell you how to add your custom fields to Add New User screen Need help? You can Email me or Skype chat First let’s create a custom field, say “Company Name” and show it on both Add/Update user screens. Above code will add a new field labeled “Company Name”. Notice the third hook “user_new_form”, this hook will display the field on Add New User screen. Lastly we need to save the custom field in database.
function custom_user_profile_fields($user){ if(is_object($user)) $company = esc_attr( get_the_author_meta( 'company', $user->ID ) ); else $company = null; ?> <h3>Extra profile information</h3> <table class="form-table"> <tr> <th><label for="company">Company Name</label></th> <td> <input type="text" class="regular-text" name="company" value="<?php echo $company; ?>" id="company" /><br /> <span class="description">Where are you?</span> </td> </tr> </table> <?php } add_action( 'show_user_profile', 'custom_user_profile_fields' ); add_action( 'edit_user_profile', 'custom_user_profile_fields' ); add_action( "user_new_form", "custom_user_profile_fields" ); function save_custom_user_profile_fields($user_id){ # again do this only if you can if(!current_user_can('manage_options')) return false; # save my custom field update_user_meta($user_id, 'company', $_POST['company']); } add_action('user_register', 'save_custom_user_profile_fields'); add_action('profile_update', 'save_custom_user_profile_fields');
WordPress
Adding Custom Fields to WordPress User Profile and Add New User page
Adding custom profile fields in WordPress made easy through action hooks. .Most of the solutions available on internet tell you about adding custom fields on &#
· 5 min read
Related posts
WordPress
Script Logic Plugin
Introduction Script Logic is a WordPress plugin that lets you control on which pages scripts and style sheets load using WP’s conditional tags. This plug
WordPress
Multi Image Upload
Multi Image Upload adds a meta box to upload multiple images for posts and pages. You can enable it for custom post types also. Download: http://wordpress.org/p
WordPress
Install WordPress plugins, themes & upgrades without providing FTP access?
You must have experienced that WordPress asks for FTP credentials if you initiate upgrade or install plugins. And sometimes developers don’t have FTP access and