• So ive been trying to add a honey pot to my WordPress Login, but its not working how I think it should.

    I want to the login to redirect when the login form is filled out and there is any text in the Honey Pot form field.

    This is how I am trying to add the form field and handle the form:

    //LOGIN HONEYPOT
        add_action('login_form','myLogin_honeypot_form');
        function myLogin_honeypot_form (){
            $body = ( isset( $_POST['body'] ) ) ? $_POST['body']: '';
            ?>
            <p id="notTher">
                <label for="body"><?php _e('If you can see the below box, do not input any text. This is a test.','mydomain') ?><br />
                <input type="text" name="body" id="body" class="input" value="<?php echo esc_attr(stripslashes($body)); ?>" size="25" /></label>
            </p>
            <?php
        }
    
    	function myLogin_HoneyPot_Error(){
    	if($_POST['body'] != null){
    			wp_redirect( site_url().'/wp-login.php' );
    		}
    	}
    	add_filter('login_form','myLogin_HoneyPot_Error');

    The new field shows fine, and it redirects properly BUT only if an invalid username is password is entered, if a valid user name and password is entered, the form logs the user in, But i want it to redirect before processing the login and password fields so that the user will not be logged in.

    Thanks.

Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter Spudnic

    (@spudnic072)

    *The new field shows fine, and it redirects properly BUT only if an invalid username and password is entered….

    Thread Starter Spudnic

    (@spudnic072)

    This does the trick.

    //LOGIN HONEYPOT
    	//Add the new form field
    	//name the input body, better chance of attracting bots
        add_action('login_form','myLogin_honeypot_form');
        function myLogin_honeypot_form (){
            $body = ( isset( $_POST['body'] ) ) ? $_POST['body']: '';
            ?>
            <p id="notThere">
                <label for="body"><?php _e('If you can see the below box, do not input any text. This is a test.','mydomain') ?><br />
                <input type="text" name="body" id="body" class="input" value="<?php echo esc_attr(stripslashes($body)); ?>" size="25" /></label>
            </p>
            <?php
        }
    
    	//add the field processing
    	add_filter('login_errors','myLogin_HoneyPot_Error');
    	function myLogin_HoneyPot_Error(){
    	if( strlen( $_POST['body'] ) > 0 ){
    			//login uses a string for error handling
    			//if login error is set the login for will still process, so we have to sabotage the login variable $username
    			$error = sprintf( __( '<strong>ERROR</strong>: Invalid Login. <a href="%s" title="Password Lost and Found">Lost your password</a>?' ), wp_lostpassword_url() );
    			$username = '';
    			return $error;
    		}
    	}

    Thread Starter Spudnic

    (@spudnic072)

    Hide the field with

    notThere{
    display: none;
    }
Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Login Form Honey Pot’ is closed to new replies.