PluginProbe
GiveWP – Donation Plugin and Fundraising Platform / 2.13.1
GiveWP – Donation Plugin and Fundraising Platform v2.13.1
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
55 lines 1.2 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 * A helper creating class attribute strings
13 *
14 * Note that no deduplication of class names takes place.
15 *
16 * Usage:
17 *
18 * ```php
19 * Html::classNames(
20 * // Provide default class names
21 * 'field-label',
22 * // Conditionally set class names
23 * [
24 * 'fancy': $this->isFancy(),
25 * 'hidden': $this->isHidden(),
26 * ],
27 * // This works the same providing them as individual arguments
28 * ['w-1/3', 'flex-grow', 'flex-shrink-0']
29 * );
30 * ```
31 *
32 * @param string|array ...$arguments
33 *
34 * @return string
35 */
36 public static function classNames( ...$arguments ) {
37 $classList = [];
38
39 array_walk_recursive(
40 $arguments,
41 static function ( $value, $key ) use ( &$classList ) {
42 if ( is_string( $key ) && $value === true ) {
43 // In this case, a class name (the array key) is being set conditionally.
44 // We add the class name to the list if it passed the condition (the array value).
45 $classList[] = $key;
46 } elseif ( is_string( $value ) ) {
47 $classList[] = $value;
48 }
49 }
50 );
51
52 return implode( ' ', $classList );
53 }
54 }
55