Mailchimp_Helpers::validate_webhook( $request )

Validates the webhook.

Contents


Return Return

(boolean) True if okay. Otherwise, false.


Source Source

File: src/integrations/mailchimp/helpers/mailchimp-helpers.php

	public function validate_webhook( $request ) {
		// Don't process any GET request. Just return true if its a GET statement.
		if ( 'GET' === $request->get_method() ) {
			return true;
		}
		$query_params = $request->get_query_params();
		$headers = $request->get_headers();
		// Mailchimp sets user agent to MailChimp if its coming from their webhook.
		$user_agent = isset( $headers['user_agent'] ) ? $headers['user_agent'] : '';
		if ( empty( $user_agent ) ) {
			return false;
		}
		$user_agent_values = array_values( $user_agent );
		if ( 'MailChimp' !== array_shift( $user_agent_values ) ) {
			return false;
		}
		if ( ! isset( $query_params['key'] ) ) {
			return false;
		}
		$actual_key = $this->get_webhook_key();
		if ( $actual_key !== $query_params['key'] ) {
			return false;
		}
		return true;
	}