|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
if ( ! defined( 'ABSPATH' ) ) { |
|
4
|
|
|
exit; // Exit if accessed directly |
|
5
|
|
|
} |
|
6
|
|
|
|
|
7
|
|
|
/** |
|
8
|
|
|
* A component class for rendering a bootstrap alert. |
|
9
|
|
|
* |
|
10
|
|
|
* @since 1.0.0 |
|
11
|
|
|
*/ |
|
12
|
|
|
class AUI_Component_Alert { |
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* Build the component. |
|
16
|
|
|
* |
|
17
|
|
|
* @param array $args |
|
18
|
|
|
* |
|
19
|
|
|
* @return string The rendered component. |
|
20
|
|
|
*/ |
|
21
|
|
|
public static function get($args = array()){ |
|
22
|
|
|
$defaults = array( |
|
23
|
|
|
'type' => 'info', |
|
24
|
|
|
'class' => '', |
|
25
|
|
|
'icon' => '', |
|
26
|
|
|
'heading' => '', |
|
27
|
|
|
'content' => '', |
|
28
|
|
|
'footer' => '', |
|
29
|
|
|
'dismissible'=> false, |
|
30
|
|
|
'data' => '', |
|
31
|
|
|
); |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* Parse incoming $args into an array and merge it with $defaults |
|
35
|
|
|
*/ |
|
36
|
|
|
$args = wp_parse_args( $args, $defaults ); |
|
37
|
|
|
$output = ''; |
|
38
|
|
|
if ( ! empty( $args['content'] ) ) { |
|
39
|
|
|
$type = sanitize_html_class( $args['type'] ); |
|
40
|
|
|
if($type=='error'){$type='danger';} |
|
41
|
|
|
$icon = !empty($args['icon']) ? "<i class='".esc_attr($args['icon'])."'></i>" : ''; |
|
42
|
|
|
|
|
43
|
|
|
// set default icon |
|
44
|
|
|
if(!$icon && $args['icon']!==false && $type){ |
|
45
|
|
|
if($type=='danger'){$icon = '<i class="fas fa-exclamation-circle"></i>';} |
|
46
|
|
|
elseif($type=='warning'){$icon = '<i class="fas fa-exclamation-triangle"></i>';} |
|
47
|
|
|
elseif($type=='success'){$icon = '<i class="fas fa-check-circle"></i>';} |
|
48
|
|
|
elseif($type=='info'){$icon = '<i class="fas fa-info-circle"></i>';} |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
$data = ''; |
|
52
|
|
|
$class = !empty($args['class']) ? esc_attr($args['class']) : ''; |
|
53
|
|
|
if($args['dismissible']){$class .= " alert-dismissible fade show";} |
|
54
|
|
|
|
|
55
|
|
|
// open |
|
56
|
|
|
$output .= '<div class="alert alert-' . $type . ' '.$class.'" role="alert" '.$data.'>'; |
|
57
|
|
|
|
|
58
|
|
|
// heading |
|
59
|
|
|
if ( ! empty( $args['heading'] ) ) { |
|
60
|
|
|
$output .= '<h4 class="alert-heading">' . $args['heading'] . '</h4>'; |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
// icon |
|
64
|
|
|
if ( ! empty( $icon) ) { |
|
65
|
|
|
$output .= $icon." "; |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
// content |
|
69
|
|
|
$output .= $args['content']; |
|
70
|
|
|
|
|
71
|
|
|
// dismissible |
|
72
|
|
|
if($args['dismissible']){ |
|
73
|
|
|
$output .= '<button type="button" class="close" data-dismiss="alert" aria-label="Close">'; |
|
74
|
|
|
$output .= '<span aria-hidden="true">×</span>'; |
|
75
|
|
|
$output .= '</button>'; |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
// footer |
|
79
|
|
|
if ( ! empty( $args['footer'] ) ) { |
|
80
|
|
|
$output .= '<hr>'; |
|
81
|
|
|
$output .= '<p class="mb-0">' . $args['footer'] . '</p>'; |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
// close |
|
85
|
|
|
$output .= '</div>'; |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
return $output; |
|
89
|
|
|
} |
|
90
|
|
|
|
|
91
|
|
|
} |