wpcf7_generate_captcha

The Contact Form 7 wpcf7 generate captcha function.

Description

wpcf7_generate_captcha( (null) $options = null ); 

Parameters (1)

0. $options — Optional. (null) => null
The options.

Usage

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

Defined (1)

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

/modules/really-simple-captcha.php  
  1. function wpcf7_generate_captcha( $options = null ) { 
  2. if ( ! $captcha = wpcf7_init_captcha() ) { 
  3. return false; 
  4.  
  5. if ( ! is_dir( $captcha->tmp_dir ) || ! wp_is_writable( $captcha->tmp_dir ) ) 
  6. return false; 
  7.  
  8. $img_type = imagetypes(); 
  9. if ( $img_type & IMG_PNG ) 
  10. $captcha->img_type = 'png'; 
  11. elseif ( $img_type & IMG_GIF ) 
  12. $captcha->img_type = 'gif'; 
  13. elseif ( $img_type & IMG_JPG ) 
  14. $captcha->img_type = 'jpeg'; 
  15. else 
  16. return false; 
  17.  
  18. if ( is_array( $options ) ) { 
  19. if ( isset( $options['img_size'] ) ) 
  20. $captcha->img_size = $options['img_size']; 
  21. if ( isset( $options['base'] ) ) 
  22. $captcha->base = $options['base']; 
  23. if ( isset( $options['font_size'] ) ) 
  24. $captcha->font_size = $options['font_size']; 
  25. if ( isset( $options['font_char_width'] ) ) 
  26. $captcha->font_char_width = $options['font_char_width']; 
  27. if ( isset( $options['fg'] ) ) 
  28. $captcha->fg = $options['fg']; 
  29. if ( isset( $options['bg'] ) ) 
  30. $captcha->bg = $options['bg']; 
  31.  
  32. $prefix = wp_rand(); 
  33. $captcha_word = $captcha->generate_random_word(); 
  34. return $captcha->generate_image( $prefix, $captcha_word );