PluginProbe ʕ •ᴥ•ʔ
Shortcoder — Create Shortcodes for Anything / 6.3
Shortcoder — Create Shortcodes for Anything v6.3
trunk 3.0 3.0.1 3.1 3.2 3.3 3.4 3.4.1 4.0 4.0.1 4.0.2 4.0.3 4.1 4.1.1 4.1.2 4.1.3 4.1.4 4.1.5 4.1.6 4.1.7 4.1.8 4.1.9 4.2 4.3 4.4 4.5 4.6 5.0 5.0.1 5.0.2 5.0.3 5.0.4 5.1 5.2 5.2.1 5.3 5.3.1 5.3.2 5.3.3 5.3.4 5.4 5.5 5.6 5.7 5.8 6.0 6.1 6.2 6.3 6.3.1 6.3.2 6.4 6.5 6.5.1 6.5.2 6.5.3
shortcoder / admin / form.php
shortcoder / admin Last commit date
css 2 years ago font 2 years ago images 2 years ago js 2 years ago admin.php 2 years ago edit.php 2 years ago form.php 2 years ago insert.php 2 years ago manage.php 2 years ago settings.php 2 years ago tools.php 2 years ago
form.php
122 lines
1 <?php
2
3 if( ! defined( 'ABSPATH' ) ) exit;
4
5 class SC_Admin_Form{
6
7 public static function table( $rows = array(), $print = false, $class = '' ){
8
9 $html = '<table class="form-table ' . esc_attr( $class ) . '">';
10
11 foreach( $rows as $row ){
12 $html .= '<tr ' . ( isset( $row[2] ) ? $row[2] : '' ) . '>';
13 $html .= '<th>' . ( isset( $row[0] ) ? $row[0] : '' ) . '</th>';
14 $html .= '<td>' . ( isset( $row[1] ) ? $row[1] : '' ) . '</td>';
15 $html .= '</tr>';
16 }
17
18 $html .= '</table>';
19
20 if( $print ){
21 echo $html;
22 }else{
23 return $html;
24 }
25
26 }
27
28 public static function field( $field_type, $params = array() ){
29
30 $fields = array( 'text', 'select', 'checkbox', 'textarea' );
31
32 $default_props = array(
33 'id' => '',
34 'name' => '',
35 'class' => '',
36 'value' => '',
37 'list' => array(),
38 'type' => 'text',
39 'required' => '',
40 'placeholder' => '',
41 'rows' => '',
42 'cols' => '',
43 'helper' => '',
44 'tooltip' => '',
45 'before_text' => '',
46 'after_text' => '',
47 'custom' => ''
48 );
49
50 if( !in_array( $field_type, $fields ) ){
51 return '';
52 }
53
54 $params = Shortcoder::set_defaults( $params, $default_props );
55 $params = self::clean_attr( $params );
56 $field_html = '';
57
58 extract( $params, EXTR_SKIP );
59
60 $id_attr = empty( $id ) ? '' : 'id="' . $id . '"';
61
62 switch( $field_type ){
63 case 'text':
64 $field_html = "<input type='$type' class='$class' $id_attr name='$name' value='$value' placeholder='$placeholder' " . ( $required ? "required='$required'" : "" ) . " $custom />";
65 break;
66
67 case 'select':
68 $field_html .= "<select name='$name' class='$class' $id_attr $custom>";
69 foreach( $list as $k => $v ){
70 $field_html .= "<option value='$k'" . selected( $value, $k, false ) . ">$v</option>";
71 }
72 $field_html .= "</select>";
73 break;
74
75 case 'textarea':
76 $field_html .= "<textarea $id_attr name='$name' class='$class' placeholder='$placeholder' rows='$rows' cols='$cols' $custom>$value</textarea>";
77 break;
78
79 case 'checkbox':
80 $field_html .= '<div class="radios_wrap">';
81 foreach( $list as $k => $v ){
82 $checked = in_array( $k, $value ) ? ' checked="checked"' : '';
83 $field_html .= "<label class='lbl_margin' $custom><input type='checkbox' name='{$name}[]' class='$class' value='$k' $id_attr $checked />&nbsp;$v </label>";
84 }
85 $field_html .= '</div>';
86 break;
87
88 }
89
90 if( !empty( $tooltip ) ){
91 $field_html .= "<div class='sc-tt'><span class='dashicons dashicons-editor-help'></span><span class='sc-tt-text'>$tooltip</span></div>";
92 }
93
94 if( !empty( $helper ) ){
95 $field_html .= "<p class='description'>$helper</p>";
96 }
97
98 return $field_html;
99
100 }
101
102 public static function clean_attr( $a ){
103
104 foreach( $a as $k=>$v ){
105 if( is_array( $v ) ){
106 $a[ $k ] = self::clean_attr( $v );
107 }else{
108
109 if( in_array( $k, array( 'custom', 'tooltip', 'helper', 'before_text', 'after_text' ) ) ){
110 $a[ $k ] = wp_kses_post( $v );
111 }else{
112 $a[ $k ] = esc_attr( $v );
113 }
114 }
115 }
116
117 return $a;
118 }
119
120 }
121
122 ?>