wp_kses_attr_parse

Advertisement

Summery Summery

Finds all attributes of an HTML element.

Syntax Syntax

wp_kses_attr_parse( string $element )

Description Description

Does not modify input. May return "evil" output.

Based on wp_kses_split2() and wp_kses_attr().

Parameters Parameters

$element

(Required) HTML element.

Return Return

(array|bool) List of attributes found in the element. Returns false on failure.

Source Source

File: wp-includes/kses.php

		if ( 0 == $working ) { // Not well-formed, remove and try again.
			$attr = wp_kses_html_error( $attr );
			$mode = 0;
		}
	} // End while.

	if ( 1 == $mode && false === array_key_exists( $attrname, $attrarr ) ) {
		// Special case, for when the attribute list ends with a valueless
		// attribute like "selected".
		$attrarr[ $attrname ] = array(
			'name'  => $attrname,
			'value' => '',
			'whole' => $attrname,
			'vless' => 'y',
		);
	}

	return $attrarr;
}

/**
 * Finds all attributes of an HTML element.
 *
 * Does not modify input.  May return "evil" output.
 *
 * Based on `wp_kses_split2()` and `wp_kses_attr()`.
 *
 * @since 4.2.3
 *
 * @param string $element HTML element.
 * @return array|bool List of attributes found in the element. Returns false on failure.
 */
function wp_kses_attr_parse( $element ) {
	$valid = preg_match( '%^(<\s*)(/\s*)?([a-zA-Z0-9]+\s*)([^>]*)(>?)$%', $element, $matches );
	if ( 1 !== $valid ) {
		return false;

Advertisement

Changelog Changelog

Changelog
Version Description
4.2.3 Introduced.

Advertisement

Leave a Reply