• I want to add a security question to the registration page.

    I found a code snippet that works very well on non-multisites:

    add_action( 'register_form', 'add_register_field' );
    function add_register_field() { ?>
    	<p>
    		<label><?php _e('What is the name of the ship in the TV show Firefly?') ?><br />
    		<input type="text" name="user_proof" id="user_proof" class="input" size="25" tabindex="20" /></label>
    	</p>
    <?php }
    
    add_action( 'register_post', 'add_register_field_validate', 10, 3 );
    function add_register_field_validate( $sanitized_user_login, $user_email, $errors) {
    	if (!isset($_POST[ 'user_proof' ]) || empty($_POST[ 'user_proof' ])) {
    		return $errors->add( 'proofempty', '<strong>ERROR</strong>: You did not answer the proof-of-humanship question.'  );
    	} elseif ( strtolower( $_POST[ 'user_proof' ] ) != 'serenity' ) {
    		return $errors->add( 'prooffail', '<strong>ERROR</strong>: You did not answer the proof-of-humanship question correctly.'  );
    	}
    }

    I know that “register_form” should be replaced by “signup_extra_fields” and I think “register_post” should be replaced by “wpmu_validate_blog_signup”, but all I get is a blank page when I try to submit it. I am not sure how to use the wpmu_validate_blog_signup function properly.

    Can someone tell me what I need to change to make it work?

Viewing 1 replies (of 1 total)
  • Moderator bcworkz

    (@bcworkz)

    Check the source code for the related function. Where the filter is applied, there’s an informative inline doc/comment about the data passed (as a single array) to your callback. Naturally your security question answer wouldn’t be there, but you can get it from $_POST. If all is good, return the array unchanged. If there’s a problem, add an error message in the passed WP_Error object. If there’s no WP_Error object in $result[‘errors’], create one anew. Update the array accordingly and return it.

Viewing 1 replies (of 1 total)
  • The topic ‘Adding a “Security Question” to multisite registration page’ is closed to new replies.