WPCF7_Validation::invalidate()publicCF7 1.0

Marks a form control as an invalid field.

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

Хуков нет.

Возвращает

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

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

$WPCF7_Validation = new WPCF7_Validation();
$WPCF7_Validation->invalidate( $context, $error );
$context(WPCF7_FormTag|массив|строка) (обязательный)
Context representing the target field.
$error(WP_Error|строка) (обязательный)
The error of the field.

Код WPCF7_Validation::invalidate() CF7 5.9.3

public function invalidate( $context, $error ) {
	if ( $context instanceof WPCF7_FormTag ) {
		$tag = $context;
	} elseif ( is_array( $context ) ) {
		$tag = new WPCF7_FormTag( $context );
	} elseif ( is_string( $context ) ) {
		$tags = wpcf7_scan_form_tags( array( 'name' => trim( $context ) ) );
		$tag = $tags ? new WPCF7_FormTag( $tags[0] ) : null;
	}

	$name = ! empty( $tag ) ? $tag->name : null;

	if ( empty( $name )
	or ! wpcf7_is_name( $name ) ) {
		return;
	}

	if ( is_wp_error( $error ) ) {
		$message = $error->get_error_message();
	} else {
		$message = $error;
	}

	if ( $this->is_valid( $name ) ) {
		$id = $tag->get_id_option();

		if ( empty( $id )
		or ! wpcf7_is_name( $id ) ) {
			$id = null;
		}

		$this->invalid_fields[$name] = array(
			'reason' => (string) $message,
			'idref' => $id,
		);
	}
}