PluginProbe ʕ •ᴥ•ʔ
Admin Columns / 3.1
Admin Columns v3.1
7.0.19 2.3.5 2.4 2.4.1 2.4.10 2.4.2 2.4.3 2.4.4 2.4.5 2.4.6 2.4.7 2.4.8 2.4.9 2.5.2 2.5.3 2.5.4 2.5.5 2.5.6 2.5.6.1 2.5.6.2 2.5.6.3 2.5.6.4 3.0 3.0.1 3.0.2 3.0.3 3.0.5 3.0.7 3.1 3.1.1 3.1.10 3.1.2 3.1.3 3.1.5 3.2.3 3.2.7 3.3.1 3.4.1 3.4.6 3.4.8 4.0.1 4.0.3 4.1.6 4.2.2 4.2.5 4.3 4.3.2 4.4.1 4.4.4 4.4.5 4.5.5 4.6.1 4.7.18 4.7.19 4.7.20 4.7.7 7.0.13 7.0.14 7.0.16 trunk 1.0 1.1 1.1.3 1.2 1.2.1 1.3 1.3.1 1.4 1.4.1 1.4.2 1.4.3 1.4.4 1.4.5 1.4.5.1 1.4.6 1.4.6.1 1.4.6.2 1.4.6.3 1.4.6.4 1.4.7 1.4.8 1.4.9 2.0.0 2.0.1 2.0.2 2.0.3 2.1.0 2.1.1 2.1.2 2.1.3 2.1.4 2.1.5 2.2 2.2.1 2.2.1.1 2.2.2 2.2.3 2.2.4 2.2.5 2.2.5.1 2.2.6 2.2.6.1 2.2.6.2 2.2.6.3 2.2.6.4 2.2.7 2.2.8 2.2.8.1 2.2.9 2.3.1 2.3.2 2.3.3
codepress-admin-columns / classes / Form / Element / Checkbox.php
codepress-admin-columns / classes / Form / Element Last commit date
Checkbox.php 8 years ago Input.php 8 years ago Radio.php 8 years ago Select.php 8 years ago
Checkbox.php
111 lines
1 <?php
2
3 if ( ! defined( 'ABSPATH' ) ) {
4 exit;
5 }
6
7 class AC_Form_Element_Checkbox extends AC_Form_Element {
8
9 /**
10 * @var bool
11 */
12 protected $vertical;
13
14 protected $multiple;
15
16 protected function get_type() {
17 return 'checkbox';
18 }
19
20 protected function get_classes() {
21 $classes = array(
22 $this->get_type() . '-labels',
23 );
24
25 if ( $this->is_vertical() ) {
26 $classes[] = 'vertical';
27 }
28
29 return $classes;
30 }
31
32 public function render() {
33 $elements = $this->get_elements();
34
35 if ( ! $elements ) {
36 return false;
37 }
38
39 $template = '<div class="%s-labels %s">%s</div>';
40
41 return sprintf( $template, $this->get_type(), implode( ' ', $this->get_classes() ), implode( "\n", $elements ) );
42 }
43
44 private function get_elements() {
45 if ( $this->is_multiple() ) {
46 $this->set_name( $this->get_name() . '[]' );
47 }
48
49 $options = $this->get_options();
50
51 if ( empty( $options ) ) {
52 return null;
53 }
54
55 $elements = array();
56
57 $value = (array) $this->get_value();
58
59 foreach ( $options as $key => $label ) {
60 $input = new AC_Form_Element_Input( $this->get_name() );
61
62 $input->set_value( $key )
63 ->set_type( $this->get_type() )
64 ->set_id( $this->get_id() . '-' . $key );
65
66 if ( in_array( $key, $value ) ) {
67 $input->set_attribute( 'checked', 'checked' );
68 }
69
70 $attributes = $this->get_attributes();
71
72 $elements[] = sprintf( '<label %s>%s%s</label>', $this->get_attributes_as_string( $attributes ), $input->render(), esc_html( $label ) );
73 }
74
75 if ( $description = $this->render_description() ) {
76 $elements[] = $description;
77 }
78
79 return $elements;
80 }
81
82 public function set_multiple( $multiple ) {
83 $this->multiple = (bool) $multiple;
84
85 return $this;
86 }
87
88 public function is_multiple() {
89 if ( empty( $this->multiple ) ) {
90 return false;
91 }
92
93 return $this->multiple;
94 }
95
96 public function set_vertical( $vertical ) {
97 $this->vertical = (bool) $vertical;
98
99 return $this;
100 }
101
102 public function is_vertical() {
103 if ( empty( $this->vertical ) ) {
104 return false;
105 }
106
107 return $this->vertical;
108 }
109
110 }
111