PluginProbe ʕ •ᴥ•ʔ
Shortcoder — Create Shortcodes for Anything / 5.3.3
Shortcoder — Create Shortcodes for Anything v5.3.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 5 years ago font 5 years ago images 5 years ago js 5 years ago admin.php 5 years ago edit.php 5 years ago form.php 5 years ago insert.php 5 years ago manage.php 5 years ago tools.php 5 years ago
form.php
112 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 ' . $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 $defaults = array(
31
32 'text' => array(
33 'type' => 'text',
34 'value' => '',
35 'id' => '',
36 'class' => 'regular-text',
37 'name' => '',
38 'placeholder' => '',
39 'required' => '',
40 'helper' => '',
41 'tooltip' => '',
42 'custom' => ''
43 ),
44
45 'select' => array(
46 'id' => '',
47 'class' => '',
48 'name' => '',
49 'list' => array(),
50 'value' => '',
51 'helper' => '',
52 'tooltip' => '',
53 'custom' => ''
54 ),
55
56 'textarea' => array(
57 'type' => 'text',
58 'value' => '',
59 'name' => '',
60 'id' => '',
61 'class' => '',
62 'placeholder' => '',
63 'rows' => '',
64 'cols' => '',
65 'helper' => '',
66 'tooltip' => '',
67 'custom' => ''
68 )
69
70 );
71
72 $params = wp_parse_args( $params, $defaults[ $field_type ] );
73 $field_html = '';
74
75 extract( $params, EXTR_SKIP );
76
77 $id_attr = empty( $id ) ? '' : 'id="' . $id . '"';
78
79 switch( $field_type ){
80 case 'text':
81 $field_html = "<input type='$type' class='$class' $id_attr name='$name' value='$value' placeholder='$placeholder' " . ( $required ? "required='$required'" : "" ) . " $custom />";
82 break;
83
84 case 'select':
85 $field_html .= "<select name='$name' class='$class' $id_attr $custom>";
86 foreach( $list as $k => $v ){
87 $field_html .= "<option value='$k' " . selected( $value, $k, false ) . ">$v</option>";
88 }
89 $field_html .= "</select>";
90 break;
91
92 case 'textarea':
93 $field_html .= "<textarea $id_attr name='$name' class='$class' placeholder='$placeholder' rows='$rows' cols='$cols' $custom>$value</textarea>";
94 break;
95
96 }
97
98 if( !empty( $tooltip ) ){
99 $field_html .= "<div class='sc-tt'><span class='dashicons dashicons-editor-help'></span><span class='sc-tt-text'>$tooltip</span></div>";
100 }
101
102 if( !empty( $helper ) ){
103 $field_html .= "<p class='description'>$helper</p>";
104 }
105
106 return $field_html;
107
108 }
109
110 }
111
112 ?>