dsf6778 2018-01-09 10:44
浏览 68

注册表单挂钩两次显示相同的字段

I have custommized registration form here but this hook is executing it twice.

add_action( 'register_form', array( &$this, 'customize_registration_form' ) );

public function customize_registration_form(){
        $first_name = ( ! empty( $_POST['first_name'] ) ) ? trim( $_POST['first_name'] ) : '';
        $last_name = ( ! empty( $_POST['last_name'] ) ) ? trim( $_POST['last_name'] ) : '';
        ?>
        <p>
            <label for="first_name"><?php _e( 'First Name', $this->textdomain ) ?><br />
                <input type="text" name="first_name" id="first_name" class="input" value="<?php echo esc_attr( wp_unslash( $first_name ) ); ?>" size="25" /></label>
        </p>
        <p>
            <label for="last_name"><?php _e( 'Last Name', $this->textdomain ) ?><br />
                <input type="text" name="last_name" id="last_name" class="input" value="<?php echo esc_attr( wp_unslash( $last_name ) ); ?>" size="25" /></label>
        </p>
        <?php
    }

I am getting same form area twice.How can i solve this issue?

  • 写回答

1条回答 默认 最新

  • doumei1203 2018-01-09 10:57
    关注

    The code seems fine, I'd suggest checking and making sure your class instantiates only once during runtime.

    Try listing all callbacks on the register_form hook (see this SO answer for the ways to do it). There is a chance your method gets hooked twice, thus duplicating the markup. If this is the case, consider using Dependency Injection Container to avoid this type of issues (and many others + other benefits).

    评论

报告相同问题?