它在新用户和编辑用户屏幕中添加字段。别忘了在你的函数中包含这一点。php文件。
<?php
class UserFieldsClass
{
public function __construct()
{
// This will create a new area in the user edit screen and the add new user screen.
add_action( \'user_new_form\', array( $this, \'show_extra_profile_fields\' ) );
add_action( \'show_user_profile\', array( $this, \'show_extra_profile_fields\' ) );
add_action( \'edit_user_profile\', array( $this, \'show_extra_profile_fields\' ) );
add_action( \'personal_options_update\', array($this, \'save_extra_profile_fields\') );
add_action( \'edit_user_profile_update\', array($this, \'save_extra_profile_fields\') );
add_action( \'user_register\', array( $this, \'save_extra_profile_fields\' ) );
}
function show_extra_profile_fields($user)
{ ?>
<h3>More Information</h3>
<table class="form-table">
<tr>
<th><label for="user_skype">Skype:</label></th>
<td>
<input type="text" name="user_skype" id="user_skype"
value="<?php echo esc_attr(get_the_author_meta(\'user_skype\', $user->ID)); ?>"
class="regular-text"/><br/>
<span class="description">Please enter your Skype username.</span>
</td>
</tr>
</table>
<?php }
function save_extra_profile_fields( $user_id ) {
if (!current_user_can(\'manage_options\'))
return false;
update_user_meta($user_id, \'user_skype\', $_POST[\'user_skype\']);
}
}
$userFieldsClass = new UserFieldsClass();