WPCF7_MailTag_OutputCalculator::calc_swv_result()privateCF7 1.0

Метод класса: WPCF7_MailTag_OutputCalculator{}

Хуков нет.

Возвращает

null. Ничего (null).

Использование

// private - только в коде основоного (родительского) класса
$result = $this->calc_swv_result( $mail_tag, $rule );
$mail_tag(WPCF7_MailTag) (обязательный)
-
$rule([SWV\Rule]()) (обязательный)
-

Код WPCF7_MailTag_OutputCalculator::calc_swv_result() CF7 6.0.1

private function calc_swv_result( WPCF7_MailTag $mail_tag, SWV\Rule $rule ) {

	if ( $rule instanceof SWV\AnyRule ) {
		$result = 0b000;

		foreach ( $rule->rules() as $child_rule ) {
			$result |= $this->calc_swv_result( $mail_tag, $child_rule );
		}

		return $result;
	}

	if ( $rule instanceof SWV\CompositeRule ) {
		$result = 0b111;

		foreach ( $rule->rules() as $child_rule ) {
			$result &= $this->calc_swv_result( $mail_tag, $child_rule );
		}

		return $result;
	}

	$field_prop = $rule->get_property( 'field' );

	if ( empty( $field_prop ) or $field_prop !== $mail_tag->field_name() ) {
		return self::email | self::text | self::blank;
	}

	if ( $rule instanceof SWV\RequiredRule ) {
		return ~ self::blank;
	}

	if ( $rule instanceof SWV\EmailRule ) {
		return self::email | self::blank;
	}

	if ( $rule instanceof SWV\EnumRule ) {
		$acceptable_values = (array) $rule->get_property( 'accept' );
		$acceptable_values = array_map( 'strval', $acceptable_values );
		$acceptable_values = array_filter( $acceptable_values );
		$acceptable_values = array_unique( $acceptable_values );

		if ( ! $mail_tag->get_option( 'do_not_heat' ) ) {
			$pipes = $this->contact_form->get_pipes(
				$mail_tag->field_name()
			);

			$acceptable_values = array_map(
				static function ( $val ) use ( $pipes ) {
					return $pipes->do_pipe( $val );
				},
				$acceptable_values
			);
		}

		$email_values = array_filter(
			$acceptable_values,
			'wpcf7_is_mailbox_list'
		);

		if ( count( $email_values ) === count( $acceptable_values ) ) {
			return self::email | self::blank;
		} else {
			return self::email | self::text | self::blank;
		}
	}

	return self::email | self::text | self::blank;
}