wordpress 给原生注册页面添加自定义字段

在不使用 wordpress 插件的情况下,我们可以修改 wordpress 的原生注册页面添加自定义字段.

示例 : 比如我门需要添加密码和确认密码输入框,让注册用户输入密码,注册成功后给用户发送邮件

wordpress 给原生注册页面添加自定义字段_第1张图片

示例代码:

//给注册页面添加 :密码输入、本站站名验证
    add_action( 'register_form', 'ts_show_extra_register_fields' );
    add_action( 'register_form', 'ts_show_extra_register_fields' );
    function ts_show_extra_register_fields(){
        ?>
        

add( 'passwords_not_matched', "Error: Entered passwords differ" ); } } // 注册成功写库 add_action( 'user_register', 'ts_register_extra_fields' ); function ts_register_extra_fields( $user_id ){ $userdata = array(); $userdata['ID'] = $user_id; if ( $_POST['password'] !== '' ) { $userdata['user_pass'] = $_POST['password']; } $new_user_id = wp_update_user( $userdata ); // 发送邮件 $custom_subject = "Aragon Tourism: Registered Successfully"; $msg = "Congratulations, you've been registered successfully on Aragon Tourism Site!". "\r\n\r\n"; $msg .= "Username:" .$_POST['user_login']; wp_mail($_POST['user_email'],$custom_subject,$msg); } add_action('phpmailer_init', 'wse199274_intercept_registration_email'); function wse199274_intercept_registration_email($phpmailer){ $admin_email = get_option( 'admin_email' ); # Intercept username and password email by checking subject line if( strpos($phpmailer->Subject, 'Your username and password info') ){ # clear the recipient list $phpmailer->ClearAllRecipients(); # optionally, send the email to the WordPress admin email $phpmailer->AddAddress($admin_email); }else{ #not intercepted } } add_action('phpmailer_init', 'wse19927411_intercept_registration_email'); function wse19927411_intercept_registration_email($phpmailer){ $admin_email = get_option( 'admin_email' ); # Intercept username and password email by checking subject line if( strpos($phpmailer->Subject, 'Notice of Password Change') ){ # clear the recipient list $phpmailer->ClearAllRecipients(); # optionally, send the email to the WordPress admin email $phpmailer->AddAddress($admin_email); }else{ #not intercepted } }

wordpress 给原生注册页面添加自定义字段_第2张图片

你可能感兴趣的:(wordpress)