WPCF7_HTMLFormatter::end_tag()publicCF7 1.0

Closes an element and its open descendants at a time.

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

Хуков нет.

Возвращает

null. Ничего.

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

$WPCF7_HTMLFormatter = new WPCF7_HTMLFormatter();
$WPCF7_HTMLFormatter->end_tag( $tag );
$tag(строка) (обязательный)
An end tag.

Код WPCF7_HTMLFormatter::end_tag() CF7 5.7.3

public function end_tag( $tag ) {
	if ( preg_match( '/<\/(.+?)(?:\s|>)/', $tag, $matches ) ) {
		$tag_name = strtolower( $matches[1] );
	} else {
		$tag_name = strtolower( $tag );
	}

	$stacked_elements = array_values( $this->stacked_elements );

	$tag_position = array_search( $tag_name, $stacked_elements );

	if ( false === $tag_position ) {
		return;
	}

	// Element groups that make up an indirect nesting structure.
	// Descendant can contain ancestors.
	static $nesting_families = array(
		array(
			'ancestors' => array( 'dl', ),
			'descendants' => array( 'dd', 'dt', ),
		),
		array(
			'ancestors' => array( 'ol', 'ul', 'menu', ),
			'descendants' => array( 'li', ),
		),
		array(
			'ancestors' => array( 'table', ),
			'descendants' => array( 'td', 'th', 'tr', 'thead', 'tbody', 'tfoot', ),
		),
	);

	foreach ( $nesting_families as $family ) {
		$ancestors = (array) $family['ancestors'];
		$descendants = (array) $family['descendants'];

		if ( in_array( $tag_name, $descendants ) ) {
			$intersect = array_intersect(
				$ancestors,
				array_slice( $stacked_elements, 0, $tag_position )
			);

			if ( $intersect ) { // Ancestor appears after descendant.
				return;
			}
		}
	}

	while ( $element = array_shift( $this->stacked_elements ) ) {
		$this->append_end_tag( $element );

		if ( $element === $tag_name ) {
			break;
		}
	}
}