Advertisement
eventsmanager

captcha for event submission form

Jul 23rd, 2013
1,320
1
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.30 KB | None | 1 0
  1. <?php
  2. /*
  3. This snippet will allow Really Simple Captcha to work with the Events Manager event submission formss
  4.  
  5. Instructions:
  6. 1. Download and Install -> http://wordpress.org/extend/plugins/really-simple-captcha/
  7. 2. Add this code to your site, such as pasting the contents of this into a new php file and place it in the wp-content/mu-plugins folder. See here for instructions - http://wp-events-plugin.com/tutorials/how-to-safely-add-php-code-to-wordpress/
  8. */
  9.  
  10. function em_validate_event_form($result){
  11.   global $EM_Event,$EM_Notices;
  12.   $captcha_instance = new ReallySimpleCaptcha();
  13.   $captcha_instance_correct = false;
  14.   $captcha_instance_prefix = $_REQUEST['captcha_instance_prefix'];
  15.   $captcha_instance_code = $_REQUEST['captcha_instance_code'];
  16.   $captcha_instance_check = $captcha_instance->check( $captcha_instance_prefix, $captcha_instance_code );
  17.   $captcha_instance_correct = $captcha_instance_check;
  18.   if ( !$captcha_instance_correct && !is_user_logged_in() ){
  19.     $EM_Notices->add_error('Invalid security code');
  20.     return false;
  21.   }
  22.   return $result;
  23. }
  24. add_filter('em_event_validate','em_validate_event_form');
  25.  
  26. function my_em_event_form_captcha(){
  27.   if ( !is_user_logged_in() ){
  28.     $captcha_instance = new ReallySimpleCaptcha();
  29.     $captcha_instance->chars = 'ABCDEFGHJKLMNPQRSTUVWXYZ23456789';
  30.     $captcha_instance->char_length = '4';
  31.     // Width/Height dimensions of CAPTCHA image.
  32.     $captcha_instance->img_size = array( '72', '24' );
  33.     // Font color of CAPTCHA characters, in RGB (0 - 255).
  34.     $captcha_instance->fg = array( '0', '0', '0' );
  35.     // Background color of CAPTCHA image, in RGB (0 - 255).
  36.     $captcha_instance->bg = array( '255', '255', '255' );
  37.     // Font Size of CAPTCHA characters.
  38.     $captcha_instance->font_size = '16';
  39.     // Width between CAPTCHA characters.
  40.     $captcha_instance->font_char_width = '15';
  41.     // CAPTCHA image type. Can be 'png', 'jpeg', or 'gif'
  42.     $captcha_instance->img_type = 'png';
  43.     $captcha_instance_word = $captcha_instance->generate_random_word();
  44.     $captcha_instance_prefix = mt_rand();
  45.     $captcha_instance_image_name = $captcha_instance->generate_image($captcha_instance_prefix, $captcha_instance_word);
  46.     $captcha_instance_image_url =  get_bloginfo('wpurl') . '/wp-content/plugins/really-simple-captcha/tmp/';
  47.     $captcha_instance_image_src = $captcha_instance_image_url.$captcha_instance_image_name;
  48.     $captcha_instance_image_width = $captcha_instance->img_size[0];
  49.     $captcha_instance_image_height = $captcha_instance->img_size[1];
  50.     $captcha_instance_field_size = $captcha_instance->char_length;
  51.     $captcha_instance_form_label = 'Anti-Spam:';
  52.     ?>
  53.     <p class="comment-form-captcha">
  54.       <img src="<?php echo $captcha_instance_image_src; ?>" alt="captcha" width="<?php echo $captcha_instance_image_width; ?>" height="<?php echo $captcha_instance_image_height; ?>" />
  55.       <label for="captcha_code"><?php echo $captcha_instance_form_label; ?></label>
  56.       <input id="captcha_instance_code" name="captcha_instance_code" size="<?php echo $captcha_instance_field_size; ?>" type="text" />
  57.       <input id="captcha_instance_prefix" name="captcha_instance_prefix" type="hidden" value="<?php echo $captcha_instance_prefix; ?>" />
  58.     </p>
  59.     <?php
  60.   }
  61. }
  62. add_action('em_front_event_form_footer','my_em_event_form_captcha');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement