diff --git a/captcha.admin.inc b/captcha.admin.inc index f27227a..2743dab 100644 --- a/captcha.admin.inc +++ b/captcha.admin.inc @@ -201,6 +201,14 @@ function captcha_admin_settings() { '#description' => t('Define if challenges should be omitted during the rest of a session once the user successfully responds to a challenge.'), ); + // Enable wrong response counter. + $form['captcha_enable_stats'] = array( + '#type' => 'checkbox', + '#title' => t('Enable statistics'), + '#description' => t('Keep a counter of all wrong CAPTCHA responses. There is a performance penalty in enabling this option as all incorrect CAPTCHAs will result in clearing the variable cache.'), + '#default_value' => variable_get('captcha_enable_stats', FALSE), + ); + // Option for logging wrong responses. $form['captcha_log_wrong_responses'] = array( '#type' => 'checkbox', @@ -309,6 +317,7 @@ function captcha_admin_settings_submit($form, &$form_state) { variable_set('captcha_default_validation', $form_state['values']['captcha_default_validation']); variable_set('captcha_persistence', $form_state['values']['captcha_persistence']); + variable_set('captcha_enable_stats', $form_state['values']['captcha_enable_stats']); variable_set('captcha_log_wrong_responses', $form_state['values']['captcha_log_wrong_responses']); drupal_set_message(t('The CAPTCHA settings have been saved.'), 'status'); diff --git a/captcha.install b/captcha.install index c10b25c..f53f600 100644 --- a/captcha.install +++ b/captcha.install @@ -114,7 +114,7 @@ function captcha_schema() { function captcha_requirements($phase) { $requirements = array(); $t = get_t(); - if ($phase == 'runtime') { + if ($phase == 'runtime' && variable_get('captcha_enable_stats', FALSE)) { // Show the wrong response counter in the status report. $requirements['captcha_wrong_response_counter'] = array( 'title' => $t('CAPTCHA'), diff --git a/captcha.module b/captcha.module index cc0432c..7d7c53c 100644 --- a/captcha.module +++ b/captcha.module @@ -616,7 +616,9 @@ function captcha_validate($element, &$form_state) { // set form error form_set_error('captcha_response', t('The answer you entered for the CAPTCHA was not correct.')); // update wrong response counter - variable_set('captcha_wrong_response_counter', variable_get('captcha_wrong_response_counter', 0) + 1); + if (variable_get('captcha_enable_stats', FALSE)) { + variable_set('captcha_wrong_response_counter', variable_get('captcha_wrong_response_counter', 0) + 1); + } // log to watchdog if needed if (variable_get('captcha_log_wrong_responses', FALSE)) { watchdog('CAPTCHA',