Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /*
- This snippet will allow Really Simple Captcha to work with the Events Manager event submission formss
- Instructions:
- 1. Download and Install -> http://wordpress.org/extend/plugins/really-simple-captcha/
- 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/
- */
- function em_validate_event_form($result){
- global $EM_Event,$EM_Notices;
- $captcha_instance = new ReallySimpleCaptcha();
- $captcha_instance_correct = false;
- $captcha_instance_prefix = $_REQUEST['captcha_instance_prefix'];
- $captcha_instance_code = $_REQUEST['captcha_instance_code'];
- $captcha_instance_check = $captcha_instance->check( $captcha_instance_prefix, $captcha_instance_code );
- $captcha_instance_correct = $captcha_instance_check;
- if ( !$captcha_instance_correct && !is_user_logged_in() ){
- $EM_Notices->add_error('Invalid security code');
- return false;
- }
- return $result;
- }
- add_filter('em_event_validate','em_validate_event_form');
- function my_em_event_form_captcha(){
- if ( !is_user_logged_in() ){
- $captcha_instance = new ReallySimpleCaptcha();
- $captcha_instance->chars = 'ABCDEFGHJKLMNPQRSTUVWXYZ23456789';
- $captcha_instance->char_length = '4';
- // Width/Height dimensions of CAPTCHA image.
- $captcha_instance->img_size = array( '72', '24' );
- // Font color of CAPTCHA characters, in RGB (0 - 255).
- $captcha_instance->fg = array( '0', '0', '0' );
- // Background color of CAPTCHA image, in RGB (0 - 255).
- $captcha_instance->bg = array( '255', '255', '255' );
- // Font Size of CAPTCHA characters.
- $captcha_instance->font_size = '16';
- // Width between CAPTCHA characters.
- $captcha_instance->font_char_width = '15';
- // CAPTCHA image type. Can be 'png', 'jpeg', or 'gif'
- $captcha_instance->img_type = 'png';
- $captcha_instance_word = $captcha_instance->generate_random_word();
- $captcha_instance_prefix = mt_rand();
- $captcha_instance_image_name = $captcha_instance->generate_image($captcha_instance_prefix, $captcha_instance_word);
- $captcha_instance_image_url = get_bloginfo('wpurl') . '/wp-content/plugins/really-simple-captcha/tmp/';
- $captcha_instance_image_src = $captcha_instance_image_url.$captcha_instance_image_name;
- $captcha_instance_image_width = $captcha_instance->img_size[0];
- $captcha_instance_image_height = $captcha_instance->img_size[1];
- $captcha_instance_field_size = $captcha_instance->char_length;
- $captcha_instance_form_label = 'Anti-Spam:';
- ?>
- <p class="comment-form-captcha">
- <img src="<?php echo $captcha_instance_image_src; ?>" alt="captcha" width="<?php echo $captcha_instance_image_width; ?>" height="<?php echo $captcha_instance_image_height; ?>" />
- <label for="captcha_code"><?php echo $captcha_instance_form_label; ?></label>
- <input id="captcha_instance_code" name="captcha_instance_code" size="<?php echo $captcha_instance_field_size; ?>" type="text" />
- <input id="captcha_instance_prefix" name="captcha_instance_prefix" type="hidden" value="<?php echo $captcha_instance_prefix; ?>" />
- </p>
- <?php
- }
- }
- add_action('em_front_event_form_footer','my_em_event_form_captcha');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement