Tell me how to register in Wordpress, the task is simple registration, e-mail and name, but there is no personal account, no administrative part for the user, registration is needed so that the user can see the hidden rubric, how to do it? Those. if the user has registered and entered, then he sees an additional section in the menu.

<form> <input class="form__input form__input_popup icon-1" name='' type="text" placeholder="E-mail" /> <input class="form__input form__input_popup icon-2" name='' type="text" placeholder="******" /> <input class="button button_popup" type="submit" value="Зарегистрироваться" /> </form> 

    2 answers 2

    1) Registration: Paste in functions.php

     add_action( 'admin_post_nopriv_'user_registration', 'user_registration` ); add_action( 'admin_post_'user_registration', 'user_registration` ); function user_registration() { // $user_name и user_email берем из формы регистрации // Таже настоятельно рекомендую провалидировать данные из формы и использовать wp_nonce_field(); $random_password = wp_generate_password(15, false); $user_id = wp_create_user( $user_name, $random_password, $user_email ); if(is_wp_error( $user_id )){ // Обрабатываем ошибку если пользователь не создался $user_id->get_error_message(); }else{ // Устанавоиваем роль пользователю, для данного случая так как для юзера не должна быть видима админка я бы рекомендовал создать кастомную роль, а потом по ней срыть и закрыть от него все что не не стоит видеть $user = new WP_User( $user_id ); $user->set_role( 'contributor' ); // отправляем пользователю письмо с его паролем wp_mail( $user_email, 'Welcome!', 'Your Password: ' . $random_password ); } } 

    2) Arshen form replaceable

     <?php echo esc_url( admin_url('admin-post.php') ); ?> 

    3) Insert the hidden field into the form:

     <input type="hidden" name="action" value="user_registration"> 

    4) Display the hidden category:

     if(is_user_logged_in()){ // можем выводить срытую категрию } 
    • Tell me where this code? in the registration template? - Anton Essential
    • I threw the fields above, tell me where to substitute the values ​​to take the data - Anton Essential
    • More precisely, how to handle all this, in the form tag method of some kind and action? - Anton Essential
    • Modified answer - Andrey Svyrydov

    When displaying a menu, you need to check what the function returns.

     is_user_logged_in(); 

    and if it returns true, it means that the user is registered on the site and logged in with his username and password.

    In this case, he needs to show the required rubric in the menu; otherwise, do not display it on the screen.