Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * Template Name: Registration Page
- *
- * This is the template that displays all pages by default.
- * Please note that this is the WordPress construct of pages
- * and that other 'pages' on your WordPress site may use a
- * different template.
- *
- * @link https://developer.wordpress.org/themes/basics/template-hierarchy/
- *
- * @package worldofdominas
- */
- if ( isset($_POST['submit'] ) ) {
- $username = sanitize_text_field( $_POST['username'] );
- $email = sanitize_email( $_POST['email'] );
- $password = sanitize_text_field( $_POST['password'] );
- $errors = array();
- if ( empty( $username ) || empty( $email ) || empty( $password ) ) {
- $errors[] = 'Пожалуйста, заполните все обязательные поля.';
- }
- if ( !is_email( $email ) ) {
- $errors[] = 'Неверный формат email.';
- }
- if ( username_exists( $username ) ) {
- $errors[] = 'Логин уже занят.';
- }
- if ( email_exists( $email ) ) {
- $errors[] = 'Email уже зарегистрирован.';
- }
- if ( empty( $errors ) ) {
- wp_create_user( $username, $password, $email );
- echo '<div style="color: green;">Регистрация прошла успешно!</div>';
- } else {
- foreach ( $errors as $error ) {
- echo '<div style="color: red;">' . $error . '</div>';
- }
- }
- }
- get_header();
- ?>
- <main id="primary">
- <div class="registration-form">
- <form action="<?php echo esc_url( $_SERVER['REQUEST_URI'] ); ?>" method="post">
- <p>
- <label for="username">Логин <strong>*</strong></label>
- <input type="text" name="username" value="<?php echo ( isset( $_POST['username'] ) ? esc_attr( $_POST['username'] ) : '' ); ?>" size="40" />
- </p>
- <p>
- <label for="email">Email <strong>*</strong></label>
- <input type="email" name="email" value="<?php echo ( isset( $_POST['email'] ) ? esc_attr( $_POST['email'] ) : '' ); ?>" size="40" />
- </p>
- <p>
- <label for="password">Пароль <strong>*</strong></label>
- <input type="password" name="password" value="<?php echo ( isset( $_POST['password'] ) ? esc_attr( $_POST['password'] ) : '' ); ?>" size="40" />
- </p>
- <p>
- <input type="submit" name="submit" value="Регистрация"/>
- </p>
- </form>
- </div>
- </main><!-- #main -->
- <?php get_footer();?>
Advertisement
Add Comment
Please, Sign In to add comment