WPCF7_FormTagsManager::parse_attsprivateCF7 1.0

Parses the attributes of a form-tag to extract the name, options, and values.

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

Хуков нет.

Возвращает

Массив|Строку. An associative array of the options and values if the input is in the correct syntax, otherwise the input text itself.

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

// private - только в коде основоного (родительского) класса
$result = $this->parse_atts( $text );
$text(строка) (обязательный)
Attributes of a form-tag.

Код WPCF7_FormTagsManager::parse_atts() CF7 6.1.4

private function parse_atts( $text ) {
	$atts = array(
		'options' => array(),
		'values' => array(),
	);

	$whitespaces = wpcf7_get_unicode_whitespaces();

	$text = preg_replace( '/[\x{00a0}\x{200b}]+/u', ' ', $text );
	$text = wpcf7_strip_whitespaces( $text );

	$pattern = '%^([-+*=0-9a-zA-Z:.!?#$&@_/|\%' . $whitespaces . ']*?)'
		. '((?:'
		. '[' . $whitespaces . ']*"[^"]*"'
		. '|'
		. '[' . $whitespaces . ']*\'[^\']*\''
		. ')*)$%u';

	if ( preg_match( $pattern, $text, $matches ) ) {
		if ( ! empty( $matches[1] ) ) {
			$atts['options'] = preg_split(
				sprintf( '/[%s]+/u', $whitespaces ),
				wpcf7_strip_whitespaces( $matches[1] )
			);
		}

		if ( ! empty( $matches[2] ) ) {
			preg_match_all( '/"[^"]*"|\'[^\']*\'/', $matches[2], $matched_values );
			$atts['values'] = wpcf7_strip_quote_deep( $matched_values[0] );
		}
	} else {
		$atts = $text;
	}

	return $atts;
}