PluginProbe
WP Coder – Insert & Manage Code Snippets / 4.2
WP Coder – Insert & Manage Code Snippets v4.2
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 +65 -20 3.0.54.2 View file →
@@ -8,19 +8,23 @@
8 8
9 9 public static function textarea( $name = '', $default = '' ): void {
10 10 self::check_name( $name );
11 11 $value = self::get_value( $name, $default );
12 - $id = self::get_id( $name );
13 12 $name = self::get_name( $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 = [] ): void {
17 + public static function select( $name = '', $default = '', $options = [] , $order = ''): void {
18 18 self::check_name( $name );
19 - $value = self::get_value( $name, $default );
20 - $id = self::get_id( $name );
21 - $name = self::get_name( $name );
22 - echo '<select name="' . esc_attr( $name ) . '" id="' . esc_attr( $id ) . '">';
19 + $pre_name = $name;
20 + if ( is_numeric( $order ) ) {
21 + $pre_name = $name . '[' . $order . ']';
22 + }
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).'">';
23 27 foreach ( $options as $key => $val ) {
24 28
25 29 if ( strrpos( $key, '_start' ) ) {
26 30 echo '<optgroup label="' . esc_attr( $val ) . '">';
@@ -32,26 +36,60 @@
32 36 }
33 37 echo '</select>';
34 38 }
35 39
36 - public static function text( $name = '', $default = '', $type = 'text' ): void {
40 + public static function radio( $name = '', $default = '', $options = [], $order = '' ): void {
37 41 self::check_name( $name );
38 - $value = self::get_value( $name, $default );
39 - $id = self::get_id( $name );
40 - $name = self::get_name( $name );
41 - echo '<input type="' . esc_attr( $type ) . '" name="' . esc_attr( $name ) . '" id="' . esc_attr( $id ) . '" value="' . esc_attr( $value ) . '">';
42 + $pre_name = $name;
43 + if ( is_numeric( $order ) ) {
44 + $pre_name = $name . '[' . $order . ']';
45 + }
46 + $value = self::get_value( $pre_name, $default );
47 + $name = self::get_name( $name, $order );
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 + }
42 53 }
43 54
44 - public static function checkbox( $name = '' ): void {
55 + public static function text( $name = '', $default = '', $type = 'text', $order = '' ): void {
45 56 self::check_name( $name );
46 - $value = self::get_value( $name );
47 - $id = self::get_id( $name );
48 - $name = self::get_name( $name );
49 - echo '<input type="checkbox" name="' . esc_attr( $name ) . '" id="' . esc_attr( $id ) . '" value="1"' . checked( $value, "1", false ) . '>';
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 );
64 + $class = ( $type === 'color' ) ? 'wowp-field-color' : '';
65 + if ( empty( $class ) ) {
66 + echo '<input type="' . esc_attr( $type ) . '" name="' . esc_attr( $name ) . '" value="' . esc_attr( $value ) . '" id="'.esc_attr($id).'">';
67 +
68 + } else {
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 +
71 + }
50 72 }
51 73
52 - private static function get_name( $name ) {
74 + public static function checkbox( $name = '', $order = '' ): void {
75 + self::check_name( $name );
76 + $pre_name = $name;
77 + if ( is_numeric( $order ) ) {
78 + $pre_name = $name . '[' . $order . ']';
79 + }
80 + $value = self::get_value( $pre_name );
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).'">';
85 + }
86 +
87 + private static function get_name( $name, $order = '' ) {
53 88 if ( strpos( $name, '[' ) !== false ) {
89 + if ( is_numeric( $order ) ) {
90 + return 'param' . $name . '[]';
91 + }
54 92 return 'param' . $name;
55 93 }
56 94
57 95 return $name;
@@ -78,9 +116,9 @@
78 116
79 117 return $default[ $name ];
80 118 }
81 119
82 - private static function get_id( $name ) {
120 + public static function get_id( $name ) {
83 121 return str_replace( array( '][', '[', ']' ), array( '_', '', '' ), $name );
84 122 }
85 123
86 124 private static function get_param_value( $name, $array ) {
@@ -99,9 +137,9 @@
99 137 }
100 138
101 139 private static function check_name( $name ) {
102 140 if ( empty( $name ) ) {
103 - wp_die( __( 'Field must have name', 'wpcoder' ) );
141 + wp_die( esc_attr__( 'Field must have name', 'wp-coder' ) );
104 142 }
105 143 }
106 144
107 145 public static function getDefault(): array {
@@ -148,6 +186,13 @@
148 186 }
149 187 }
150 188
151 189 return $data;
190 + }
191 +
192 + public static function add_prefix($prefix, $arr): array {
193 + foreach ($arr as $key => $val) {
194 + $arr[$key]['name'] = $prefix. $val['name'];
195 + }
196 + return $arr;
152 197 }
153 198 }