If any WordPress dev can help me to understand what is the exact difference between functions esc_attr() and sanitize_text_field() ?
I would like to submit email value to the database first and then retrieve the same in different classes that I've created. With sanitize_text_field I am able to remove html tags like h2, h3 and other but I do not quite understand what exactly est_attr function does while echoing both. Below is the snippet of my function, any detailed explanation with example will help me and others who wants to understand it thoroughly. Or are there any better alternative php or wp functions to use while submitting such information to database and retrieve the same?
public static function smtp_email_id()
{
$smtp_email_id = esc_attr( get_option( 'smtp_email_id' ) );
echo '<input type="email" class="regular-text" name="smtp_email_id" value="'.$smtp_email_id.'" placeholder="username@email.com" />';
}
Thank you guys