I have added a script in my functions.php file which checks a second custom database within the WordPress database when a member tries to login. This script was working correctly in the past and I just today noticed it stopped working and the validation is not seeming to occur.

Here is the script I have added to my functions.php file.

    add_filter( 'authenticate', 'check_user_status', 30, 3 );
    function check_user_status( $user, $username, $password ) {
      global $wpdb;
      $ismember = $wpdb->get_row( $wpdb->prepare( "SELECT UName FROM custom_table WHERE UName = %s", $username ) );
      $status = $wpdb->get_row( $wpdb->prepare( "SELECT Status FROM custom_table WHERE UName = %s", $username ) );
      $rep = 'YES';
      $blocked = 'NO';
        if ( is_null ( $ismember ) ) {
        return new WP_Error( 'not_found_status', 'User not found, Please try again. If you continue to experience difficulties contact support.' );
        elseif ($status== $rep) {
            return $user;
        elseif ($status == $blocked) {
            return new WP_Error( 'blocked_status', 'It appears that you are currently not able to access member level content at this time. Please contact support' );
        else {
            return $user;

Originally the validation would work as follows

  1. User enters their login credentials
  2. Validation script checks secondary custom database to check the value of a specific column (status).
  3. If the user is not in the secondary database or if the users "status" is "NO" then they are not permitted to login to the website and an error is thrown back.
  4. If their status" is "YES" or "NULL" then they are allowed to log into the website.

Now it doesn't seem to even respond and even when status is no or the user is not even in the custom table I can still log into the site.

How can I get this script to work again? there are no errors going to the error log and when I check the code on phpcodechecker.com there don't seem to be any issues from what it shows.

I am sure to some its a pretty basic issue with a simple fix but I am just not seeing it and could really use a second set of eyes. Thanks Stack Community.

  • I thought I had it working but for some reason the solution worked on one server but not another. what is the right way to do this as I am obviously not doing something right though I can't see it. – DigitalDesigner Sep 5 '18 at 22:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.