Manage WordPress Errors
-
Hello,
I am building a custom registration plugin and had everything working all right, except showing the eventual errors on the front page.
This is a brief example of the functions I’m using, some of the code has been cut out for “keeping it simple” reasons, but mostly similar with code from wp-login.php:
add_action('init', 'rms_check_login'); function rms_check_login() { $user_login = sanitize_user( $_POST['username'] ); $user_email = apply_filters( 'user_registration_email', $_POST['email'] ); ........................................................ // check form fields for errors if ( $user_login == '' ) { $errors->add( 'empty_username', __( '<strong>ERROR</strong>: Please enter a username.' ) ); } ................................................................... $errors = new WP_Error(); if ( $errors->get_error_code() ) { // !!! need to capture errors and show them on the front-end !!! return $errors->get_error_message(); } else { // insert new user and send notification $user_pass = wp_generate_password(); $user_id = wp_create_user($user_login, $user_pass, $user_email); ................................................................. wp_redirect( $redirect_to ); exit; } }
I don’t know what I’m doing wrong but I am not able to capture the eventual errors and show them on the front page, please help!
The custom registration form is part of a regular WordPress page (e.g. https://mydomain.com/registration-form/).
Thank you very much for your time and looking forward for your thoughts.
Best regards.
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
- The topic ‘Manage WordPress Errors’ is closed to new replies.