重温这个有趣的问题,我会说不,这是不可能的.
分析文件时/wp-admin/user-new.php,没有允许这样做的动作挂钩.即使遵循<form>导致无处可使用的功能.
一个可能和脏的解决方案是使用jQuery注入字段.
将新用户添加到数据库时,我们可以使用钩子user_profile_update_errors来更新用户元素(也可以作为hack).
更新:可以添加一个新字段:
add_action( 'user_new_form', function( $type ){
if( 'add-new-user' !== $type )
return;
echo '<input type="text" name="custom_user_field" id="custom_user_field" value=""/>';
});
Run Code Online (Sandbox Code Playgroud)
要获取发布的数据并进行处理,请使用:
add_action( 'user_profile_update_errors', function( $data )
{
if ( is_wp_error( $data->errors ) && ! empty( $data->errors ) )
return;
# Do your thing with $_POST['custom_user_field']
wp_die( sprintf( '<pre>%s</pre>', print_r( $_POST, true ) ) );
});
Run Code Online (Sandbox Code Playgroud)