The sanitize_email() function is a WordPress function that sanitizes an email address to remove invalid characters and formatting. It is commonly used in WordPress plugins and themes to ensure that user-submitted email addresses are safe and properly formatted.
The function takes a single argument, which is the email address to sanitize. The function returns the sanitized email address, or false if the email address is not valid.
Here’s an example of how to use the sanitize_email() function:
$email = 'firstname.lastname@example.org'; $sanitized_email = sanitize_email( $email ); echo $sanitized_email;
In this example, we first define the $email variable with an email address. We then pass this variable to the sanitize_email() function, which returns the sanitized email address. Finally, we use the echo statement to display the sanitized email address on the screen.
Overall, the sanitize_email() function is a useful tool for ensuring that email addresses submitted by users are safe and properly formatted.