@@ -19,16 +19,25 @@ Generate a string of HTML attributes from the associative array provided.
19
19
If ` attr ` is a non-iterable object, then only accessible non-static properties
20
20
will be incorporated into the result.
21
21
22
- If a value of ` attr ` is an array, its values will be concatenated and
23
- delimited with a space .
22
+ If an attribute name is an empty string, the attribute is ignored.
23
+ The attribute name will be trimmed of leading/trailing whitespace .
24
24
25
- If a value of ` attr ` is a boolean, the value's key will be rendered without
26
- a value.
27
-
28
- If the value is Stringable, Arrayble, or a [ ` Closure ` ] [ class.closure ] ,
29
- attempts will be made to parse as a string.
25
+ If an attribute value is callable (either as a [ ` Closure ` ] [ class.closure ] or
26
+ invokable), it is called and the returned value continues processing.
27
+
28
+ If an attribute value is ` null ` , the attribute is ignored.
29
+
30
+ If an attribute value is an arrayable or a stringable object, it is converted
31
+ to its primitive type.
32
+
33
+ If an attribute value is a boolean and ` true ` , the attribute will be rendered
34
+ without a value, otherwise the attribute is ignored.
35
+
36
+ If an attribute value is an array, only numbers and strings are accepted.
37
+ Strings of the array will be trimmed of leading/trailing whitespace.
38
+ If the filtered array is empty, the attribute is ignored.
30
39
31
- Values that cannot be converted into strings will be ignored .
40
+ Any other value will be serialized using [ ` json_encode() ` ] [ function.json_encode ] .
32
41
33
42
- ` callback ` — Callback function for escaping the values for the HTML attributes.
34
43
@@ -57,4 +66,6 @@ into your project path somewhere.
57
66
58
67
[ class.closure ] : https://php.net/class.closure
59
68
[ function.htmlspecialchars ] : https://php.net/function.htmlspecialchars
69
+ [ function.json_encode ] : https://php.net/function.json_encode
70
+ [ object.invoke ] : https://php.net/oop5.magic#object.invoke
60
71
[ wp.esc_attr ] : https://developer.wordpress.org/reference/functions/esc_attr/
0 commit comments