I am building a custom login and register form in the theme of my client's website, and I need to process any error messages into a variable that can be displayed on the page within the form. I am using shortcodes for the forms themselves, so using the 'after_setup_theme' action executes after the shortcodes are rendered, meaning any variables I set can't be used in the shortcode itself. This also means that on a successful login, is_user_logged_in() was already checked beforehand, so it still thinks the user is not actually logged in.
Is there another action that takes place BEFORE 'after_setup_theme' that I can use to process the login and store any error variables?
EDIT: Here is the custom function for processing the login and the action hook. For the moment, I have the error printing on the page and moving it into the form with jQuery, but I'd rather find a solution that allows me to print it where it belongs, so I don't have to manipulate the DOM elements on load.
function custom_login() { if(!is_admin() && !preg_match('*wp-login.php*', $_SERVER['REQUEST_URI'])) { $username = isset($_POST['log']) && strlen($_POST['log']) ? $_POST['log'] : ''; $password = isset($_POST['pwd']) && strlen($_POST['pwd']) ? $_POST['pwd'] : ''; if(strlen($username)) { $creds = array(); $creds['user_login'] = $username; $creds['user_password'] = $password; $creds['remember'] = true; $user = wp_signon($creds, false); if (is_wp_error($user)) { $login_error = '<div style="display: none;" id="login-error">'.$user->get_error_message().'</div>'; echo $login_error; } else { if(isset($_POST['redirect_to']) && strlen($_POST['redirect_to']) > 3) { wp_redirect($_POST['redirect_to']); } else { wp_redirect(home_url().'/login/'); } } } } } // run it before the headers and cookies are sent if(isset($_POST['frontend_login'])) { add_action('after_setup_theme', 'custom_login'); }