PluginProbe ʕ •ᴥ•ʔ
Shortcoder — Create Shortcodes for Anything / 5.8
Shortcoder — Create Shortcodes for Anything v5.8
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 4 years ago font 4 years ago images 4 years ago js 4 years ago admin.php 4 years ago edit.php 4 years ago form.php 4 years ago insert.php 4 years ago manage.php 4 years ago settings.php 4 years ago tools.php 4 years ago
form.php
103 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 $fields = array( 'text', 'select', 'checkbox', 'textarea' );
31
32 $default_props = array(
33 'id' => '',
34 'name' => '',
35 'class' => '',
36 'value' => '',
37 'list' => array(),
38 'type' => '',
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 $field_html = '';
56
57 extract( $params, EXTR_SKIP );
58
59 $id_attr = empty( $id ) ? '' : 'id="' . $id . '"';
60
61 switch( $field_type ){
62 case 'text':
63 $field_html = "<input type='text' class='$class' $id_attr name='$name' value='$value' placeholder='$placeholder' " . ( $required ? "required='$required'" : "" ) . " $custom />";
64 break;
65
66 case 'select':
67 $field_html .= "<select name='$name' class='$class' $id_attr $custom>";
68 foreach( $list as $k => $v ){
69 $field_html .= "<option value='$k' " . selected( $value, $k, false ) . ">$v</option>";
70 }
71 $field_html .= "</select>";
72 break;
73
74 case 'textarea':
75 $field_html .= "<textarea $id_attr name='$name' class='$class' placeholder='$placeholder' rows='$rows' cols='$cols' $custom>" . esc_textarea( $value ) . "</textarea>";
76 break;
77
78 case 'checkbox':
79 $field_html .= '<div class="radios_wrap">';
80 foreach( $list as $k => $v ){
81 $checked = in_array( $k, $value ) ? ' checked="checked"' : '';
82 $field_html .= "<label class='lbl_margin' $custom><input type='checkbox' name='{$name}[]' class='$class' value='$k' $id_attr $checked />&nbsp;$v </label>";
83 }
84 $field_html .= '</div>';
85 break;
86
87 }
88
89 if( !empty( $tooltip ) ){
90 $field_html .= "<div class='sc-tt'><span class='dashicons dashicons-editor-help'></span><span class='sc-tt-text'>$tooltip</span></div>";
91 }
92
93 if( !empty( $helper ) ){
94 $field_html .= "<p class='description'>$helper</p>";
95 }
96
97 return $field_html;
98
99 }
100
101 }
102
103 ?>