WordPress.org

Ready to get started?Download WordPress

Forums

SI CAPTCHA Anti-Spam
Inserting SI CAPTCHA into login forms created by wp_login_form() (5 posts)

  1. iisisrael
    Member
    Posted 2 months ago #

    SI CAPTCHA can be inserted into login forms created by wp_login_form() by adding a filter and returning the captcha html as a string instead of echoing it. The patch below:

    • adds a function si_captcha_inline_login_form that returns the captcha html string,
    • modifies si_captcha_captcha_html to allow string return as an option instead of echoing, and
    • adds the si_captcha_inline_login_form function as a filter that gets applied by wp_login_form()
    --- a/wp-content/plugins/si-captcha-for-wordpress/si-captcha.php	Tue Feb 04 11:24:22 2014 -0600
    +++ b/wp-content/plugins/si-captcha-for-wordpress/si-captcha.php	Tue Feb 04 15:40:24 2014 -0600
    @@ -449,6 +449,41 @@
     } //  end function si_captcha_bp_login_sidebar_form
    
    +// this function adds the captcha to the login form any time wp_login_form is called
    +function si_captcha_inline_login_form() {
    +   global $si_captcha_url, $si_captcha_opt;
    +
    +   if ($si_captcha_opt['si_captcha_login'] != 'true') {
    +        return true; // captcha setting is disabled for login
    +   }
    +
    +// Test for some required things, print error message right here if not OK.
    +if ($this->si_captcha_check_requires()) {
    +
    +  $si_aria_required = ($si_captcha_opt['si_captcha_aria_required'] == 'true') ? ' aria-required="true" ' : '';
    +
    +// the captcha html - buddypress sidebar login form
    +$si_html = '
    +<div class="captchaSizeDivSmall">
    +';
    +  $si_html .= $this->si_captcha_captcha_html('si_image_side_login','log', true);
    +$si_html .= '
    +</div>
    +
    +    <label for="captcha_code_side_login">';
    +  $si_html .= ($si_captcha_opt['si_captcha_label_captcha'] != '') ? $si_captcha_opt['si_captcha_label_captcha'] : __('CAPTCHA Code', 'si-captcha');
    +  $si_html .= '</label>
    +<input style="width=145px;" id="captcha_code_side_login" name="captcha_code" class="input" type="text" value="" '.$si_aria_required.' />
    +<br />
    +<br />
    +';
    +}
    +
    +  return $si_html;
    +
    +} //  end function si_captcha_inline_login_form
    +
    +
     // this function adds the captcha to the register form
     function si_captcha_register_form() {
        global $si_captcha_url, $si_captcha_opt;
    @@ -804,7 +839,7 @@
     } // end function si_captcha_validate_code
    
     // displays the CAPTCHA in the forms
    -function si_captcha_captcha_html($label = 'si_image', $form_id = 'com') {
    +function si_captcha_captcha_html($label = 'si_image', $form_id = 'com', $no_echo = false) {
       global $si_captcha_url, $si_captcha_dir, $si_captcha_url_ns, $si_captcha_dir_ns, $si_captcha_opt;
    
       $capt_disable_sess = 0;
    @@ -839,9 +874,11 @@
         $securimage_show_url .= '&prefix='.$prefix;
       }
    
    +  $si_html = '';
    +
        if($si_captcha_opt['si_captcha_honeypot_enable'] == 'true' ) {
           // hidden empty honeypot field
    -      echo '
    +      $si_html .= '
             <div style="display:none;">
               <label for="email_'.$form_id.'"><small>'.__('Leave this field empty', 'si-captcha').'</small></label>
               <input type="text" name="email_'.$form_id.'" id="email_'.$form_id.'" value="" />
    @@ -849,29 +886,32 @@
     ';
       }
    
    -  echo '<img id="'.$label.'" class="si-captcha" src="'.$securimage_show_url.'" '.$securimage_size.' alt="';
    -  echo ($si_captcha_opt['si_captcha_tooltip_captcha'] != '') ? esc_attr( $si_captcha_opt['si_captcha_tooltip_captcha'] ) : esc_attr(__('CAPTCHA Image', 'si-captcha'));
    -  echo '" title="';
    -  echo ($si_captcha_opt['si_captcha_tooltip_captcha'] != '') ? esc_attr( $si_captcha_opt['si_captcha_tooltip_captcha'] ) : esc_attr(__('CAPTCHA Image', 'si-captcha'));
    -  echo '" />'."\n";
    +  $si_html .= '<img id="'.$label.'" class="si-captcha" src="'.$securimage_show_url.'" '.$securimage_size.' alt="';
    +  $si_html .= ($si_captcha_opt['si_captcha_tooltip_captcha'] != '') ? esc_attr( $si_captcha_opt['si_captcha_tooltip_captcha'] ) : esc_attr(__('CAPTCHA Image', 'si-captcha'));
    +  $si_html .= '" title="';
    +  $si_html .= ($si_captcha_opt['si_captcha_tooltip_captcha'] != '') ? esc_attr( $si_captcha_opt['si_captcha_tooltip_captcha'] ) : esc_attr(__('CAPTCHA Image', 'si-captcha'));
    +  $si_html .= '" />'."\n";
       if($capt_disable_sess) {
    -        echo '    <input id="si_code_'.$form_id.'" name="si_code_'.$form_id.'" type="hidden"  value="'.$prefix.'" />'."\n";
    +        $si_html .= '    <input id="si_code_'.$form_id.'" name="si_code_'.$form_id.'" type="hidden"  value="'.$prefix.'" />'."\n";
       }
    
    -  echo '    <div id="si_refresh_'.$form_id.'">'."\n";
    -  echo '<a href="#" rel="nofollow" title="';
    -  echo ($si_captcha_opt['si_captcha_tooltip_refresh'] != '') ? esc_attr( $si_captcha_opt['si_captcha_tooltip_refresh'] ) : esc_attr(__('Refresh Image', 'si-captcha'));
    +  $si_html .= '    <div id="si_refresh_'.$form_id.'">'."\n";
    +  $si_html .= '<a href="#" rel="nofollow" title="';
    +  $si_html .= ($si_captcha_opt['si_captcha_tooltip_refresh'] != '') ? esc_attr( $si_captcha_opt['si_captcha_tooltip_refresh'] ) : esc_attr(__('Refresh Image', 'si-captcha'));
       if($capt_disable_sess) {
    -    echo '" onclick="si_captcha_refresh(\''.$label.'\',\''.$form_id.'\',\''.$securimage_url.'\',\''.$securimage_show_rf_url.'\'); return false;">'."\n";
    +    $si_html .= '" onclick="si_captcha_refresh(\''.$label.'\',\''.$form_id.'\',\''.$securimage_url.'\',\''.$securimage_show_rf_url.'\'); return false;">'."\n";
       }else{
    -    echo '" onclick="document.getElementById(\''.$label.'\').src = \''.$securimage_show_url.'&sid=\''.' + Math.random(); return false;">'."\n";
    +    $si_html .= '" onclick="document.getElementById(\''.$label.'\').src = \''.$securimage_show_url.'&sid=\''.' + Math.random(); return false;">'."\n";
       }
    -  echo '      <img class="captchaImgRefresh" src="'.$si_captcha_url.'/images/refresh.png" width="22" height="20" alt="';
    -  echo ($si_captcha_opt['si_captcha_tooltip_refresh'] != '') ? esc_attr( $si_captcha_opt['si_captcha_tooltip_refresh'] ) : esc_attr(__('Refresh Image', 'si-captcha'));
    -  echo '" onclick="this.blur();" /></a>
    +  $si_html .= '      <img class="captchaImgRefresh" src="'.$si_captcha_url.'/images/refresh.png" width="22" height="20" alt="';
    +  $si_html .= ($si_captcha_opt['si_captcha_tooltip_refresh'] != '') ? esc_attr( $si_captcha_opt['si_captcha_tooltip_refresh'] ) : esc_attr(__('Refresh Image', 'si-captcha'));
    +  $si_html .= '" onclick="this.blur();" /></a>
       </div>
       ';
    
    +  if ( $no_echo ) return $si_html;
    +  echo $si_html;
    +
     } // end function si_captcha_captcha_html
    
     function si_captcha_plugin_action_links( $links, $file ) {
    @@ -1230,6 +1270,7 @@
    
       if ($si_captcha_opt['si_captcha_login'] == 'true') {
         add_action('login_form', array( &$si_image_captcha, 'si_captcha_login_form' ) );
    +    add_filter('login_form_middle', array( &$si_image_captcha, 'si_captcha_inline_login_form' ) );
         add_action('login_head', array( &$si_image_captcha, 'si_captcha_login_head' ) );
         add_action('bp_login_bar_logged_out', array( &$si_image_captcha, 'si_captcha_bp_login_form' ) );
         add_action('bp_sidebar_login_form', array( &$si_image_captcha, 'si_captcha_bp_login_sidebar_form' ) );

    Third party plugins that use wp_login_form() need to allow SI CAPTCHA fields to pass through any login form submission handling (e.g. https://wordpress.org/support/topic/allow-inserted-captcha-or-other-fields?replies=1)

    https://wordpress.org/plugins/si-captcha-for-wordpress/

  2. spameur
    Member
    Posted 2 months ago #

    An hope was born! Great!
    ...but can't understand your markup.
    Could you post the complete modified file ?
    What Mike thinks about it and security ?
    Thanks anyway.
    Regards.

  3. iisisrael
    Member
    Posted 2 months ago #

    The whole script as modified:

    [Excessive code mpderated. Please use a pastebin.]

  4. iisisrael
    Member
    Posted 2 months ago #

  5. wpinklady
    Member
    Posted 1 month ago #

    How to add "some code" into Woocommerce login/lost password form??? It only shows up at Register form. Can the team help??? Thank you very much.

Reply

You must log in to post.

About this Plugin

About this Topic

Tags

No tags yet.