Пример #1
0
function metaField($field, $options = array())
{
    wp_enqueue_style('osteo-meta-styles', plugins_url('osteo-meta-fields/css/osteo-meta-styles.css'));
    wp_enqueue_style('osteo-meta-icons', plugins_url('osteo-meta-fields/icons/style.css'));
    wp_enqueue_script('osteo-general-field-scripts', plugins_url('osteo-meta-fields/js/osteo-meta-field-scripts.js'), array(), '20120206', true);
    $defaultOptions = array('title' => null, 'description' => null, 'type' => 'input', 'class' => null, 'options' => null, 'required' => false, 'data' => 'post_meta', 'args' => false, 'secondary_type' => null, 'style' => false, 'taxonomy' => false, 'value' => null, 'meta-items' => null);
    $options = array_merge($defaultOptions, $options);
    // get the value of the field and set it
    if (isset($options['value'])) {
        // weird... probably shouldn't be set yet
    } else {
        // check if we should get_meta or get_option
        if ($options['data'] == 'post_meta') {
            /* Removed because we don't need it to be an array of arrays, we just need a single array of choices
                   if($options['type'] == 'checkbox') {
                       $array_or_string = false; // give us that array
                   } else {
                       $array_or_string = true; // let's get a string instead of an array
                   }
                   $options['value'] = get_post_meta(get_the_ID(), $field, $array_or_string);
               */
            $options['value'] = get_post_meta(get_the_ID(), $field, true);
        } elseif ($options['data'] == 'option') {
            // use get_option
            $options['value'] = get_option($field);
        }
    }
    if (isset($options['title'])) {
        echo '<p class="meta-title"><strong>' . $options["title"] . '</strong>' . ($options["required"] == true ? '<span style="color: red;">*</span>' : '') . (!empty($options["description"]) ? ' ' . $options["description"] : '') . '</p>';
    }
    whichField($field, $options);
}
Пример #2
0
function metaTerm($term, $fields = array())
{
    // getting passed the $term object and we're analyzing it to see what to do with it
    // since no term_id ever repeats, we're storing everything in the
    // wp_options table as "term_$term_id" as an array of all fields, like meta-items.php
    if (isset($term->term_id)) {
        // this means that we're editing a term, not creating a new one
        $term_id = $term->term_id;
        $term_value = get_option('term_' . $term_id);
    } else {
        // there's no value
        $term_value = null;
        $term_id = null;
    }
    $term_field = 'term_' . $term_id;
    foreach ($fields as $field) {
        // use plain ol 'term_meta' for the array name. We'll change it to 'term_'.$term_id when we save it
        $fieldName = 'term_meta[' . $field["dataname"] . ']';
        // pass on the value, if any
        if (isset($term_value[$field["dataname"]])) {
            $fieldValue = $term_value[$field["dataname"]];
        } else {
            $fieldValue = null;
        }
        isset($field['title']) ? $termTitle = $field['title'] : ($termTitle = NULL);
        isset($field['description']) ? $termDescription = $field['description'] : ($termDescription = NULL);
        isset($field['type']) ? $fieldType = $field['type'] : ($fieldType = 'input');
        isset($field['options']) ? $termOpts = $field['options'] : ($termOpts = NULL);
        // for passing on featured image value if we're on images
        if ($fieldType == 'images' && isset($term_value[$field["dataname"] . 'FeaturedIMG'])) {
            $featuredImgVal = $term_value[$field["dataname"] . 'FeaturedIMG'];
        } else {
            $featuredImgVal = null;
        }
        // for passing on if we're on a single image
        if ($fieldType == 'images' && isset($field['single-image'])) {
            $singleImage = $field['single-image'];
        } else {
            $singleImage = null;
        }
        // clear the array
        $termOptions = '';
        // set-up new options to pass on to meta-fields.php
        $termOptions = array('title' => $termTitle, 'description' => $termDescription, 'type' => $fieldType, 'dataname' => $field["dataname"], 'value' => $fieldValue, 'options' => $termOpts, 'is_term' => true, 'featured_value' => $featuredImgVal, 'single-image' => $singleImage);
        // create and edit have different formatting, so we're giving them
        // the right html so it formats correctly
        $request_link = "{$_SERVER['REQUEST_URI']}";
        if (strpos($request_link, 'action=edit') !== false) {
            $div_or_tr = 'tr';
        } else {
            $div_or_tr = 'div';
        }
        ?>

        <<?php 
        echo $div_or_tr;
        ?>
 class="form-field">
            <th scope="row" valign="top">
                <?php 
        echo !empty($termTitle) ? '<label for="' . $field["dataname"] . '">' . $termTitle . '</label>' : '';
        ?>
            </th>
            <td>
                <?php 
        whichField($fieldName, $termOptions);
        echo !empty($termDescription) ? '<span class="description">' . $termDescription . '</span>' : '';
        ?>
            </td>
        </<?php 
        echo $div_or_tr;
        ?>
>
        <?php 
    }
}