Last active
December 6, 2022 09:08
-
-
Save 19h47/2149242aced9856d0b15b24fe14de2ed to your computer and use it in GitHub Desktop.
Determines whether the given billing phone exists.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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