esc_attr

Retrieve the translation of $text and escapes it for safe use in an attribute.

Description

(string) esc_attr__( (string) $text, (string) $domain = 'default' ); 

If there is no translation, or the text domain isn't loaded, the original text is returned.

Returns (string)

Translated text on success, original text on failure.

Parameters (2)

0. $text (string)
Text to translate.
1. $domain — Optional. (string) => 'default'
Text domain. Unique identifier for retrieving translated strings. Default default..

Usage

  1. if ( !function_exists( 'esc_attr__' ) ) { 
  2. require_once ABSPATH . WPINC . '/l10n.php'; 
  3.  
  4. // Text to translate. 
  5. $text = ''; 
  6.  
  7. // Optional. Text domain. Unique identifier for retrieving translated strings. 
  8. // Default 'default'. 
  9. $domain = 'default'; 
  10.  
  11. // NOTICE! Understand what this does before running. 
  12. $result = esc_attr__($text, $domain); 
  13.  

Defined (3)

The function is defined in the following location(s).

/wp-includes/l10n.php  
  1. function esc_attr__( $text, $domain = 'default' ) { 
  2. return esc_attr( translate( $text, $domain ) ); 
/wp-includes/formatting.php  
  1. function esc_attr( $text ) { 
  2. $safe_text = wp_check_invalid_utf8( $text ); 
  3. $safe_text = _wp_specialchars( $safe_text, ENT_QUOTES ); 
  4. /** 
  5. * Filters a string cleaned and escaped for output in an HTML attribute. 
  6. * Text passed to esc_attr() is stripped of invalid or special characters 
  7. * before output. 
  8. * @since 2.0.6 
  9. * @param string $safe_text The text after it has been escaped. 
  10. * @param string $text The text prior to being escaped. 
  11. */ 
  12. return apply_filters( 'attribute_escape', $safe_text, $text ); 
/wp-admin/includes/noop.php  
  1. function esc_attr() {}