'; } function registration_css() { global $recaptcha_opt; if ($recaptcha_opt['re_registration']) { $width = 0; if ($recaptcha_opt['re_theme_reg'] == 'red' || $recaptcha_opt['re_theme_reg'] == 'white' || $recaptcha_opt['re_theme_reg'] == 'blackglass') $width = 358; else if ($recaptcha_opt['re_theme_reg'] == 'clean') $width = 485; echo << #login { width: {$width}px !important; } #login a { text-align: center; } #nav { text-align: center; } form .submit { margin-top: 10px; } REGISTRATION; } } add_action('wp_head', 're_css'); // include the stylesheet in typical pages to style hidden emails add_action('admin_head', 're_css'); // include stylesheet to style options page add_action('login_head', 're_css'); // include stylesheet to style reCAPTCHA on registration page add_action('login_head', 'registration_css'); // include the login div styling, embedded /* ============================================================================= End CSS ============================================================================= */ // If the plugin is deactivated, delete the preferences function delete_preferences() { global $wpmu; if ($wpmu != 1) delete_option('recaptcha'); } register_deactivation_hook(__FILE__, 'delete_preferences'); /* ============================================================================= reCAPTCHA on Registration Form - Thanks to Ben C.'s recapture plugin ============================================================================= */ // Display the reCAPTCHA on the registration form function display_recaptcha($errors) { global $recaptcha_opt, $wpmu; if ($recaptcha_opt['re_registration']) { $format = << var RecaptchaOptions = { theme : '{$recaptcha_opt['re_theme_reg']}', lang : '{$recaptcha_opt['re_lang']}' , tabindex : 30 }; END; $comment_string = << document.getElementById('recaptcha_table').style.direction = 'ltr'; COMMENT_FORM; if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == "on") $use_ssl = true; else $use_ssl = false; if ($wpmu == 1) { $error = $errors->get_error_message('captcha'); ?> '.$error.'

' : '') ?> '; echo $format . recaptcha_wp_get_html($_GET['rerror'], $use_ssl); } } } // Hook the display_recaptcha function into WordPress if ($wpmu != 1) add_action('register_form', 'display_recaptcha'); else add_action('signup_extra_fields', 'display_recaptcha'); // Check the captcha function check_recaptcha() { global $recaptcha_opt, $errors; if (empty($_POST['recaptcha_response_field'])) $errors['blank_captcha'] = $recaptcha_opt['error_blank']; else { $response = recaptcha_check_answer($recaptcha_opt['privkey'], $_SERVER['REMOTE_ADDR'], $_POST['recaptcha_challenge_field'], $_POST['recaptcha_response_field']); if (!$response->is_valid) if ($response->error == 'incorrect-captcha-sol') $errors['captcha_wrong'] = $recaptcha_opt['error_incorrect']; } } // Check the captcha function check_recaptcha_new($errors) { global $recaptcha_opt; if (empty($_POST['recaptcha_response_field']) || $_POST['recaptcha_response_field'] == '') { $errors->add('blank_captcha', $recaptcha_opt['error_blank']); return $errors; } $response = recaptcha_check_answer($recaptcha_opt['privkey'], $_SERVER['REMOTE_ADDR'], $_POST['recaptcha_challenge_field'], $_POST['recaptcha_response_field'] ); if (!$response->is_valid) if ($response->error == 'incorrect-captcha-sol') $errors->add('captcha_wrong', $recaptcha_opt['error_incorrect']); return $errors; } // Check the recaptcha on WordPress MU function check_recaptcha_wpmu($result) { global $_POST, $recaptcha_opt; // It's blogname in 2.6, blog_id prior to that if (isset($_POST['blog_id']) || isset($_POST['blogname'])) return $result; // no text entered if (empty($_POST['recaptcha_response_field']) || $_POST['recaptcha_response_field'] == '') { $result['errors']->add('blank_captcha', $recaptcha_opt['error_blank']); return $result; } $response = recaptcha_check_answer($recaptcha_opt['privkey'], $_SERVER['REMOTE_ADDR'], $_POST['recaptcha_challenge_field'], $_POST['recaptcha_response_field'] ); // incorrect CAPTCHA if (!$response->is_valid) if ($response->error == 'incorrect-captcha-sol') { $result['errors']->add('captcha_wrong', $recaptcha_opt['error_incorrect']); echo "
". $recaptcha_opt['error_incorrect'] . "
"; } return $result; } if ($recaptcha_opt['re_registration']) { if ($wpmu == 1) add_filter('wpmu_validate_user_signup', 'check_recaptcha_wpmu'); else if ($wpmu == 0) { // Hook the check_recaptcha function into WordPress if (version_compare(get_bloginfo('version'), '2.5' ) >= 0) add_filter('registration_errors', 'check_recaptcha_new'); else add_filter('registration_errors', 'check_recaptcha'); } } /* ============================================================================= End reCAPTCHA on Registration Form ============================================================================= */ /* ============================================================================= reCAPTCHA Plugin Default Options ============================================================================= */ $option_defaults = array ( 'pubkey' => '', // the public key for reCAPTCHA 'privkey' => '', // the private key for reCAPTCHA 'use_mailhide' => '0', // whether or not to use mailhide 're_bypass' => '', // whether to sometimes skip reCAPTCHAs for registered users 're_bypasslevel' => '', // who doesn't have to do the reCAPTCHA (should be a valid WordPress capability slug) 'mh_bypass' => '', // whether to sometimes skip the MailHide filter for registered users 'mh_bypasslevel' => '', // who can see full emails normally (should be a valid WordPress capability slug) 'mailhide_pub' => '', // mailhide public key 'mailhide_priv' => '', // mailhide private key 're_theme' => 'red', // the default theme for reCAPTCHA on the comment post 're_theme_reg' => 'red', // the default theme for reCAPTCHA on the registration form 're_lang' => 'en', // the default language for reCAPTCHA 're_tabindex' => '5', // the default tabindex for reCAPTCHA 're_comments' => '1', // whether or not to show reCAPTCHA on the comment post 're_registration' => '1', // whether or not to show reCAPTCHA on the registratoin page 're_xhtml' => '0', // whether or not to be XHTML 1.0 Strict compliant 'mh_replace_link' => '', // name the link something else 'mh_replace_title' => '', // title of the link 'error_blank' => 'ERROR: Please fill in the reCAPTCHA form.', // the message to display when the user enters no CAPTCHA response 'error_incorrect' => 'ERROR: That reCAPTCHA response was incorrect.', // the message to display when the user enters the incorrect CAPTCHA response ); // install the defaults if ($wpmu != 1) add_option('recaptcha', $option_defaults, 'reCAPTCHA Default Options', 'yes'); /* ============================================================================= End reCAPTCHA Plugin Default Options ============================================================================= */ /* ============================================================================= MailHide - This scans for addresses and hides them using the MailHide API ============================================================================= */ // The main mailhide filter function mh_insert_email($content = '') { global $recaptcha_opt; // set the minimum capability needed to skip the MailHide if there is one if ($recaptcha_opt['mh_bypass'] AND $recaptcha_opt['mh_bypasslevel']) $needed_capability = $recaptcha_opt['mh_bypasslevel']; // skip the MailHide display if the minimum capability is met if (($needed_capability && current_user_can($needed_capability)) || !$recaptcha_opt['re_comments']) { // remove the nohides $content = preg_replace('/\[\/?nohide\]/i','',$content); return $content; } // Regular Expressions thanks to diabolic from EFNet #regex // match hyperlinks with emails $regex = '%(?]*href="(?:mailto:)?([^@"]+@[^@"]+)"[^>]*>(.+?)<\\/a>(?!\\[/nohide\\])%i'; $content = preg_replace_callback($regex, "mh_replace_hyperlink", $content); // match emails $regex = '%\\b([\\w.+-]+@[a-z\\d.-]+\\.[a-z]{2,6})\\b(?!\\s*\\[\\/nohide\\]|(?:(?!]*>).)*<\\/a>)%iU'; $content = preg_replace_callback($regex, "mh_replace", $content); // remove the nohides $content = preg_replace('/\[\/?nohide\]/i','',$content); return $content; } // replace the hyperlinked emails i.e. this or that function mh_replace_hyperlink($matches) { global $recaptcha_opt; // set the minimum capability needed to skip the MailHide if there is one if ($recaptcha_opt['mh_bypass'] AND $recaptcha_opt['mh_bypasslevel']) $needed_capability = $recaptcha_opt['mh_bypasslevel']; // skip the MailHide display if the minimum capability is met if (($needed_capability && current_user_can($needed_capability)) || !$recaptcha_opt['re_comments']) { // remove the nohides $content = preg_replace('/\[\/?nohide\]/i','',$content); return $content; } // get the url, the part inside the href. this is the email of course $url = recaptcha_mailhide_url($recaptcha_opt['mailhide_pub'], $recaptcha_opt['mailhide_priv'], $matches[1]); // construct a new hyperlink with the url hidden but the link text the same $html = "" . $matches[2] . ""; // style it $html = '' . $html . ""; return $html; } // replace the plain text emails i.e. haha@lol.com function mh_replace($matches) { global $recaptcha_opt; if ($recaptcha_opt['mh_replace_link'] == "" && $recaptcha_opt['mh_replace_title'] == "") { // fine plain text emails and hide them $html = recaptcha_mailhide_html($recaptcha_opt['mailhide_pub'], $recaptcha_opt['mailhide_priv'], $matches[1]); } else { // replace both things if ($recaptcha_opt['mh_replace_link'] != "" && $recaptcha_opt['mh_replace_title'] != "") { $url = recaptcha_mailhide_url($recaptcha_opt['mailhide_pub'], $recaptcha_opt['mailhide_priv'], $matches[1]); $html = "" . $recaptcha_opt['mh_replace_link'] . ""; } // only replace the link else if ($recaptcha_opt['mh_replace_link'] != "" && $recaptcha_opt['mh_replace_title'] == "") { $url = recaptcha_mailhide_url($recaptcha_opt['mailhide_pub'], $recaptcha_opt['mailhide_priv'], $matches[1]); $html = "" . $recaptcha_opt['mh_replace_link'] . ""; } // only replace the title else if ($recaptcha_opt['mh_replace_link'] == "" && $recaptcha_opt['mh_replace_title'] != "") { $url = recaptcha_mailhide_url($recaptcha_opt['mailhide_pub'], $recaptcha_opt['mailhide_priv'], $matches[1]); $emailparts = _recaptcha_mailhide_email_parts ($matches[1]); $html = htmlentities($emailparts[0], ENT_QUOTES) . "...@" . htmlentities($emailparts[1], ENT_QUOTES); } } // style it $html = '' . $html . ""; return $html; } // add the filters only if mcrypt is loaded if ($recaptcha_opt['use_mailhide'] && extension_loaded('mcrypt')) { add_filter('the_content', 'mh_insert_email'); // For posts/pages add_filter('get_comment_text', 'mh_insert_email'); // For comments add_filter('the_content_rss', 'mh_insert_email'); // For RSS add_filter('comment_text_rss', 'mh_insert_email'); // For RSS Comments } /* ============================================================================= End MailHide ============================================================================= */ /* ============================================================================= reCAPTCHA - The reCAPTCHA comment spam protection section ============================================================================= */ function recaptcha_wp_hash_comment($id) { global $recaptcha_opt; if (function_exists('wp_hash')) return wp_hash(RECAPTCHA_WP_HASH_COMMENT . $id); else return md5(RECAPTCHA_WP_HASH_COMMENT . $recaptcha_opt['privkey'] . $id); } function recaptcha_wp_get_html ($recaptcha_error, $use_ssl=false) { global $recaptcha_opt; return recaptcha_get_html($recaptcha_opt['pubkey'], $recaptcha_error, $use_ssl, $recaptcha_opt['re_xhtml']); } /** * Embeds the reCAPTCHA widget into the comment form. * */ function recaptcha_comment_form() { global $user_ID, $recaptcha_opt; // set the minimum capability needed to skip the captcha if there is one if ($recaptcha_opt['re_bypass'] AND $recaptcha_opt['re_bypasslevel']) $needed_capability = $recaptcha_opt['re_bypasslevel']; // skip the reCAPTCHA display if the minimum capability is met if (($needed_capability && current_user_can($needed_capability)) || !$recaptcha_opt['re_comments']) return; else { // Did the user fail to match the CAPTCHA? If so, let them know if ($_GET['rerror'] == 'incorrect-captcha-sol') echo "

" . $recaptcha_opt['error_incorrect'] . "

"; //modify the comment form for the reCAPTCHA widget $recaptcha_js_opts = << var RecaptchaOptions = { theme : '{$recaptcha_opt['re_theme']}', lang : '{$recaptcha_opt['re_lang']}' , tabindex : {$recaptcha_opt['re_tabindex']} }; OPTS; if ($recaptcha_opt['re_xhtml']) { $comment_string = << COMMENT_FORM; } else { $comment_string = << COMMENT_FORM; } if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == "on") $use_ssl = true; else $use_ssl = false; echo $recaptcha_js_opts . recaptcha_wp_get_html($_GET['rerror'], $use_ssl) . $comment_string; } } add_action('comment_form', 'recaptcha_comment_form'); function recaptcha_wp_show_captcha_for_comment() { global $user_ID; return true; } $recaptcha_saved_error = ''; /** * Checks if the reCAPTCHA guess was correct and sets an error session variable if not * @param array $comment_data * @return array $comment_data */ function recaptcha_wp_check_comment($comment_data) { global $user_ID, $recaptcha_opt; global $recaptcha_saved_error; // set the minimum capability needed to skip the captcha if there is one if ($recaptcha_opt['re_bypass'] AND $recaptcha_opt['re_bypasslevel']) $needed_capability = $recaptcha_opt['re_bypasslevel']; // skip the filtering if the minimum capability is met if (($needed_capability && current_user_can($needed_capability)) || !$recaptcha_opt['re_comments']) return $comment_data; if (recaptcha_wp_show_captcha_for_comment()) { if ( $comment_data['comment_type'] == '' ) { // Do not check trackbacks/pingbacks $challenge = $_POST['recaptcha_challenge_field']; $response = $_POST['recaptcha_response_field']; $recaptcha_response = recaptcha_check_answer ($recaptcha_opt ['privkey'], $_SERVER['REMOTE_ADDR'], $challenge, $response); if ($recaptcha_response->is_valid) return $comment_data; else { $recaptcha_saved_error = $recaptcha_response->error; add_filter('pre_comment_approved', create_function('$a', 'return \'spam\';')); return $comment_data; } } } return $comment_data; } /* * If the reCAPTCHA guess was incorrect from recaptcha_wp_check_comment, then redirect back to the comment form * @param string $location * @param OBJECT $comment * @return string $location */ function recaptcha_wp_relative_redirect($location, $comment) { global $recaptcha_saved_error; if($recaptcha_saved_error != '') { //replace the '#comment-' chars on the end of $location with '#commentform'. $location = substr($location, 0,strrpos($location, '#')) . ((strrpos($location, "?") === false) ? "?" : "&") . 'rcommentid=' . $comment->comment_ID . '&rerror=' . $recaptcha_saved_error . '&rchash=' . recaptcha_wp_hash_comment ($comment->comment_ID) . '#commentform'; } return $location; } /* * If the reCAPTCHA guess was incorrect from recaptcha_wp_check_comment, then insert their saved comment text * back in the comment form. * @param boolean $approved * @return boolean $approved */ function recaptcha_wp_saved_comment() { if (!is_single() && !is_page()) return; if ($_GET['rcommentid'] && $_GET['rchash'] == recaptcha_wp_hash_comment ($_GET['rcommentid'])) { $comment = get_comment($_GET['rcommentid']); $com = preg_replace('/([\\/\(\)\+\;\'\"])/e','\'%\'.dechex(ord(\'$1\'))', $comment->comment_content); $com = preg_replace('/\\r\\n/m', '\\\n', $com); echo " var _recaptcha_wordpress_savedcomment = '" . $com ."'; _recaptcha_wordpress_savedcomment = unescape(_recaptcha_wordpress_savedcomment); "; wp_delete_comment($comment->comment_ID); } } function recaptcha_wp_blog_domain () { $uri = parse_url(get_settings('siteurl')); return $uri['host']; } add_filter('wp_head', 'recaptcha_wp_saved_comment',0); add_filter('preprocess_comment', 'recaptcha_wp_check_comment',0); add_filter('comment_post_redirect', 'recaptcha_wp_relative_redirect',0,2); function recaptcha_wp_add_options_to_admin() { global $wpmu; if ($wpmu == 1 && is_site_admin()) { add_submenu_page('wpmu-admin.php', 'reCAPTCHA', 'reCAPTCHA', 'manage_options', __FILE__, 'recaptcha_wp_options_subpanel'); add_options_page('reCAPTCHA', 'reCAPTCHA', 'manage_options', __FILE__, 'recaptcha_wp_options_subpanel'); } else if ($wpmu != 1) { add_options_page('reCAPTCHA', 'reCAPTCHA', 'manage_options', __FILE__, 'recaptcha_wp_options_subpanel'); } } function recaptcha_wp_options_subpanel() { global $wpmu; // Default values for the options array $optionarray_def = array( 'pubkey' => '', 'privkey' => '', 'use_mailhide' => '', 're_bypasslevel' => '3', 'mh_bypasslevel' => '3', 'mailhide_pub' => '', 'mailhide_priv' => '', 're_theme' => 'red', 're_theme_reg' => 'red', 're_lang' => 'en', 're_tabindex' => '5', 're_comments' => '1', 're_registration' => '1', 're_xhtml' => '0', 'mh_replace_link' => '', 'mh_replace_title' => '', 'error_blank' => 'ERROR: Please fill in the reCAPTCHA form.', 'error_incorrect' => 'ERROR: That reCAPTCHA response was incorrect.', ); if ($wpmu != 1) add_option('recaptcha', $optionarray_def, 'reCAPTCHA Options'); /* Check form submission and update options if no error occurred */ if (isset($_POST['submit'])) { $optionarray_update = array ( 'pubkey' => $_POST['recaptcha_opt_pubkey'], 'privkey' => $_POST['recaptcha_opt_privkey'], 'use_mailhide' => $_POST['use_mailhide'], 're_bypass' => $_POST['re_bypass'], 're_bypasslevel' => $_POST['re_bypasslevel'], 'mailhide_pub' => $_POST['mailhide_pub'], 'mailhide_priv' => $_POST['mailhide_priv'], 'mh_bypass' => $_POST['mh_bypass'], 'mh_bypasslevel' => $_POST['mh_bypasslevel'], 're_theme' => $_POST['re_theme'], 're_theme_reg' => $_POST['re_theme_reg'], 're_lang' => $_POST['re_lang'], 're_tabindex' => $_POST['re_tabindex'], 're_comments' => $_POST['re_comments'], 're_registration' => $_POST['re_registration'], 're_xhtml' => $_POST['re_xhtml'], 'mh_replace_link' => $_POST['mh_replace_link'], 'mh_replace_title' => $_POST['mh_replace_title'], 'error_blank' => $_POST['error_blank'], 'error_incorrect' => $_POST['error_incorrect'], ); // save updated options if ($wpmu == 1) update_site_option('recaptcha', $optionarray_update); else update_option('recaptcha', $optionarray_update); } /* Get options */ if ($wpmu == 1) $optionarray_def = get_site_option('recaptcha'); else $optionarray_def = get_option('recaptcha'); /* ============================================================================= reCAPTCHA Admin Page and Functions ============================================================================= */ /* * Display an HTML id and name * @param string $checked_value selected value for dropdown, slug form. * @return NULL */ function recaptcha_dropdown_capabilities($select_name, $checked_value="") { // define choices: Display text => permission slug $capability_choices = array ( 'All registered users' => 'read', 'Edit posts' => 'edit_posts', 'Publish Posts' => 'publish_posts', 'Moderate Comments' => 'moderate_comments', 'Administer site' => 'level_10' ); // print the ' . "\n"; foreach ($capability_choices as $text => $capability) : if ($capability == $checked_value) $checked = ' selected="selected" '; echo '\t \n"; $checked = NULL; endforeach; echo " \n"; } // end recaptcha_dropdown_capabilities() ?>

reCAPTCHA Options

About reCAPTCHA

reCAPTCHA is a free, accessible CAPTCHA service that helps to digitize books while blocking spam on your blog.

reCAPTCHA asks commenters to retype two words scanned from a book to prove that they are a human. This verifies that they are not a spambot while also correcting the automatic scans of old books. So you get less spam, and the world gets accurately digitized books. Everybody wins! For details, visit the reCAPTCHA website.

NOTE: If you are using some form of Cache plugin you will probably need to flush/clear your cache for changes to take effect.

reCAPTCHA Keys reCAPTCHA requires an API key, consisting of a "public" and a "private" key. You can sign up for a free reCAPTCHA key.


Comment Options />
/> of capabilities ?>

Registration Options />
Error Messages

The following are the messages to display when the user does not enter a CAPTCHA response or enters the incorrect CAPTCHA response.


General Settings
/>

About MailHide

MailHide uses reCAPTCHA to protect email adresses displayed on your blog from being harvested for spam.

Activating MailHide will automatically hide all emails in posts and comments from spam bots. For example, support@recaptcha.net would become supp...@recaptcha.net. There are also options below for choosing the text to show for hidden emails.

MailHide also requires a public and private key which you can generate using the key generation service.

MailHide Keys />


Visibility Options
/> of capabilities ?>

The following allows you to show the replaced links differently. Usually, you get something like this, supp...@recaptcha.net , where the email is broken up into two pieces and then a link with dots is placed in the middle. The Email Replacement Text value lets you choose what to name the link and then the Reveal Link Title value determines the text that is shown when the link is hovered over.

For example, if the Email Replacement Text option is set to HIDDEN EMAIL and the Reveal Link Title option is set to Click here to reveal this address, then ALL emails will be hidden like this: HIDDEN EMAIL

If you want to maintain the default method of hiding emails then leave both boxes blank.


Other Information

CSS: You can style the hidden emails and much more in the recaptcha.css stylesheet in wp-recaptcha's plugin folder.

You can bypass email hiding for an address by enclosing it within [nohide][/nohide], ex. [nohide]some@email.com[/nohide].

reCAPTCHA is not active You must enter your reCAPTCHA API key for it to work

"; } if (($wpmu == 1 && is_site_admin()) || $wpmu != 1) add_action('admin_footer', 'recaptcha_warning'); return; } // If the mcrypt PHP module isn't loaded then display an alert if (($recaptcha_opt['use_mailhide'] && !extension_loaded('mcrypt')) && !isset($_POST['submit'])) { function mcrypt_warning() { global $wpmu; $path = plugin_basename(__FILE__); $top = 0; if ($wp_version <= 2.5) $top = 12.7; else $top = 7; echo "

MailHide is not active You must have the mcrypt module loaded for it to work

"; } if (($wpmu == 1 && is_site_admin()) || $wpmu != 1) add_action('admin_footer', 'mcrypt_warning'); return; } // If MailHide is enabled but no keys have been entered if ($recaptcha_opt['use_mailhide'] && !($recaptcha_opt['mailhide_pub'] && $recaptcha_opt['mailhide_pub']) && !isset($_POST['submit'])) { function mailhide_warning() { global $wpmu; $path = plugin_basename(__FILE__); $top = 0; if ($wp_version <= 2.5) $top = 12.7; else $top = 7; echo "

MailHide is not active You must enter your MailHide API keys for it to work

"; } if (($wpmu == 1 && is_site_admin()) || $wpmu != 1) add_action('admin_footer', 'mailhide_warning'); return; } /* ============================================================================= End Apply the admin menu ============================================================================= */ ?>