小编Llo*_*oyd的帖子

将名字和姓氏添加到 Wordpress 注册表单

我的 WP 注册表单只有用户名、电子邮件和密码选项。

//1. firstname
Run Code Online (Sandbox Code Playgroud)

add_action( 'register_form', 'myplugin_register_form' ); 函数 myplugin_register_form() {

$first_name = ( ! empty( $_POST['first_name'] ) ) ? trim( $_POST['first_name'] ) : '';

    ?>

    <?php
}

//2. Add validation. In this case, we make sure first_name is required.
add_filter( 'registration_errors', 'myplugin_registration_errors', 10, 3 );
function myplugin_registration_errors( $errors, $sanitized_user_login, $user_email ) {

    if ( empty( $_POST['first_name'] ) || ! empty( $_POST['first_name'] ) && trim( $_POST['first_name'] ) == '' ) {
        $errors->add( 'first_name_error', __( '<strong>ERROR</strong>: You must include a …
Run Code Online (Sandbox Code Playgroud)

php wordpress

3
推荐指数
1
解决办法
4304
查看次数

标签 统计

php ×1

wordpress ×1