如何在 wordpress 插件 Contact form 7 中验证当前服务器时间?

How to validate current server time in wordpress plugin Contact form 7?

当用户点击提交按钮时,我需要验证当前的服务器时间和日期,如果服务器时间不在所需的时间间隔或日期(周末)内,则会出现 return 错误消息。

想通了!

    add_action("wpcf7_before_send_mail", "wpcf7_do_something_else", 15, 3);  
    function wpcf7_do_something_else($cf7, &$abort, $submission) {
        $id = $cf7->id();  // id of your cf7 form

        if ($id == 3580) {

            $date = date_i18n( get_option( 'date_format' ) );
            $date = explode(" ", $date);
            $day = $date[0];
            $time = date_i18n( get_option( 'time_format' ) );
            $time = explode(':',$time);
            $hour = intval($time[0]);

            //custom day and time validation
            if ( ( $day == 'Sunday' || $day == 'Saturday' ) || !( ( 5 <= $hour) && ($hour <= 20) ) || ( $day == "Friday" && $hour >= 20 ) ) {
                $abort = true; // &$abort reference
                $submission->set_status( 'validation_failed' );
                $errMsg = "Your error message"; // custom error message
                $submission->set_response( $cf7->filter_message($errMsg) ); 
            }
        }

        return $wpcf;
    }

希望这对某人有所帮助:)