/** * 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 _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 }
/** * 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 }