protected function init_hooks() { // load custom template function at this stage to make it pluggable $this->_load_template_functions(); if (defined('WPCF7_VERSION')) { // add support for Contact Form 7 (CF7) automatically if CF7 is // installed and activated include_once dirname(__FILE__) . '/class-bwp-recaptcha-cf7.php'; BWP_RECAPTCHA_CF7::init($this); } if (!empty($this->options['input_pubkey']) && !empty($this->options['input_prikey'])) { // this action needs to be added when a captcha is manually needed add_action('bwp_recaptcha_add_markups', array($this, 'add_recaptcha')); if ('yes' == $this->options['enable_comment']) { // add captcha to comment form if (!$this->_is_captcha_required()) { // if user chooses to integrate with akismet, only show // recaptcha when comment is marked as spam add_action('akismet_spam_caught', array($this, 'add_recaptcha_after_akismet')); } else { if (!$this->user_can_bypass()) { if ($this->options['select_position'] == 'after_fields') { // show captcha after website field add_action('comment_form_after_fields', array($this, 'add_recaptcha')); add_action('comment_form_logged_in_after', array($this, 'add_recaptcha')); } elseif ($this->options['select_position'] == 'after_comment_field') { // show captcha after comment field (default @since 1.1.1) add_filter('comment_form_defaults', array($this, 'add_recaptcha_after_comment_field')); } // fill the comment textarea add_filter('comment_form_field_comment', array($this, 'fill_comment_content')); // check entered captcha for comment form add_action('pre_comment_on_post', array($this, 'check_recaptcha')); } } } if ('yes' == $this->options['enable_registration'] && $this->is_reg) { // normal user registration page add_action('register_form', array($this, 'add_recaptcha')); add_filter('registration_errors', array($this, 'check_reg_recaptcha')); } if ('yes' == $this->options['enable_registration'] && $this->is_signup) { // wpms user/site registration page add_action('signup_extra_fields', array($this, 'add_recaptcha')); add_action('signup_blogform', array($this, 'add_blog_reg_recaptcha')); add_filter('wpmu_validate_user_signup', array($this, 'check_user_reg_recaptcha')); add_filter('wpmu_validate_blog_signup', array($this, 'check_blog_reg_recaptcha')); } if ('yes' == $this->options['enable_login'] && $this->is_login) { // @since 1.1.0 add captcha to login form add_action('login_form', array($this, 'add_recaptcha')); // the priority of 15 is to ensure that we run the filter before // WordPress authenticates the user. add_filter('authenticate', array($this, 'authenticate_with_recaptcha'), 15); } } }
function add_hooks() { if ((!defined('AKISMET_VERSION') || $this->options['enable_akismet'] != 'yes') && isset($_SESSION['bwp_capt_akismet_needed'])) { unset($_SESSION['bwp_capt_akismet_needed']); } // add support for Contact Form 7 (CF7) automatically if (defined('WPCF7_VERSION')) { include_once dirname(__FILE__) . '/class-bwp-recaptcha-cf7.php'; BWP_RECAPTCHA_CF7::init($this); } // init public and private keys based on multi-site setting, @since 1.1.0 $this->init_captcha_keys(); if (!empty($this->options['input_pubkey']) && !empty($this->options['input_prikey'])) { if ('yes' == $this->options['enable_comment']) { // if user chooses to integrate with akismet, only show recaptcha when comment is marked as spam if (defined('AKISMET_VERSION') && 'yes' == $this->options['enable_akismet'] && (empty($_SESSION['bwp_capt_akismet_needed']) || 'yes' != $_SESSION['bwp_capt_akismet_needed'])) { add_action('akismet_spam_caught', array($this, 'add_recaptcha_after_akismet')); } else { if (!$this->user_can_bypass()) { // this action needs to be added manually into your theme file, i.e. comments.php add_action('bwp_recaptcha_add_markups', array($this, 'add_recaptcha')); // action for themes using the comment_form() functions added in WordPress 3.0 add_action('comment_form_after_fields', array($this, 'add_recaptcha')); add_action('comment_form_logged_in_after', array($this, 'add_recaptcha')); // fill the comment textarea add_action('comment_form', array($this, 'fill_comment_content')); // check the captcha add_action('pre_comment_on_post', array($this, 'check_recaptcha')); } } } if ('yes' == $this->options['enable_registration'] && $this->is_reg) { // normal user registration page add_action('register_form', array($this, 'add_recaptcha')); add_action('login_head', array($this, 'enqueue_media')); add_filter('registration_errors', array($this, 'check_reg_recaptcha')); // wpms user/site registration page add_action('signup_extra_fields', array($this, 'add_recaptcha')); add_action('signup_blogform', array($this, 'add_blog_reg_recaptcha')); add_filter('wpmu_validate_user_signup', array($this, 'check_user_reg_recaptcha')); add_filter('wpmu_validate_blog_signup', array($this, 'check_blog_reg_recaptcha')); } // add captcha to login form @since 1.1.0 if ('yes' == $this->options['enable_login'] && $this->is_login) { add_action('login_form', array($this, 'add_recaptcha')); add_action('login_head', array($this, 'enqueue_media')); // the 40 priority is to ensure that we run the filter after // WordPress authenticates the user. add_filter('authenticate', array($this, 'authenticate_with_recaptcha'), 40); } } }