<?php if ( !defined( 'ABSPATH' ) ) exit;//PHPの宣言と直接アクセスの拒否

/***** ユーザー登録スパム対策 *****/
/* https://nendeb.com/260
/* ダミー項目を作る */
function haup_check_spam_register_field() {
	wp_nonce_field( 'haup_register_nonce_action', 'haup_register_nonce' );
?>
<p style="display:none">
	<label><?php echo esc_html( 'URL' ) ?><br />
	<input type="text" name="user_proof_url" id="user_proof_url" class="input" size="25" tabindex="30" /></label>
</p>
<?php
}
add_action( 'register_form', 'haup_check_spam_register_field' );
 
/* ダミー項目に入力があったらスパムと判定する */
function haup_check_spam_register_field_validate( $sanitized_user_login, $user_email, $errors ) {
//nonce検証
	if ( isset( $_POST['haup_register_nonce'] ) && ! check_admin_referer( 'haup_register_nonce_action', 'haup_register_nonce' ) ) {
		wp_die( '<strong>ERROR</strong>' );
	}

	if ( !empty( $_POST[ 'user_proof_url' ] ) ) {
		return $errors->add( 'proofempty', '<strong>ERROR</strong>' );
	}
}
add_action( 'register_post', 'haup_check_spam_register_field_validate', 10, 3 );