- 🇮🇳India heykarthikwithu Bengaluru 🌍
@apaderno condition check if the user is returning name or not will solve this?
(below is the sample with couple of examples, one with object check & and other with using the fetchField)/** * Checks for usernames blocked by user administration. * * @param $name * A string containing a name of the user. * * @return * Object with property 'name' (the user name), if the user is blocked; * FALSE if the user is not blocked. */ function user_is_blocked($name) { $user = db_select('users') ->fields('users', array('name')) ->condition('name', db_like($name), 'LIKE') ->condition('status', 0) ->execute()->fetchObject(); // Check if name is empty, if empty return FALSE. if (empty($user->name)) { return FALSE; } return $user; }
/** * Checks for usernames blocked by user administration. * * @param $name * A string containing a name of the user. * * @return * Object with property 'name' (the user name), if the user is blocked; * FALSE if the user is not blocked. */ function user_is_blocked($name) { $user = db_select('users') ->fields('users', array('name')) ->condition('name', db_like($name), 'LIKE') ->condition('status', 0) ->execute(); // Check if user name is empty, if empty return FALSE. if (empty($user->fetchField)) { return FALSE; } return $user->fetch(); }
Thanks :)
- Status changed to Closed: works as designed
over 1 year ago 2:43pm 5 August 2023 - 🇸🇰Slovakia poker10
Thanks for reporting this.
I agree with the #5, that this is an expected behavior. Whan you install a Drupal 7 site, there is an user with UID 0 and empty username in the database. Therefore the query will test this user, which is blocked, as it is an internal user for handling default access permissions. I would say that adding additional conditions here would make the function less clear, therefore closing this.