wpcf7_count_form_tag_handler

The Contact Form 7 wpcf7 count form tag handler function.

Description

wpcf7_count_form_tag_handler( $tag ); 

Parameters (1)

0. $tag
The tag.

Usage

  1. if ( !function_exists( 'wpcf7_count_form_tag_handler' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'contact-form-7/modules/count.php'; 
  3.  
  4. // The tag. 
  5. $tag = null; 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = wpcf7_count_form_tag_handler($tag); 
  9.  

Defined (1)

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

/modules/count.php  
  1. function wpcf7_count_form_tag_handler( $tag ) { 
  2. $tag = new WPCF7_FormTag( $tag ); 
  3.  
  4. if ( empty( $tag->name ) ) { 
  5. return ''; 
  6.  
  7. $targets = wpcf7_scan_form_tags( array( 'name' => $tag->name ) ); 
  8. $maxlength = $minlength = null; 
  9.  
  10. while ( $targets ) { 
  11. $target = array_shift( $targets ); 
  12. $target = new WPCF7_FormTag( $target ); 
  13.  
  14. if ( 'count' != $target->type ) { 
  15. $maxlength = $target->get_maxlength_option(); 
  16. $minlength = $target->get_minlength_option(); 
  17. break; 
  18.  
  19. if ( $maxlength && $minlength && $maxlength < $minlength ) { 
  20. $maxlength = $minlength = null; 
  21.  
  22. if ( $tag->has_option( 'down' ) ) { 
  23. $value = (int) $maxlength; 
  24. $class = 'wpcf7-character-count down'; 
  25. } else { 
  26. $value = '0'; 
  27. $class = 'wpcf7-character-count up'; 
  28.  
  29. $atts = array(); 
  30. $atts['id'] = $tag->get_id_option(); 
  31. $atts['class'] = $tag->get_class_option( $class ); 
  32. $atts['data-target-name'] = $tag->name; 
  33. $atts['data-starting-value'] = $value; 
  34. $atts['data-current-value'] = $value; 
  35. $atts['data-maximum-value'] = $maxlength; 
  36. $atts['data-minimum-value'] = $minlength; 
  37. $atts = wpcf7_format_atts( $atts ); 
  38.  
  39. $html = sprintf( '<span %1$s>%2$s</span>', $atts, $value ); 
  40.  
  41. return $html;