WP自定义注册表

时间:2017-09-08 10:58:10

标签: wordpress customization custom-wordpress-pages

如何在不使用任何插件的情况下从头开始创建或修改WP注册表单? 在网上找不到任何追索权。全部都有插件。

提前致谢

2 个答案:

答案 0 :(得分:0)

add_action( 'register_form', 'myplugin_register_form' );
function myplugin_register_form() {

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

        ?>
        <p>
            <label for="first_name"><?php _e( 'First Name', 'mydomain' ) ?><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>
        <?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 first name.', 'mydomain' ) );
        }

        return $errors;
    }

    //3. Finally, save our extra registration user meta.
    add_action( 'user_register', 'myplugin_user_register' );
    function myplugin_user_register( $user_id ) {
        if ( ! empty( $_POST['first_name'] ) ) {
            update_user_meta( $user_id, 'first_name', trim( $_POST['first_name'] ) );
        }
    }

答案 1 :(得分:0)

我通常从头开始创建一个插件,以便能够制作自定义联系表单 - 请参阅:https://codex.wordpress.org/Writing_a_Plugin

您的插件需要显示一个表单,即:

E12:F15

然后在你的

contact_form.php

做类似的事情:

<form id="myform" method="post" action="contact_form.php">
    <input type="text" name="first_name" />
    <input type="text" name="last_name" />
    <textarea rows="10" name="message" />
    <input type="submit" value="Submit" />
</form>

我希望这可以帮助你!

学习如何构建WP插件将在未来极大地帮助您,因此有必要深入了解WP文档以获得更广泛的知识。祝你好运! : - )