Skip to content

Instantly share code, notes, and snippets.

@xnau
Created October 8, 2025 19:58
Show Gist options
  • Select an option

  • Save xnau/b9b2343df562ce83514490b8c64508a1 to your computer and use it in GitHub Desktop.

Select an option

Save xnau/b9b2343df562ce83514490b8c64508a1 to your computer and use it in GitHub Desktop.
Demonstrates a method for checking two fields for a username match when using the Participants Database Login
<?php
/**
* Plugin Name: PDB Login Check Multiple Usernames
* Description: check two fields for a username match
* Version: 0.1
*/
add_filter( 'pdb-login_username_query', 'xnau_modify_login_query' );
/**
* adds a secondary check field to the login query
*
* @param string $query
* @return string modified query
*/
function xnau_modify_login_query( $query )
{
// this is the name of the secondary field to check
$second_field = 'email_2';
/*
* this uses a regular expression to add the secondary field check to the login query
*/
$query = preg_replace( '/^(.+ = (.+))$/', '$1 OR `' . $second_field . '` = $2', $query );
// return the modified query
return $query;
}
@xnau
Copy link
Author

xnau commented Oct 8, 2025

To use this code: How to Install a WordPress Plugin from a Gist

This plugin checks two fields for a match with the username input in the login form. Be sure to type in the name of the second field you want checked where the $second_field variable is assigned.

This will fail if there is more than one record that matches the username input in either field.

You must know how to use regular expressions if you need to edit the way this plugin alters the query. A good help page for regular expressions can be found here: Regular Expressions 101 You must also, of course, know how to write database queries.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment