Icon.php
1.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
<?php
namespace AC\Helper;
class Icon {
public function dashicon( $args = [] ) {
$defaults = [
'icon' => '',
'title' => '',
'class' => '',
'tooltip' => '',
];
$data = (object) wp_parse_args( $args, $defaults );
$class = 'dashicons dashicons-' . $data->icon;
if ( $data->class ) {
$class .= ' ' . trim( $data->class );
}
$attributes = [];
if ( $data->title ) {
$attributes[] = 'title="' . esc_attr( $data->title ) . '"';
}
if ( $data->tooltip && is_string( $data->tooltip ) ) {
$attributes[] = ac_helper()->html->get_tooltip_attr( $data->tooltip );
}
return '<span class="' . esc_attr( $class ) . '" ' . implode( ' ', $attributes ) . '></span>';
}
/**
* @param bool $tooltip
* @param bool $title
* @param string $class
*
* @return string
* @since 3.0
*/
public function yes( $tooltip = false, $title = true, $class = 'green' ) {
if ( true === $title ) {
$title = __( 'Yes' );
}
return $this->dashicon( [ 'icon' => 'yes', 'class' => $class, 'title' => $title, 'tooltip' => $tooltip ] );
}
/**
* @param bool $tooltip
* @param bool $title
* @param string $class
*
* @return string
* @since 3.0
*/
public function no( $tooltip = false, $title = true, $class = 'red' ) {
if ( true === $title ) {
$title = __( 'No' );
}
return $this->dashicon( [ 'icon' => 'no-alt', 'class' => $class, 'title' => $title, 'tooltip' => $tooltip ] );
}
/**
* @param $is_true
* @param string $tooltip
*
* @return string HTML Dashicon
* @since 3.0
*/
public function yes_or_no( $is_true, $tooltip = '' ) {
return $is_true ? $this->yes( $tooltip ) : $this->no( $tooltip );
}
}