Php 如何在wordpress multisite中为新用户注册向注册页面添加新字段?
我想在用户注册页面中添加一个自定义字段。如何将字段添加到当前表单中?我尝试了下面的代码,但它不起作用,也没有从、Php 如何在wordpress multisite中为新用户注册向注册页面添加新字段?,php,wordpress,Php,Wordpress,我想在用户注册页面中添加一个自定义字段。如何将字段添加到当前表单中?我尝试了下面的代码,但它不起作用,也没有从、register\u post和user\u register挂钩 add_action('register_form','show_first_name_field'); add_action('register_post','check_fields',10,3); add_action('user_register', 'register_extra_fields'); fun
register\u post
和user\u register
挂钩
add_action('register_form','show_first_name_field');
add_action('register_post','check_fields',10,3);
add_action('user_register', 'register_extra_fields');
function show_first_name_field()
{
?>
<p>
<label>Twitter<br/>
<input id="twitter" type="text" tabindex="30" size="25" value="<?php echo $_POST['twitter']; ?>" name="twitter" />
</label>
</p>
<?php
}
function check_fields ( $login, $email, $errors )
{
global $twitter;
if ( $_POST['twitter'] == '' )
{
$errors->add( 'empty_realname', "<strong>ERROR</strong>: Please Enter your twitter handle" );
}
else
{
$twitter = $_POST['twitter'];
}
}
function register_extra_fields ( $user_id, $password = "", $meta = array() )
{
update_user_meta( $user_id, 'twitter', $_POST['twitter'] );
}
add_动作('register_form','show_first_name_field');
添加操作('register\u post','check\u fields',10,3);
添加操作(“用户注册”、“注册额外字段”);
函数show_first_name_field()
{
?>
推特
这是官方文档上的链接,试试这个:这是官方文档上的链接,试试这个:我解决了它。我使用下面的代码在注册页面中添加自定义字段
/**
* Add additional custom field to profile page
*/
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="twitter">Twitter</label></th>
<td>
<input type="text" name="twitter" id="twitter" value="<?php echo esc_attr( get_the_author_meta( 'twitter', $user->ID ) ); ?>" class="regular-text" /><br />
<span class="description">Please enter your Twitter username.</span>
</td>
</tr>
</table>
<?php
}
/**
* Save data input from custom field on profile page
*/
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, 'twitter', $_POST['twitter'] );
}
/**
* Add cutom field to WPMU registration form
*/
add_action('signup_extra_fields','custom_signup_extra_fields', $errors);
function custom_signup_extra_fields($errors) {
?>
<label>Twitter</label>
<input id="twitter" type="text" size="25" value="<?php echo $_POST['twitter']; ?>" name="twitter" />
<br />
<?php
}
/**
* Save custom field input to wp_signups table
*/
add_filter( 'add_signup_meta', 'custom_add_signup_meta' );
function custom_add_signup_meta ( $meta = array() ) {
$meta['twitter'] = $_POST['twitter'];
return $meta;
}
/**
*将其他自定义字段添加到配置文件页面
*/
添加操作('show_user_profile'、'my_show_extra_profile_fields');
添加操作(“编辑用户配置文件”、“我的显示额外配置文件”字段);
函数my\u show\u extra\u profile\u字段($user)
{
?>
额外配置文件信息
啁啾
我解决了这个问题。我使用下面的代码在注册页面中添加自定义字段
/**
* Add additional custom field to profile page
*/
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="twitter">Twitter</label></th>
<td>
<input type="text" name="twitter" id="twitter" value="<?php echo esc_attr( get_the_author_meta( 'twitter', $user->ID ) ); ?>" class="regular-text" /><br />
<span class="description">Please enter your Twitter username.</span>
</td>
</tr>
</table>
<?php
}
/**
* Save data input from custom field on profile page
*/
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, 'twitter', $_POST['twitter'] );
}
/**
* Add cutom field to WPMU registration form
*/
add_action('signup_extra_fields','custom_signup_extra_fields', $errors);
function custom_signup_extra_fields($errors) {
?>
<label>Twitter</label>
<input id="twitter" type="text" size="25" value="<?php echo $_POST['twitter']; ?>" name="twitter" />
<br />
<?php
}
/**
* Save custom field input to wp_signups table
*/
add_filter( 'add_signup_meta', 'custom_add_signup_meta' );
function custom_add_signup_meta ( $meta = array() ) {
$meta['twitter'] = $_POST['twitter'];
return $meta;
}
/**
*将其他自定义字段添加到配置文件页面
*/
添加操作('show_user_profile'、'my_show_extra_profile_fields');
添加操作(“编辑用户配置文件”、“我的显示额外配置文件”字段);
函数my\u show\u extra\u profile\u字段($user)
{
?>
额外配置文件信息
啁啾