wpcf7_mask_password

The Contact Form 7 wpcf7 mask password function.

Description

wpcf7_mask_password( $text, (int) $length_unmasked = 0 ); 

Parameters (2)

0. $text
The text.
1. $length_unmasked — Optional. (int)
The length unmasked.

Usage

  1. if ( !function_exists( 'wpcf7_mask_password' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'contact-form-7/includes/formatting.php'; 
  3.  
  4. // The text. 
  5. $text = null; 
  6.  
  7. // The length unmasked. 
  8. $length_unmasked = -1; 
  9.  
  10. // NOTICE! Understand what this does before running. 
  11. $result = wpcf7_mask_password($text, $length_unmasked); 
  12.  

Defined (1)

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

/includes/formatting.php  
  1. function wpcf7_mask_password( $text, $length_unmasked = 0 ) { 
  2. $length = strlen( $text ); 
  3. $length_unmasked = absint( $length_unmasked ); 
  4.  
  5. if ( 0 == $length_unmasked ) { 
  6. if ( 9 < $length ) { 
  7. $length_unmasked = 4; 
  8. } elseif ( 3 < $length ) { 
  9. $length_unmasked = 2; 
  10. } else { 
  11. $length_unmasked = $length; 
  12.  
  13. $text = substr( $text, 0 - $length_unmasked ); 
  14. $text = str_pad( $text, $length, '*', STR_PAD_LEFT ); 
  15. return $text;