Esempio n. 1
0
function getParentCategoryByProperty($id, $prop, $values, $highest = true)
{
    if (!is_array($values)) {
        $values = array($values);
    }
    $val = $id;
    do {
        if ($props = category_custom_fields_get($id)) {
            if (isset($props[$prop]) && !empty($props[$prop]) && in_array($props[$prop], $values)) {
                $val = $id;
                if (!$highest) {
                    break;
                }
            }
        }
        $cat = get_term_by('id', $id, 'category', ARRAY_A);
        $id = $cat['parent'];
    } while ($id);
    return $val;
}
function category_custom_fields_save($term_id = 0)
{
    global $THEMEREX_options;
    // verify nonce
    if (!isset($_POST['meta_box_category_nonce']) || !wp_verify_nonce($_POST['meta_box_category_nonce'], basename(__FILE__))) {
        return $term_id;
    }
    $custom_options = category_custom_fields_get($term_id);
    $need_save = false;
    foreach ($THEMEREX_options as $field) {
        if (!isset($field['override']) || !in_array('category', explode(',', $field['override']))) {
            continue;
        }
        if (!isset($field['std'])) {
            continue;
        }
        $id = $field['id'];
        if (!isset($_POST[$id . '_inherit'])) {
            continue;
        }
        $need_save = true;
        if (is_inherit_option($_POST[$id . '_inherit'])) {
            $new = '';
        } else {
            if (isset($_POST[$id])) {
                if ($field['type'] == 'socials') {
                    if (!empty($field['cloneable'])) {
                        foreach ($_POST[$id] as $k => $v) {
                            $_POST[$id][$k] = array('url' => stripslashes($v), 'icon' => stripslashes($_POST[$id . '_icon'][$k]));
                        }
                    } else {
                        $_POST[$id] = array('url' => stripslashes($_POST[$id]), 'icon' => stripslashes($_POST[$id . '_icon']));
                    }
                } else {
                    if (is_array($_POST[$id])) {
                        foreach ($_POST[$id] as $k => $v) {
                            $_POST[$id][$k] = stripslashes($v);
                        }
                    } else {
                        $_POST[$id] = stripslashes($_POST[$id]);
                    }
                }
                // Add cloneable index
                if (!empty($field['cloneable'])) {
                    $rez = array();
                    foreach ($_POST[$id] as $k => $v) {
                        $rez[$_POST[$id . '_numbers'][$k]] = $v;
                    }
                    $_POST[$id] = $rez;
                }
                $new = $_POST[$id];
            } else {
                $new = $field['type'] == 'checkbox' ? 'false' : '';
            }
        }
        $custom_options[$id] = $new ? $new : 'inherit';
    }
    if ($need_save) {
        category_custom_fields_set($term_id, $custom_options);
    }
}
Esempio n. 3
0
function category_custom_fields_save($term_id = 0)
{
    global $THEMEREX_theme_options;
    $term_meta = category_custom_fields_get($term_id);
    $need_save = false;
    foreach ($THEMEREX_theme_options as $option) {
        if (!isset($option['override']) || !in_array('category', explode(',', $option['override']))) {
            continue;
        }
        if (!isset($option['id'])) {
            continue;
        }
        $id = get_option_name($option['id']);
        if (!isset($_POST[$id])) {
            continue;
        }
        $need_save = true;
        $multiple = isset($option['multiple']) && $option['multiple'];
        if ($multiple && is_array($_POST[$id])) {
            sort($_POST[$id]);
        }
        $inc = isset($option['increment']) && $option['increment'] || $option['type'] == 'socials';
        if ($inc && is_array($_POST[$id])) {
            foreach ($_POST[$id] as $k => $v) {
                $_POST[$id][$k] .= '|' . $_POST[$id . '_numbers'][$k] . ($option['type'] == 'socials' ? '|' . $_POST[$id . '_icons'][$k] : '');
            }
        }
        $new = isset($_POST[$id]) ? ($multiple || $inc) && is_array($_POST[$id]) ? implode(',', $_POST[$id]) : stripslashes($_POST[$id]) : ($option['type'] == 'checkbox' ? 'false' : '');
        if (isset($option['enable'])) {
            $new = $new . '|' . (isset($_POST[$id . '_enable']) ? 1 : 0);
        }
        $term_meta[$id] = $new ? $new : 'default';
    }
    //save the option array
    if ($need_save) {
        category_custom_fields_set($term_id, $term_meta);
    }
}
Esempio n. 4
0
function category_custom_fields_save($term_id = 0)
{
    global $THEMEREX_options;
    // verify nonce
    if (!isset($_POST['meta_box_category_nonce']) || !wp_verify_nonce($_POST['meta_box_category_nonce'], basename(__FILE__))) {
        return $term_id;
    }
    $custom_options = category_custom_fields_get($term_id);
    if (themerex_options_merge_new_values($THEMEREX_options, $custom_options, $_POST, 'save', 'category')) {
        category_custom_fields_set($term_id, $custom_options);
    }
}