• Resolved hoangemini

    (@hoangemini)


    I want to customize the validate email field to check if the email entered is the same as the login account. But wp_get_current_user() cannot be used to obtain user credentials.

    // validate contact form 7

    add_filter('wpcf7_validate_email*', 'custom_email_confirmation_validation_filter', 20, 2);
    function custom_email_confirmation_validation_filter($result, $tag)
    {
        $current_user_c = wp_get_current_user();
        var_dump($current_user_c);
        if ('apply-email' == $tag->name) {
            $apply_email = isset($_POST['apply-email']) ? trim($_POST['apply-email']) : '';
            $user_email = $current_user_c->user_email;
    
            if ($apply_email != $user_email) {
                $result->invalidate($tag, "間違ったメールアカウト");
            }
        }
    
        return $result;
    }
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
  • The topic ‘In wpcf7_validate_email* not cannot be used wp_get_current_user()’ is closed to new replies.