wp_kses_allowed_html()
Returns an array of allowed HTML tags and attributes for a given context.
Used By: wp_kses()
1 time — 0.000061 sec (very fast) | 50000 times — 1.72 sec (fast)
Hooks from the function
Return
Array
. Array of allowed HTML tags and their allowed attributes.
Usage
wp_kses_allowed_html( $context );
- $context(string|array)
- The context for which to retrieve tags. Allowed values are 'post', 'strip', 'data', 'entities', or the name of a field filter such as pre_user_description, or an array of allowed HTML elements and attributes.
Default: ''
Examples
#1 Get the default list of allowed tags
Here the list is obtained for the user with the role of Administrator.
The list may differ, depending on the role and the specified context.
$data = wp_kses_allowed_html( $context ); print_r( $data ); /* we get Array ( [a] => Array ( [href] => 1 [title] => 1 ) [abbr] => Array ( [title] => 1 ) [acronym] => Array ( [title] => 1 ) [b] => Array() [blockquote] => Array ( [cite] => 1 ) [cite] => Array() [code] => Array() [del] => Array ( [datetime] => 1 ) [em] => Array() [i] => Array() [q] => Array ( [cite] => 1 ) [s] => Array() [strike] => Array() [strong] => Array() [pre] => Array ( [class] => 1 [name] => 1 [code] => 1 ) [var] => Array() [h3] => Array() [h4] => Array() [img] => Array ( [class] => 1 [alt] => 1 [src] => 1 ) [li] => Array() [ol] => Array() [ul] => Array() ) */
#2 If you specify the context
// strips all html (empty array) $data = wp_kses_allowed_html( 'strip' ); /* Array ( ) */ // allows a list of HTML Entities such as $data = wp_kses_allowed_html( 'entities' ); /* Array ( [0] => nbsp [1] => iexcl [2] => cent [3] => pound [4] => curren [5] => yen [6] => brvbar [7] => sect [8] => uml [9] => copy [10] => ordf [11] => laquo [12] => not [13] => shy [14] => reg [15] => macr [16] => deg [17] => plusmn [18] => acute [19] => micro [20] => para [21] => middot etc. ... ) */
// allows all most inline elements and strips all block-level elements except blockquote $allowed_html = wp_kses_allowed_html( 'data' ); // very permissive: allows pretty much all HTML to pass - same as what's normally applied to the_content by default $allowed_html = wp_kses_allowed_html( 'post' );
Notes
- Global. Array. $allowedposttags
- Global. Array. $allowedtags
- Global. Array. $allowedentitynames
Changelog
Since 3.5.0 | Introduced. |
Since 5.0.1 | form removed as allowable HTML tag. |