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 / Select.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
Select.php
101 lines
1 <?php
2
3 if ( ! defined( 'ABSPATH' ) ) {
4 exit;
5 }
6
7 class AC_Form_Element_Select extends AC_Form_Element {
8
9 /**
10 * @var string
11 */
12 protected $no_result = '';
13
14 protected function render_options( array $options ) {
15 $output = array();
16
17 foreach ( $options as $key => $option ) {
18 if ( isset( $option['options'] ) && is_array( $option['options'] ) ) {
19 $output[] = $this->render_optgroup( $option );
20
21 continue;
22 }
23
24 $output[] = $this->render_option( $key, $option );
25 }
26
27 return implode( "\n", $output );
28 }
29
30 protected function render_option( $key, $label ) {
31 $template = '<option %s>%s</option>';
32 $attributes = $this->get_option_attributes( $key );
33
34 return sprintf( $template, $this->get_attributes_as_string( $attributes ), esc_html( $label ) );
35 }
36
37 protected function get_option_attributes( $key ) {
38 $attributes = array();
39 $attributes['value'] = $key;
40
41 if ( selected( $this->get_value(), $key, false ) ) {
42 $attributes['selected'] = 'selected';
43 }
44
45 return $attributes;
46 }
47
48 /**
49 * @param array $group
50 *
51 * @return string
52 */
53 protected function render_optgroup( array $group ) {
54 $template = '<optgroup %s>%s</optgroup>';
55 $attributes = array();
56
57 if ( isset( $group['title'] ) ) {
58 $attributes['label'] = esc_attr( $group['title'] );
59 }
60
61 return sprintf( $template, $this->get_attributes_as_string( $attributes ), $this->render_options( $group['options'] ) );
62 }
63
64 public function render() {
65 if ( ! $this->get_options() ) {
66 return $this->get_no_result();
67 }
68
69 $template = '
70 <select %s>
71 %s
72 </select>
73 %s';
74
75 $attributes = $this->get_attributes();
76 $attributes['name'] = $this->get_name();
77 $attributes['id'] = $this->get_id();
78
79 return sprintf( $template, $this->get_attributes_as_string( $attributes ), $this->render_options( $this->get_options() ), $this->render_description() );
80 }
81
82 /**
83 * @return string
84 */
85 public function get_no_result() {
86 return $this->no_result;
87 }
88
89 /**
90 * @param string $no_result
91 *
92 * @return $this
93 */
94 public function set_no_result( $no_result ) {
95 $this->no_result = (string) $no_result;
96
97 return $this;
98 }
99
100 }
101