Skip to content

Instantly share code, notes, and snippets.

@19h47
Last active December 6, 2022 09:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 19h47/2149242aced9856d0b15b24fe14de2ed to your computer and use it in GitHub Desktop.
Save 19h47/2149242aced9856d0b15b24fe14de2ed to your computer and use it in GitHub Desktop.
Determines whether the given billing phone exists.
<?php
/**
* Plugin Name: Billing phone exists
* Plugin URI: https://gist.github.com/19h47/2149242aced9856d0b15b24fe14de2ed
* Description: A simple function to determines whether the given billing phone exists.
* Version: 1.0.0
* Author: Jérémy Levron
* Author URI: https://19h47.fr
*/
if ( ! function_exists( 'billing_phone_exists' ) ) {
/**
* Determines whether the given billing phone exists.
*
* @param string $phone The billing phone to check for existence.
* @see https://developer.wordpress.org/reference/functions/email_exists/
* @see https://developer.wordpress.org/reference/functions/get_user_by/
*
* @return int|false The user ID on success, false on failure.
*/
function billing_phone_exists( string $phone ) {
$user_id = reset(
get_users(
array(
'meta_key' => 'billing_phone',
'meta_value' => $phone,
'number' => 1,
'fields' => 'ID',
)
)
);
/**
* Filters whether the given phone exists.
*
* @since 1.0.0
*
* @param int|false $user_id The user ID associated with the billing phone,
* or false if the billing phone does not exist.
* @param string $phone The billing phone to check for existence.
*/
return apply_filters( 'phone_exists', $user_id, $phone );
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment