Пример #1
0
function themerex_save_data_page($post_id)
{
    global $THEMEREX_meta_box_page, $THEMEREX_options;
    // check autosave
    if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {
        return $post_id;
    }
    // verify nonce
    if (!isset($_POST['meta_box_page_nonce']) || !wp_verify_nonce($_POST['meta_box_page_nonce'], basename(__FILE__))) {
        return $post_id;
    }
    // check permissions
    if ('page' == $_POST['post_type']) {
        if (!current_user_can('edit_page', $post_id)) {
            return $post_id;
        }
    } elseif (!current_user_can('edit_post', $post_id)) {
        return $post_id;
    }
    $custom_options = array();
    $page_options = array_merge($THEMEREX_options, $THEMEREX_meta_box_page['fields']);
    if (themerex_options_merge_new_values($page_options, $custom_options, $_POST, 'save', 'page')) {
        update_post_meta($post_id, 'post_custom_options', $custom_options);
    }
}
Пример #2
0
function save_meta_box_post($post_id)
{
    global $THEMEREX_meta_box_post, $THEMEREX_options;
    // verify nonce
    if (!isset($_POST['meta_box_post_nonce']) || !wp_verify_nonce($_POST['meta_box_post_nonce'], basename(__FILE__))) {
        return $post_id;
    }
    // check autosave
    if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {
        return $post_id;
    }
    // check permissions
    if ('page' == $_POST['post_type']) {
        if (!current_user_can('edit_page', $post_id)) {
            return $post_id;
        }
    } else {
        if (!current_user_can('edit_post', $post_id)) {
            return $post_id;
        }
    }
    $custom_options = array();
    $post_options = array_merge($THEMEREX_options, $THEMEREX_meta_box_post['fields']);
    if (themerex_options_merge_new_values($post_options, $custom_options, $_POST, 'save', 'post')) {
        update_post_meta($post_id, 'post_custom_options', $custom_options);
        // Post type specific data handling
        foreach ($post_options as $field) {
            if (isset($field['id']) && $field['id'] == 'reviews_marks') {
                if (($avg = getReviewsRatingAverage($custom_options[$field['id']])) > 0) {
                    update_post_meta($post_id, 'reviews_avg', $avg);
                }
                break;
            }
        }
    }
}
Пример #3
0
function themerex_options_save()
{
    global $THEMEREX_options;
    if (!wp_verify_nonce($_POST['nonce'], 'ajax_nonce')) {
        die;
    }
    $mode = $_POST['mode'];
    $override = $_POST['override'] == '' ? 'general' : $_POST['override'];
    $options = $THEMEREX_options;
    if ($mode == 'save') {
        parse_str($_POST['data'], $post_data);
    } else {
        if ($mode == 'export') {
            parse_str($_POST['data'], $post_data);
            if ($override == 'post') {
                global $THEMEREX_meta_box_post;
                $options = array_merge($THEMEREX_options, $THEMEREX_meta_box_post['fields']);
            } else {
                if ($override == 'page') {
                    global $THEMEREX_meta_box_page;
                    $options = array_merge($THEMEREX_options, $THEMEREX_meta_box_page['fields']);
                }
            }
        } else {
            $post_data = array();
        }
    }
    $custom_options = array();
    themerex_options_merge_new_values($options, $custom_options, $post_data, $mode, $override);
    if ($mode == 'export') {
        $name = trim(chop($_POST['name']));
        $name2 = isset($_POST['name2']) ? trim(chop($_POST['name2'])) : '';
        $key = $name == '' ? $name2 : $name;
        $export = get_option('themerex_options_' . $override, array());
        $export[$key] = $custom_options;
        if ($name != '' && $name2 != '') {
            unset($export[$name2]);
        }
        update_option('themerex_options_' . $override, $export);
        if (is_dir(get_stylesheet_directory() . '/admin/export')) {
            $file = get_stylesheet_directory() . '/admin/export/theme-options.txt';
            $url = get_stylesheet_directory_uri() . '/admin/export/theme-options.txt';
        } else {
            $file = get_template_directory() . '/admin/export/theme-options.txt';
            $url = get_template_directory_uri() . '/admin/export/theme-options.txt';
        }
        $export = serialize($custom_options);
        themerex_fpc($file, $export);
        $response = array('error' => '', 'data' => $export, 'link' => $url);
        echo json_encode($response);
    } else {
        update_option('themerex_options', $custom_options);
    }
    die;
}
Пример #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);
    }
}