• I just want to add a “password” text field on registration that users have to enter an exact text to be able to continue with the registration.

    I used to just edit my template, but I changed templates and now I don’t know where to do it. I figured it was time to try to do it with a plugin.

    regular spam plugins aren’t cutting it. every once in a while, accounts are being registered and then spamming members. I figure this way will give back the old way that was working fine for years.

    Here’s the code I have so far. it installs, but nothing shows up on the registration page.

    <?php
    
    /**
    * Plugin Name: footballcaptcha
    * Plugin URI: https://www.yourwebsiteurl.com/
    * Description: creates a manual captcha
    * Version: 1.0
    * Author: sixf00t4
    * Author URI: https://yourwebsiteurl.com/
    **/
    
    //class footballcaptcha {
    
    //1. Add a new form element...
    add_action( 'register_form', 'footballcaptcha');
    
    function footballcaptcha_register_form() {
    
        //Get and set any values already sent
        $user_extra = ( isset( $_POST['user_extra'] ) ) ? $_POST['user_extra'] : '';
        ?>
    
        <p>
            <label for="user_extra"><?php _e( 'Extra Field', 'footballcaptcha' ) ?><br />
                <input type="text" name="user_extra" id="user_extra" class="input" value="<?php echo esc_attr( stripslashes( $user_extra ) ); ?>" size="25" /></label>
        </p>
    
        <?php
        }
    
        //2. Add validation. In this case, we make sure first_name is required.
        add_filter( 'registration_errors', 'footballcaptcha_registration_errors', 10, 3 );
        function footballcaptcha_registration_errors( $errors, $sanitized_user_login, $user_email ) {
            
            if ( empty( $_POST['first_name'] ) != 'football' ) {
            $errors->add( 'first_name_error', sprintf('<strong>%s</strong>: %s',__( 'ERROR', 'footballcaptcha' ),__( 'make sure your answer is lowercase and 1 word.', 'footballcaptcha' ) ) );
    
            }
    
            return $errors;
        }
    	
    
        //3. Finally, save our extra registration user meta.
        add_action( 'user_register', 'myplugin_user_register' );
        function footballcaptcha_user_register( $user_id ) {
            if ( ! empty( $_POST['first_name'] ) ) {
                update_user_meta( $user_id, 'first_name', sanitize_text_field( $_POST['first_name'] ) );
            }
       }
    	?>
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘add text check on registration’ is closed to new replies.