maxworkingwell

page-register.php

Jun 8th, 2024
517
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.50 KB | None | 0 0
  1. <?php
  2. /**
  3.  * Template Name: Registration Page
  4.  *
  5.  * This is the template that displays all pages by default.
  6.  * Please note that this is the WordPress construct of pages
  7.  * and that other 'pages' on your WordPress site may use a
  8.  * different template.
  9.  *
  10.  * @link https://developer.wordpress.org/themes/basics/template-hierarchy/
  11.  *
  12.  * @package worldofdominas
  13.  */
  14.  
  15.  
  16.  if ( isset($_POST['submit'] ) ) {
  17.     $username = sanitize_text_field( $_POST['username'] );
  18.     $email = sanitize_email( $_POST['email'] );
  19.     $password = sanitize_text_field( $_POST['password'] );
  20.  
  21.     $errors = array();
  22.  
  23.     if ( empty( $username ) || empty( $email ) || empty( $password ) ) {
  24.         $errors[] = 'Пожалуйста, заполните все обязательные поля.';
  25.     }
  26.  
  27.     if ( !is_email( $email ) ) {
  28.         $errors[] = 'Неверный формат email.';
  29.     }
  30.  
  31.     if ( username_exists( $username ) ) {
  32.         $errors[] = 'Логин уже занят.';
  33.     }
  34.  
  35.     if ( email_exists( $email ) ) {
  36.         $errors[] = 'Email уже зарегистрирован.';
  37.     }
  38.  
  39.     if ( empty( $errors ) ) {
  40.         wp_create_user( $username, $password, $email );
  41.         echo '<div style="color: green;">Регистрация прошла успешно!</div>';
  42.     } else {
  43.         foreach ( $errors as $error ) {
  44.             echo '<div style="color: red;">' . $error . '</div>';
  45.         }
  46.     }
  47. }
  48.  
  49.  
  50. get_header();
  51. ?>
  52.  
  53.     <main id="primary">
  54.  
  55.     <div class="registration-form">
  56.     <form action="<?php echo esc_url( $_SERVER['REQUEST_URI'] ); ?>" method="post">
  57.         <p>
  58.             <label for="username">Логин <strong>*</strong></label>
  59.             <input type="text" name="username" value="<?php echo ( isset( $_POST['username'] ) ? esc_attr( $_POST['username'] ) : '' ); ?>" size="40" />
  60.         </p>
  61.         <p>
  62.             <label for="email">Email <strong>*</strong></label>
  63.             <input type="email" name="email" value="<?php echo ( isset( $_POST['email'] ) ? esc_attr( $_POST['email'] ) : '' ); ?>" size="40" />
  64.         </p>
  65.         <p>
  66.             <label for="password">Пароль <strong>*</strong></label>
  67.             <input type="password" name="password" value="<?php echo ( isset( $_POST['password'] ) ? esc_attr( $_POST['password'] ) : '' ); ?>" size="40" />
  68.         </p>
  69.         <p>
  70.             <input type="submit" name="submit" value="Регистрация"/>
  71.         </p>
  72.     </form>
  73. </div>
  74.  
  75.     </main><!-- #main -->
  76.  
  77. <?php get_footer();?>
Advertisement
Add Comment
Please, Sign In to add comment