Пример #1
0
/**
 * Functions for create form elements
 *
 * @package DP API
 * @subpackage Admin
 */
function dp_form_fields($fields = '', $args = '')
{
    $defaults = array('before_container' => '<table class="form-table"><tbody>', 'after_container' => '</tbody></table>', 'before_row' => '<tr>', 'after_row' => '</td></tr>', 'before_title' => '<th scope="row">', 'after_title' => '</th><td>', 'callback' => '');
    $args = wp_parse_args($args, $defaults);
    echo $args['before_container'];
    foreach ($fields as $field) {
        if (!is_array($field)) {
            continue;
        }
        $type = !empty($field['type']) ? $field['type'] : '';
        $name = !empty($field['name']) ? $field['name'] : '';
        $types = array('text', 'password', 'upload', 'image_id', 'color', 'textarea', 'radio', 'select', 'multiselect', 'checkbox', 'checkboxes', 'custom');
        if (!empty($field['callback']) && is_callable($field['callback'])) {
            echo call_user_func($field['callback'], $field);
        } elseif ($type == 'description' && !empty($field['value'])) {
            echo '<tr><td colspan="2"><div class="description">' . $field['value'] . '</div></td></tr>';
        } elseif ($type == 'fields') {
            $defaults = array('before_container' => '', 'after_container' => '', 'before_row' => '', 'after_row' => '', 'before_title' => '', 'after_title' => '', 'callback' => '');
            echo '<tr><th>' . $field['title'] . '</th><td>';
            dp_form_fields($field['fields'], wp_parse_args($field['args'], $defaults));
            echo '</td></tr>';
        } elseif (!empty($type)) {
            if (!empty($args['callback']) && is_callable($args['callback'])) {
                $field = call_user_func($args['callback'], $field);
            }
            $field = wp_parse_args($field, $args);
            dp_form_row($field);
        }
    }
    echo $args['after_container'];
}
Пример #2
0
 function meta_box($user)
 {
     if ($this->title) {
         echo '<h3>' . $this->title . '</h3>';
     }
     $defaults = $this->fields();
     if (empty($defaults) || !is_array($defaults)) {
         return;
     }
     $new_fields = dp_instance_fields($defaults, 'user_meta', $user);
     wp_nonce_field($this->nonce_action, $this->nonce);
     echo dp_form_fields($new_fields);
 }