public static function meta_box_fill($menu_id, $args) { foreach ($args['args']['fields'] as $field) { ?> <div class="kc-field"> <label for="<?php echo esc_attr("kc-menu_navmeta-{$args['args']['id']}-{$field['id']}"); ?> "><?php echo esc_html($field['title']); ?> </label> <div class="<?php echo esc_attr("kc-field-wrap kc-field-{$field['type']}-wrap"); ?> "> <?php echo _kc_field(array('mode' => 'menu_nav', 'object_id' => $menu_id, 'section' => $args['args']['id'], 'field' => $field)); // xss ok ?> </div> </div> <?php } }
/** * Display additional fields on profile edit page * * @credit Justin Tadlock * @links http://justintadlock.com/archives/2009/09/10/adding-and-using-custom-user-profile-fields * * @param int $user_id User ID * @return null */ public static function _fields($user) { $output = ''; foreach (self::$settings as $group) { foreach ($group as $section) { # Section title & desc $output .= "<h3>{$section['title']}</h3>\n"; if (isset($section['desc']) && !empty($section['desc'])) { $output .= "{$section['desc']}\n"; } # The section $output .= "<table class='form-table'>\n"; $output .= "\t<tbody>\n"; foreach ($section['fields'] as $field) { if (!in_array($field['type'], array('checkbox', 'radio', 'multiinput', 'file'))) { $label_for = $field['id']; if ($field['type'] === 'editor') { $label_for = strtolower(str_replace(array('-', '_'), '', $label_for)); } } else { $label_for = ''; } $args = array('mode' => 'user', 'object_id' => $user->ID, 'section' => $section['id'], 'field' => $field); $output .= "\t\t<tr>\n"; $output .= "\t\t\t<th>" . _kc_field_label($field['title'], $label_for, false, false) . "</th>\n"; $output .= "\t\t\t<td>" . _kc_field($args) . "</td>\n"; $output .= "\t\t</tr>\n"; } $output .= "\t</tbody>\n"; $output .= "</table>\n"; } } echo $output; // xss ok }
public static function get_fields($item, $depth, $args) { $wide_fields = array('textarea', 'checkbox'); $out = ''; foreach (self::$sections as $section) { $out .= '<div class="kc-menu-item-section">'; $out .= "<h2>{$section['title']}</h2>\n"; foreach ($section['fields'] as $field) { $field_html = _kc_field(array('mode' => 'menu_item', 'object_id' => $item->ID, 'section' => $section['id'], 'field' => $field, 'desc_tag' => 'span')); if ($field['type'] == 'special') { $out .= $field_html; continue; } $out .= "<p class='description description-wide'>\n"; $out .= "<label for='edit-menu-item-{$section['id']}-{$field['id']}-{$item->ID}'>{$field['title']}</label><br />\n"; $out .= "<span class='kcs-field-wrap kcs-{$field['type']}-wrap'>{$field_html}</span>\n"; $out .= "</p>\n"; } $out .= '</div>'; } return $out; }
public static function _fill($object, $box) { $section = $box['args']; if (!empty($section['desc'])) { echo wpautop($section['desc']) . PHP_EOL; // xss ok } $on_side = $section['metabox']['context'] == 'side' ? true : false; if ($on_side) { $wraps = array('block' => array('<ul class="kcs-sideform">', '</ul>'), 'row' => array('<li>', '</li>')); } else { $wraps = array('block' => array('<table class="form-table">', '</table>'), 'row' => array('<tr>', '</tr>')); } ?> <?php wp_nonce_field('___kc_meta_box_nonce___', "{$object->post_type}_kc_meta_box_nonce"); ?> <?php echo $wraps['block'][0] . PHP_EOL; ?> <?php foreach ($section['fields'] as $field) { if (!in_array($field['type'], array('checkbox', 'radio', 'multiinput', 'file'))) { $label_for = $field['id']; if ($field['type'] === 'editor') { $label_for = strtolower(str_replace(array('-', '_'), '', $label_for)); } } else { $label_for = ''; } $f_label = _kc_field_label($field['title'], $label_for, !$on_side, false); $f_input = _kc_field(array('mode' => 'post', 'object_id' => $object->ID, 'section' => $section['id'], 'field' => $field)); ?> <?php echo $wraps['row'][0] . PHP_EOL; // xss ok ?> <?php if ($on_side) { ?> <span class="side-label"><?php echo $f_label; // xss ok ?> </span> <?php echo $f_input; // xss ok ?> <?php } else { ?> <?php echo $f_label; // xss ok ?> <td> <?php echo $f_input; // xss ok ?> </td> <?php } ?> <?php echo $wraps['row'][1] . PHP_EOL; // xss ok ?> <?php } ?> <?php echo $wraps['block'][1] . PHP_EOL; // xss ok ?> <?php }
/** * Field: multiinput * * Generate html multiinput fields * * @param $name string Input name attribute * @param $db_value string|array Current value (from database) of this input * @param $type string Pair options type, defaults to multiinput * * @return $output string HTML Pair option row, with the required jQuery script * */ function _kc_field_multiinput($name, $db_value, $field, $show_info = true) { # Sanitize subfields foreach ($field['subfields'] as $idx => $subfield) { # 0. attributes if (!empty($subfield['attr']) && is_array($subfield['attr'])) { unset($subfield['attr']['id']); unset($subfield['attr']['name']); } else { $subfield['attr'] = array(); } $field['subfields'][$idx] = $subfield; } if (!is_array($db_value) || empty($db_value)) { $_temp_value = array(); foreach ($field['subfields'] as $subfield) { $_temp_value[$subfield['id']] = ''; } $db_value = array($_temp_value); } $output = ''; if ($show_info) { $output .= "<p class='info'><em>" . __('Info: Drag & drop to reorder.', 'kc-settings') . "</em></p>\n"; } $output .= "\n\t<ul class='kc-rows kcs-multiinput'>\n"; foreach ($db_value as $row_idx => $row_values) { $output .= "\t\t<li class='row' data-mode='{$field['id']}'>\n"; $output .= "\t\t\t<table class='form-table widefat'>\n"; $output .= "\t\t\t\t<tbody>\n"; # subfields foreach ($field['subfields'] as $subfield) { if ($subfield['type'] == 'multiinput') { continue; } $subfield_args = array('mode' => 'subfield', 'data' => array('db_value' => !empty($row_values[$subfield['id']]) ? $row_values[$subfield['id']] : '', 'name' => "{$name}[{$row_idx}][{$subfield['id']}]", 'id' => "{$field['_id']}-{$row_idx}-{$subfield['id']}"), 'field' => $subfield); $output .= "\t\t\t\t\t<tr>\n"; $output .= "\t\t\t\t\t\t<th><label for='{$field['_id']}-{$row_idx}-{$subfield['id']}'>{$subfield['title']}</label></th>\n"; $output .= "\t\t\t\t\t\t<td>" . _kc_field($subfield_args) . "</td>\n"; $output .= "\t\t\t</tr>\n"; } $output .= "\t\t\t\t</tbody>\n"; $output .= "\t\t\t</table>\n"; # actions $output .= "\t\t\t<p class='actions'>"; $output .= '<a class="add" title="' . __('Add new row', 'kc-settings') . '">' . __('Add', 'kc-settings') . '</a>'; $output .= '<a class="del" title="' . __('Remove this row', 'kc-settings') . '">' . __('Remove', 'kc-settings') . '</a>'; $output .= '<a class="clear" title="' . __('Clear', 'kc-settings') . '">' . __('Clear', 'kc-settings') . '</a>'; $output .= "</p>\n"; $output .= "\t\t</li>\n"; } $output .= "\t</ul>\n"; return $output; }
/** * Generate term meta field HTML. * * @param string|object $args This could be a taxonomy name (string) or a term (object), depending on which screen we're at. * */ public static function _fields($args) { # Where are we? add/edit # a. Edit screen if (is_object($args)) { $edit_mode = true; $taxonomy = $args->taxonomy; $term_id = $args->term_id; $tabled = true; } else { $edit_mode = false; $taxonomy = $args; $term_id = null; $tabled = false; } if (!isset(self::$settings[$taxonomy])) { return $args; } # New term: table. Edit term: div $row_tag = $tabled ? 'tr' : 'div'; $output = ''; foreach (self::$settings[$taxonomy] as $section) { $section_head = "\t\t\t\t<h4>{$section['title']}</h4>\n"; if (isset($section['desc']) && $section['desc']) { $section_head .= "\t\t\t\t" . wpautop($section['desc']) . "\n"; } // xss ok if ($tabled) { $section_head = "<tr class='form-field'>\n\t\t\t<th colspan='2'>\n{$section_head}\t\t\t</th>\n\t\t</tr>\n"; } $output .= $section_head; foreach ($section['fields'] as $field) { $args = array('mode' => 'term', 'section' => $section['id'], 'field' => $field, 'tabled' => $tabled, 'echo' => false); if (isset($term_id)) { $args['object_id'] = $term_id; } if (!in_array($field['type'], array('checkbox', 'radio', 'multiinput', 'file'))) { $label_for = $field['id']; if ($field['type'] === 'editor') { $label_for = strtolower(str_replace(array('-', '_'), '', $label_for)); } } else { $label_for = ''; } $output .= "\t\t<{$row_tag} class='form-field kcs-field'>\n"; $the_label = _kc_field_label($field['title'], $label_for, false, false); # Wrap the field with <tr> if we're in edit mode if ($edit_mode) { $the_label = "\t\t\t<th scope='row'>{$the_label}</th>\n"; } $output .= $the_label; $the_field = "\t\t\t\t" . _kc_field($args) . "\n"; # Wrap the field with <tr> if we're in edit mode if ($edit_mode) { $the_field = "\t\t\t<td>\n{$the_field}\t\t\t</td>\n"; } $output .= $the_field; $output .= "\t\t</{$row_tag}>\n"; } } echo $output; // xss ok }