wp_kses_attr_check
Determine whether an attribute is allowed.
Description
Parameters (6)
- 0. $name (string) =>
&$name
- The attribute name. Returns empty string when not allowed.
- 1. $value (string) =>
&$value
- The attribute value. Returns a filtered value.
- 2. $whole (string) =>
&$whole
- The name=value input. Returns filtered input.
- 3. $vless (string)
- 'y' when attribute like enabled,, otherwise n..
- 4. $element (string)
- The name of the element to which this attribute belongs.
- 5. $allowed_html (array)
- The full list of allowed elements and attributes.
Usage
if ( !function_exists( 'wp_kses_attr_check' ) ) { require_once ABSPATH . WPINC . '/kses.php'; } // The attribute name. Returns empty string when not allowed. $name = &$name; // The attribute value. Returns a filtered value. $value = &$value; // The name=value input. Returns filtered input. $whole = &$whole; // 'y' when attribute like "enabled", otherwise 'n'. $vless = ''; // The name of the element to which this attribute belongs. $element = ''; // The full list of allowed elements and attributes. $allowed_html = array(); // NOTICE! Understand what this does before running. $result = wp_kses_attr_check($name, $value, $whole, $vless, $element, $allowed_html);
Defined (1)
The function is defined in the following location(s).
- /wp-includes/kses.php
- function wp_kses_attr_check( &$name, &$value, &$whole, $vless, $element, $allowed_html ) {
- $allowed_attr = $allowed_html[strtolower( $element )];
- $name_low = strtolower( $name );
- if ( ! isset( $allowed_attr[$name_low] ) || '' == $allowed_attr[$name_low] ) {
- $name = $value = $whole = '';
- return false;
- }
- if ( 'style' == $name_low ) {
- $new_value = safecss_filter_attr( $value );
- if ( empty( $new_value ) ) {
- $name = $value = $whole = '';
- return false;
- }
- $whole = str_replace( $value, $new_value, $whole );
- $value = $new_value;
- }
- if ( is_array( $allowed_attr[$name_low] ) ) {
- // there are some checks
- foreach ( $allowed_attr[$name_low] as $currkey => $currval ) {
- if ( ! wp_kses_check_attr_val( $value, $vless, $currkey, $currval ) ) {
- $name = $value = $whole = '';
- return false;
- }
- }
- }
- return true;
- }