/**
  * Verify the visitor if the form was submitted.
  *
  * @since 0.1.0
  *
  * @return void
  */
 public function verify()
 {
     if (!isset($_POST['av-nonce']) || !wp_verify_nonce($_POST['av-nonce'], 'verify-age')) {
         return;
     }
     $redirect_url = remove_query_arg(array('age-verified', 'verify-error'), wp_get_referer());
     $is_verified = false;
     $error = 1;
     // Catch-all in case something goes wrong
     $input_type = av_get_input_type();
     switch ($input_type) {
         case 'checkbox':
             if (isset($_POST['av_verify_confirm']) && (int) $_POST['av_verify_confirm'] == 1) {
                 $is_verified = true;
             } else {
                 $error = 2;
             }
             // Didn't check the box
             break;
         default:
             if (checkdate((int) $_POST['av_verify_m'], (int) $_POST['av_verify_d'], (int) $_POST['av_verify_y'])) {
                 $age = av_get_visitor_age($_POST['av_verify_y'], $_POST['av_verify_m'], $_POST['av_verify_d']);
                 if ($age >= av_get_minimum_age()) {
                     $is_verified = true;
                 } else {
                     $error = 3;
                 }
                 // Not old enough
             } else {
                 $error = 4;
                 // Invalid date
             }
             break;
     }
     $is_verified = apply_filters('av_passed_verify', $is_verified);
     if ($is_verified == true) {
         do_action('av_was_verified');
         if (isset($_POST['av_verify_remember'])) {
             $cookie_duration = time() + av_get_cookie_duration() * 60;
         } else {
             $cookie_duration = 0;
         }
         setcookie('age-verified', 1, $cookie_duration, COOKIEPATH, COOKIE_DOMAIN, false);
         wp_redirect(esc_url_raw($redirect_url) . '?age-verified=' . wp_create_nonce('age-verified'));
         exit;
     } else {
         do_action('av_was_not_verified');
         wp_redirect(esc_url_raw(add_query_arg('verify-error', $error, $redirect_url)));
         exit;
     }
 }
示例#2
0
/**
 * Adds a checkbox to the default WordPress registration form for
 * users to verify their ages. You can filter the text if you like.
 *
 * @since 0.1
 * @echo string
 */
function av_register_form()
{
    $text = '<p class="age-verify"><label for="_av_confirm_age"><input type="checkbox" name="_av_confirm_age" id="_av_confirm_age" value="1" /> ';
    $text .= esc_html(sprintf(apply_filters('av_registration_text', __('I am at least %s years old', 'age-verify')), av_get_minimum_age()));
    $text .= '</label></p><br />';
    echo $text;
}