css
6 years ago
font
6 years ago
images
6 years ago
js
6 years ago
admin.php
6 years ago
edit.php
6 years ago
form.php
6 years ago
insert.php
6 years ago
manage.php
6 years ago
tools.php
6 years ago
form.php
110 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 | switch( $field_type ){ |
| 78 | case 'text': |
| 79 | $field_html = "<input type='$type' class='$class' id='$id' name='$name' value='$value' placeholder='$placeholder' " . ( $required ? "required='$required'" : "" ) . " $custom />"; |
| 80 | break; |
| 81 | |
| 82 | case 'select': |
| 83 | $field_html .= "<select name='$name' class='$class' id='$id' $custom>"; |
| 84 | foreach( $list as $k => $v ){ |
| 85 | $field_html .= "<option value='$k' " . selected( $value, $k, false ) . ">$v</option>"; |
| 86 | } |
| 87 | $field_html .= "</select>"; |
| 88 | break; |
| 89 | |
| 90 | case 'textarea': |
| 91 | $field_html .= "<textarea id='$id' name='$name' class='$class' placeholder='$placeholder' rows='$rows' cols='$cols' $custom>$value</textarea>"; |
| 92 | break; |
| 93 | |
| 94 | } |
| 95 | |
| 96 | if( !empty( $tooltip ) ){ |
| 97 | $field_html .= "<div class='sc-tt'><span class='dashicons dashicons-editor-help'></span><span class='sc-tt-text'>$tooltip</span></div>"; |
| 98 | } |
| 99 | |
| 100 | if( !empty( $helper ) ){ |
| 101 | $field_html .= "<p class='description'>$helper</p>"; |
| 102 | } |
| 103 | |
| 104 | return $field_html; |
| 105 | |
| 106 | } |
| 107 | |
| 108 | } |
| 109 | |
| 110 | ?> |