编辑:将配置文件字段(usermeta)添加到用户注册
我正在尝试向“添加新用户”页面添加自定义字段,就像我对“用户配置文件”页面所做的那样,如下所示:
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>Player information</h3>
<table class="form-table">
<tr>
<th><label for="team-meta">Team Name</label></th>
<td>
<?php
$status = get_the_author_meta( \'team-meta\', $user->ID );
$items = get_posts (array (
\'post_type\' => \'team_page\',
\'posts_per_page\' => -1
));
echo \'<select name="team-meta" id="team-meta">
<option value="">No team selected</option>\';
foreach($items as $item) {
echo \'<option value="\'.$item->ID.\'"\',$status == $item->ID ? \' selected="selected"\' : \'\',\'>\'.$item->post_title.\'</option>\';
} // end foreach
?>
<span class="description">Please enter the player\'s team name </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_users\', $user_id ) )
return false;
update_user_meta( $user_id, \'team-meta\', $_POST[\'team-meta\'] );
}
基本上,我希望任何创建新用户的人都能够直接添加此内容,而无需访问用户配置文件。