'; $field .= '
'; return $field; } /** * Main verification function. Decides if submission was ok or not. * * @param boolean $response - Response to verify. * @param boolean $is_fallback_challenge - Is this a fallback response. * * @return bool - Did verify or not. * * @since 7.6.0 */ public static function verify( $response = false, $is_fallback_challenge = false ) { // phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundAfterLastUsed static $last_verify = null; static $last_response = null; static $duplicate_response = false; $remoteip = isset( $_SERVER['REMOTE_ADDR'] ) ? sanitize_text_field( wp_unslash( $_SERVER['REMOTE_ADDR'] ) ) : ''; $secret_key = trim( C4WP_Functions::c4wp_get_secret_key() ); $verify = false; // $_POSTs ignored for phpcs as nonce not required. if ( false === $response ) { $response = isset( $_POST['h-captcha-response'] ) ? sanitize_text_field( wp_unslash( $_POST['h-captcha-response'] ) ) : ''; // phpcs:ignore WordPress.Security.NonceVerification.Missing, if ( empty( $response ) ) { $response = empty( $response ) && isset( $_POST['response'] ) ? sanitize_text_field( wp_unslash( $_POST['response'] ) ) : ''; // phpcs:ignore WordPress.Security.NonceVerification.Missing, } } // Store what we send to google in case we need to verify if its a duplicated request. $last_response = $response; if ( $response === $last_response ) { $duplicate_response = true; } $pre_check = apply_filters( 'c4wp_verify_captcha_pre', null, $response ); if ( null !== $pre_check ) { return $pre_check; } // if $secret_key is not set. if ( ! $secret_key ) { return true; } $is_ajax_verification = ( isset( $_POST['action'] ) && 'c4wp_ajax_verify' === $_POST['action'] ) ? true : false; // phpcs:ignore WordPress.Security.NonceVerification.Missing, // Bail if we have nothing to work with. if ( empty( $response ) && ! isset( $_POST['h-captcha-response'] ) && ! $is_ajax_verification ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing, $return = ( 'proceed' === C4WP_Functions::c4wp_get_option( 'pass_on_no_captcha_found', 'proceed' ) ) ? true : false; return $return; } if ( ! $response || ! $remoteip ) { return $verify; } if ( null !== $last_verify ) { return $last_verify; } $url = apply_filters( 'c4wp_hcaptcha_verify_url', self::$verify_url ); // make a POST request to the Google reCAPTCHA Server. $request = wp_remote_post( $url, array( 'timeout' => 10, 'body' => array( 'secret' => $secret_key, 'response' => $response, 'remoteip' => $remoteip, ), ) ); // get the request response body. $request_body = wp_remote_retrieve_body( $request ); if ( ! $request_body ) { return $verify; } $result = json_decode( $request_body, true ); if ( isset( $result['success'] ) && true === $result['success'] ) { if ( isset( $result['score'] ) && ! empty( $result['score'] ) ) { $verify = $result['score'] >= C4WP_Functions::c4wp_get_option( 'score', '0.5' ); } else { $verify = true; } } $verify = apply_filters( 'c4wp_verify_captcha', $verify, $result, $response ); $last_verify = $verify; // If we know this is a duplicated request, pass verification. if ( isset( $result['error-codes'] ) && 'timeout-or-duplicate' === $result['error-codes'][0] && $duplicate_response ) { $verify = true; } /* @dev:start */ $dev_mode = apply_filters( 'c4wp_enable_dev_mode', false ); if ( $dev_mode ) { $store = array(); $store['verify_post'] = $_POST; // phpcs:ignore WordPress.Security.NonceVerification.Missing, $store['verify_result'] = $result; $store['verify_return'] = $verify; C4WP_Functions::c4wp_log_verify_result( $store ); if ( 'return_false' === C4WP_Functions::c4wp_get_option( 'override_result' ) ) { return false; } elseif ( 'return_true' === C4WP_Functions::c4wp_get_option( 'override_result' ) ) { return true; } } /* @dev:end */ return $verify; } /** * Method specific footer scripts. * * @return void * * @since 7.6.0 */ public static function footer_scripts() { // PHPCS ignored as this method uses inline scripts, which it does not like. // phpcs:disable ?>