wpcf7_captcha_form_tag_handler

The Contact Form 7 wpcf7 captcha form tag handler function.

Description

wpcf7_captcha_form_tag_handler( $tag ); 

Parameters (1)

0. $tag
The tag.

Usage

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

Defined (1)

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

/modules/really-simple-captcha.php  
  1. function wpcf7_captcha_form_tag_handler( $tag ) { 
  2. $tag = new WPCF7_FormTag( $tag ); 
  3.  
  4. if ( 'captchac' == $tag->type && ! class_exists( 'ReallySimpleCaptcha' ) ) { 
  5. return '<em>' . __( 'To use CAPTCHA, you need <a href="http://wordpress.org/extend/plugins/really-simple-captcha/">Really Simple CAPTCHA</a> plugin installed.', 'contact-form-7' ) . '</em>'; 
  6.  
  7. if ( empty( $tag->name ) ) { 
  8. return ''; 
  9.  
  10. $validation_error = wpcf7_get_validation_error( $tag->name ); 
  11.  
  12. $class = wpcf7_form_controls_class( $tag->type ); 
  13.  
  14. if ( 'captchac' == $tag->type ) { // CAPTCHA-Challenge (image) 
  15. $class .= ' wpcf7-captcha-' . $tag->name; 
  16.  
  17. $atts = array(); 
  18.  
  19. $atts['class'] = $tag->get_class_option( $class ); 
  20. $atts['id'] = $tag->get_id_option(); 
  21.  
  22. $op = array( // Default 
  23. 'img_size' => array( 72, 24 ),  
  24. 'base' => array( 6, 18 ),  
  25. 'font_size' => 14,  
  26. 'font_char_width' => 15 ); 
  27.  
  28. $op = array_merge( $op, wpcf7_captchac_options( $tag->options ) ); 
  29.  
  30. if ( ! $filename = wpcf7_generate_captcha( $op ) ) { 
  31. return ''; 
  32.  
  33. if ( ! empty( $op['img_size'] ) ) { 
  34. if ( isset( $op['img_size'][0] ) ) { 
  35. $atts['width'] = $op['img_size'][0]; 
  36.  
  37. if ( isset( $op['img_size'][1] ) ) { 
  38. $atts['height'] = $op['img_size'][1]; 
  39.  
  40. $atts['alt'] = 'captcha'; 
  41. $atts['src'] = wpcf7_captcha_url( $filename ); 
  42.  
  43. $atts = wpcf7_format_atts( $atts ); 
  44.  
  45. $prefix = substr( $filename, 0, strrpos( $filename, '.' ) ); 
  46.  
  47. $html = sprintf( 
  48. '<input type="hidden" name="_wpcf7_captcha_challenge_%1$s" value="%2$s" /><img %3$s />',  
  49. $tag->name, $prefix, $atts ); 
  50.  
  51. return $html; 
  52.  
  53. } elseif ( 'captchar' == $tag->type ) { // CAPTCHA-Response (input) 
  54. if ( $validation_error ) { 
  55. $class .= ' wpcf7-not-valid'; 
  56.  
  57. $atts = array(); 
  58.  
  59. $atts['size'] = $tag->get_size_option( '40' ); 
  60. $atts['maxlength'] = $tag->get_maxlength_option(); 
  61. $atts['minlength'] = $tag->get_minlength_option(); 
  62.  
  63. if ( $atts['maxlength'] && $atts['minlength'] 
  64. && $atts['maxlength'] < $atts['minlength'] ) { 
  65. unset( $atts['maxlength'], $atts['minlength'] ); 
  66.  
  67. $atts['class'] = $tag->get_class_option( $class ); 
  68. $atts['id'] = $tag->get_id_option(); 
  69. $atts['tabindex'] = $tag->get_option( 'tabindex', 'int', true ); 
  70. $atts['autocomplete'] = 'off'; 
  71. $atts['aria-invalid'] = $validation_error ? 'true' : 'false'; 
  72.  
  73. $value = (string) reset( $tag->values ); 
  74.  
  75. if ( wpcf7_is_posted() ) { 
  76. $value = ''; 
  77.  
  78. if ( $tag->has_option( 'placeholder' ) 
  79. || $tag->has_option( 'watermark' ) ) { 
  80. $atts['placeholder'] = $value; 
  81. $value = ''; 
  82.  
  83. $atts['value'] = $value; 
  84. $atts['type'] = 'text'; 
  85. $atts['name'] = $tag->name; 
  86.  
  87. $atts = wpcf7_format_atts( $atts ); 
  88.  
  89. $html = sprintf( 
  90. '<span class="wpcf7-form-control-wrap %1$s"><input %2$s />%3$s</span>',  
  91. sanitize_html_class( $tag->name ), $atts, $validation_error ); 
  92.  
  93. return $html;