PluginProbe
WP Coder – Insert & Manage Code Snippets / 4.3
WP Coder – Insert & Manage Code Snippets v4.3
4.5.1 1.1 2.3.1 2.3.2 2.4.1 2.5.1 2.5.2 2.5.3 2.5.4 2.5.5 2.5.6 3.0 3.0.1 3.0.2 3.0.3 3.0.4 3.0.5 3.1 3.1.1 3.2 3.2.1 3.3 3.4 3.5 3.5.1 All 39 releases
← All changes | classes/Dashboard/Field.php +40 -26 3.54.3 View file →
@@ -9,13 +9,13 @@
9 9 public static function textarea( $name = '', $default = '' ): void {
10 10 self::check_name( $name );
11 11 $value = self::get_value( $name, $default );
12 12 $name = self::get_name( $name );
13 - $id = self::get_id( $name );
14 - echo '<textarea name="' . esc_attr( $name ) . '" id="' . esc_attr( $id ) . '">' . esc_html( $value ) . '</textarea>';
13 + $id = self::get_id( $name );
14 + echo '<textarea name="' . esc_attr( $name ) . '" id="'.esc_attr($id).'">' . esc_html( $value ) . '</textarea>';
15 15 }
16 16
17 - public static function select( $name = '', $default = '', $options = [], $order = '' ): void {
17 + public static function select( $name = '', $default = '', $options = [] , $order = ''): void {
18 18 self::check_name( $name );
19 19 $pre_name = $name;
20 20 if ( is_numeric( $order ) ) {
21 21 $pre_name = $name . '[' . $order . ']';
@@ -20,25 +20,25 @@
20 20 if ( is_numeric( $order ) ) {
21 21 $pre_name = $name . '[' . $order . ']';
22 22 }
23 23 $value = self::get_value( $pre_name, $default );
24 - $name = self::get_name( $name, $order );
25 - $id = self::get_id( $pre_name );
26 - echo '<select name="' . esc_attr( $name ) . '" id="' . esc_attr( $id ) . '">';
24 + $name = self::get_name( $name , $order);
25 + $id = self::get_id( $pre_name );
26 + echo '<select name="' . esc_attr( $name ) . '" id="'.esc_attr($id).'">';
27 27 foreach ( $options as $key => $val ) {
28 +
28 29 if ( strrpos( $key, '_start' ) ) {
29 30 echo '<optgroup label="' . esc_attr( $val ) . '">';
30 31 } elseif ( strrpos( $key, '_end' ) ) {
31 32 echo '</optgroup>';
32 33 } else {
33 - echo '<option value="' . esc_attr( $key ) . '"' . selected( $value, $key,
34 - false ) . '>' . esc_html( $val ) . '</option>';
34 + echo '<option value="' . esc_attr( $key ) . '"' . selected( $value, $key, false ) . '>' . esc_html( $val ) . '</option>';
35 35 }
36 36 }
37 37 echo '</select>';
38 38 }
39 39
40 - public static function text( $name = '', $default = '', $type = 'text', $order = '' ): void {
40 + public static function radio( $name = '', $default = '', $options = [], $order = '' ): void {
41 41 self::check_name( $name );
42 42 $pre_name = $name;
43 43 if ( is_numeric( $order ) ) {
44 44 $pre_name = $name . '[' . $order . ']';
@@ -45,13 +45,30 @@
45 45 }
46 46 $value = self::get_value( $pre_name, $default );
47 47 $name = self::get_name( $name, $order );
48 48 $id = self::get_id( $pre_name );
49 + foreach ( $options as $key => $val ) {
50 + echo '<input type="radio" name="' . esc_attr( $name ) . '" value="' . esc_attr( $key ) . '"' . checked( $value, $key, false ) . ' id="' . esc_attr( $id ) . '_' . esc_attr($key) . '">';
51 + echo '<label for="' . esc_attr( $id ) . '_' . esc_attr($key) . '">' . esc_html( $val ) . '</label>';
52 + }
53 + }
54 +
55 + public static function text( $name = '', $default = '', $type = 'text', $order = '' ): void {
56 + self::check_name( $name );
57 + $pre_name = $name;
58 + if ( is_numeric( $order ) ) {
59 + $pre_name = $name . '[' . $order . ']';
60 + }
61 + $value = self::get_value( $pre_name, $default );
62 + $name = self::get_name( $name , $order);
63 + $id = self::get_id( $pre_name );
49 64 $class = ( $type === 'color' ) ? 'wowp-field-color' : '';
50 65 if ( empty( $class ) ) {
51 - echo '<input type="' . esc_attr( $type ) . '" name="' . esc_attr( $name ) . '" value="' . esc_attr( $value ) . '" id="' . esc_attr( $id ) . '">';
66 + echo '<input type="' . esc_attr( $type ) . '" name="' . esc_attr( $name ) . '" value="' . esc_attr( $value ) . '" id="'.esc_attr($id).'">';
67 +
52 68 } else {
53 - echo '<input type="text" data-alpha-enabled="true" name="' . esc_attr( $name ) . '" value="' . esc_attr( $value ) . '" class="' . esc_attr( $class ) . '" id="' . esc_attr( $id ) . '">';
69 + echo '<input type="text" data-alpha-enabled="true" name="' . esc_attr( $name ) . '" value="' . esc_attr( $value ) . '" class="' . esc_attr( $class ) . '" id="'.esc_attr($id).'">';
70 +
54 71 }
55 72 }
56 73
57 74 public static function checkbox( $name = '', $order = '' ): void {
@@ -60,13 +77,12 @@
60 77 if ( is_numeric( $order ) ) {
61 78 $pre_name = $name . '[' . $order . ']';
62 79 }
63 80 $value = self::get_value( $pre_name );
64 - $name = self::get_name( $name, $order );
65 - $id = self::get_id( $pre_name );
66 - echo '<input type="checkbox" value="1" id="checkbox_' . esc_attr( $id ) . '"' . checked( '1', $value,
67 - false ) . '>';
68 - echo '<input type="hidden" name="' . esc_attr( $name ) . '" value="' . esc_attr( $value ) . '" class="checkbox-helper" id="' . esc_attr( $id ) . '">';
81 + $name = self::get_name( $name , $order);
82 + $id = self::get_id( $pre_name );
83 + echo '<input type="checkbox" value="1" id="checkbox_'.esc_attr($id).'"' . checked( '1', $value, false ) . '>';
84 + echo '<input type="hidden" name="' . esc_attr( $name ) . '" value="'.esc_attr($value).'" class="checkbox-helper" id="'.esc_attr($id).'">';
69 85 }
70 86
71 87 private static function get_name( $name, $order = '' ) {
72 88 if ( strpos( $name, '[' ) !== false ) {
@@ -72,9 +88,8 @@
72 88 if ( strpos( $name, '[' ) !== false ) {
73 89 if ( is_numeric( $order ) ) {
74 90 return 'param' . $name . '[]';
75 91 }
76 -
77 92 return 'param' . $name;
78 93 }
79 94
80 95 return $name;
@@ -80,11 +95,13 @@
80 95 return $name;
81 96 }
82 97
83 98 private static function get_value( $name, $defval = '' ) {
99 +
84 100 $default = self::getDefault();
85 101
86 102 if ( strpos( $name, '[' ) !== false ) {
103 +
87 104 $value = self::get_param_value( 'param' . $name, $default );
88 105 if ( ! isset( $value ) && ! empty( $defval ) ) {
89 106 return $defval;
90 107 }
@@ -89,8 +106,9 @@
89 106 return $defval;
90 107 }
91 108
92 109 return $value;
110 +
93 111 }
94 112
95 113 if ( empty( $default[ $name ] ) && ! empty( $defval ) ) {
96 114 return $defval;
@@ -95,12 +113,8 @@
95 113 if ( empty( $default[ $name ] ) && ! empty( $defval ) ) {
96 114 return $defval;
97 115 }
98 116
99 - if ( empty( $default[ $name ] ) ) {
100 - return '';
101 - }
102 -
103 117 return $default[ $name ];
104 118 }
105 119
106 120 public static function get_id( $name ) {
@@ -123,9 +137,9 @@
123 137 }
124 138
125 139 private static function check_name( $name ) {
126 140 if ( empty( $name ) ) {
127 - wp_die( __( 'Field must have name', 'floating-button' ) );
141 + wp_die( esc_attr__( 'Field must have name', 'wp-coder' ) );
128 142 }
129 143 }
130 144
131 145 public static function getDefault(): array {
@@ -139,8 +153,9 @@
139 153 $action = isset( $_REQUEST['action'] ) ? sanitize_text_field( $_REQUEST['action'] ) : 'update';
140 154 $result = DBManager::get_data_by_id( $id );
141 155
142 156 if ( $action === 'update' ) {
157 +
143 158 return self::get_data( $result );
144 159 }
145 160
146 161 $data = self::get_data( $result );
@@ -173,12 +188,11 @@
173 188
174 189 return $data;
175 190 }
176 191
177 - public static function add_prefix( $prefix, $arr ): array {
178 - foreach ( $arr as $key => $val ) {
179 - $arr[ $key ]['name'] = $prefix . $val['name'];
192 + public static function add_prefix($prefix, $arr): array {
193 + foreach ($arr as $key => $val) {
194 + $arr[$key]['name'] = $prefix. $val['name'];
180 195 }
181 -
182 196 return $arr;
183 197 }
184 198 }