PluginProbe
GiveWP – Donation Plugin and Fundraising Platform / 4.1.0
GiveWP – Donation Plugin and Fundraising Platform v4.1.0
4.16.8 4.16.7.2 4.16.7.1 4.16.7 4.16.6.1 4.16.6 4.16.5.1 4.16.5 4.16.4 4.16.3 4.16.2 4.16.1 4.16.0 4.15.5 4.15.4 4.15.3 4.15.2 4.15.1 4.15.0 2.3.0 2.3.1 2.3.2 2.30.0 2.31.0 2.31.1 All 253 releases
give / src / Helpers / Html.php
Html.php
57 lines 1.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Give\Helpers;
4
5 /**
6 * HTML related helper functions
7 *
8 * @since 2.12.0
9 */
10 class Html
11 {
12 /**
13 * A helper creating class attribute strings
14 *
15 * Note that no deduplication of class names takes place.
16 *
17 * Usage:
18 *
19 * ```php
20 * Html::classNames(
21 * // Provide default class names
22 * 'field-label',
23 * // Conditionally set class names
24 * [
25 * 'fancy': $this->isFancy(),
26 * 'hidden': $this->isHidden(),
27 * ],
28 * // This works the same providing them as individual arguments
29 * ['w-1/3', 'flex-grow', 'flex-shrink-0']
30 * );
31 * ```
32 *
33 * @param string|array ...$arguments
34 *
35 * @return string
36 */
37 public static function classNames(...$arguments)
38 {
39 $classList = [];
40
41 array_walk_recursive(
42 $arguments,
43 static function ($value, $key) use (&$classList) {
44 if (is_string($key) && $value === true) {
45 // In this case, a class name (the array key) is being set conditionally.
46 // We add the class name to the list if it passed the condition (the array value).
47 $classList[] = $key;
48 } elseif (is_string($value)) {
49 $classList[] = $value;
50 }
51 }
52 );
53
54 return implode(' ', $classList);
55 }
56 }
57