Skip to content

Instantly share code, notes, and snippets.

@LinzardMac
Created February 14, 2015 20:33
Show Gist options
  • Save LinzardMac/0a19fae4062cc0ca84d5 to your computer and use it in GitHub Desktop.
Save LinzardMac/0a19fae4062cc0ca84d5 to your computer and use it in GitHub Desktop.
function csc_forgot_password(){
$username = trim($_POST['csc_forgot_login']);
$user_exists = false;
// First check by username
if ( username_exists( $username ) ){
$user_exists = true;
$user = get_user_by('login', $username);
}
elseif(!username_exists($username)) {
// invalid username
//trying to see if i can pass a variable from this function to the csc_errors function
csc_errors('forgot')->add('username_invalid', __('Invalid username'));
}
/ .. more unnecessary code you don't need to see for these purposes ../
}
// used for tracking error messages
// does putting the variable here collect it from where it was used?
function csc_errors($form_type){
static $wp_error; // Will hold global variable safely
return isset($wp_error) ? $wp_error : ($wp_error = new WP_Error(null, null, null));
}
// displays error messages from form submissions
function csc_show_error_messages() {
global $form_type;
// want to output errors only on the function that triggered the error
if($codes = csc_errors($form_type)->get_error_codes()) {
echo '<div class="csc_errors">';
// Loop error codes and display errors
foreach($codes as $code){
$message = csc_errors('forgot')->get_error_message($code);
echo '<span class="error"><strong>' . __('Error') . '</strong>: ' . $message . '</span><br/>';
}
echo '</div>';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment