Beispiel #1
0
 function themerex_callback_reviews_users_accept()
 {
     global $_REQUEST;
     if (!wp_verify_nonce($_REQUEST['nonce'], 'ajax_nonce')) {
         die;
     }
     $response = array('error' => '');
     $post_id = $_REQUEST['post_id'];
     if ($post_id > 0) {
         $marks = $_REQUEST['marks'];
         $users = $_REQUEST['users'];
         $avg = getReviewsRatingAverage($marks);
         update_post_meta($post_id, 'reviews_marks2', marksToSave($marks));
         update_post_meta($post_id, 'reviews_avg2', marksToSave($avg));
         update_post_meta($post_id, 'reviews_users', $users);
     } else {
         $response['error'] = __('Bad post ID', 'themerex');
     }
     echo json_encode($response);
     die;
 }
function themerex_options_merge_new_values(&$post_options, &$custom_options, &$post_data, $mode, $override)
{
    $need_save = false;
    foreach ($post_options as $field) {
        if ($override != 'general' && (!isset($field['override']) || !in_array($override, explode(',', $field['override'])))) {
            continue;
        }
        if (!isset($field['std'])) {
            continue;
        }
        $id = $field['id'];
        if ($override != 'general' && !isset($post_data[$id . '_inherit'])) {
            continue;
        }
        if ($id == 'reviews_marks' && $mode == 'export') {
            continue;
        }
        $need_save = true;
        if ($mode == 'save' || $mode == 'export') {
            if ($override != 'general' && is_inherit_option($post_data[$id . '_inherit'])) {
                $new = '';
            } else {
                if (isset($post_data[$id])) {
                    // Prepare specific (combined) fields
                    if (!empty($field['subset'])) {
                        $sbs = $post_data[$field['subset']];
                        $field['val'][$sbs] = $post_data[$id];
                        $post_data[$id] = $field['val'];
                    }
                    if ($field['type'] == 'socials') {
                        if (!empty($field['cloneable'])) {
                            foreach ($post_data[$id] as $k => $v) {
                                $post_data[$id][$k] = array('url' => stripslashes($v), 'icon' => stripslashes($post_data[$id . '_icon'][$k]));
                            }
                        } else {
                            $post_data[$id] = array('url' => stripslashes($post_data[$id]), 'icon' => stripslashes($post_data[$id . '_icon']));
                        }
                    } else {
                        if (is_array($post_data[$id])) {
                            foreach ($post_data[$id] as $k => $v) {
                                $post_data[$id][$k] = stripslashes($v);
                            }
                        } else {
                            $post_data[$id] = stripslashes($post_data[$id]);
                        }
                    }
                    // Add cloneable index
                    if (!empty($field['cloneable'])) {
                        $rez = array();
                        foreach ($post_data[$id] as $k => $v) {
                            $rez[$post_data[$id . '_numbers'][$k]] = $v;
                        }
                        $post_data[$id] = $rez;
                    }
                    $new = $post_data[$id];
                    // Post type specific data handling
                    if ($id == 'reviews_marks') {
                        $new = join(',', $new);
                        if (($avg = getReviewsRatingAverage($new)) > 0) {
                            $new = marksToSave($new);
                        }
                    }
                } else {
                    $new = $field['type'] == 'checkbox' ? 'false' : '';
                }
            }
        } else {
            $new = $field['std'];
        }
        $custom_options[$id] = $new || $override == 'general' ? $new : 'inherit';
    }
    return $need_save;
}
Beispiel #3
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']);
    $need_save = false;
    foreach ($post_options as $field) {
        if (!isset($field['override']) || !in_array('post', 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];
                if ($id == 'reviews_marks') {
                    $new = join(',', $new);
                    if (($avg = getReviewsRatingAverage($new)) > 0) {
                        $new = marksToSave($new);
                        update_post_meta($post_id, 'reviews_avg', marksToSave($avg));
                    }
                }
            } else {
                $new = $field['type'] == 'checkbox' ? 'false' : '';
            }
        }
        $custom_options[$id] = $new ? $new : 'inherit';
    }
    if ($need_save) {
        update_post_meta($post_id, 'post_custom_options', $custom_options);
    }
}
Beispiel #4
0
function save_meta_box_post($post_id)
{
    global $THEMEREX_meta_box_post, $THEMEREX_theme_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();
    $need_save = false;
    foreach ($THEMEREX_meta_box_post['fields'] as $field) {
        if (!isset($field['id'])) {
            continue;
        }
        if (!isset($_POST[$field['id']])) {
            continue;
        }
        $need_save = true;
        $new = isset($_POST[$field['id']]) ? is_array($_POST[$field['id']]) ? join(',', $_POST[$field['id']]) : $_POST[$field['id']] : '';
        $custom_options[$field['id']] = $new ? $new : 'default';
        if ($field['id'] == 'reviews_marks' && ($avg = getReviewsRatingAverage($new)) > 0) {
            $custom_options[$field['id']] = marksToSave($custom_options[$field['id']]);
            update_post_meta($post_id, 'reviews_avg', marksToSave($avg));
        }
    }
    foreach ($THEMEREX_theme_options as $option) {
        if (!isset($option['override']) || !in_array('post', explode(',', $option['override']))) {
            continue;
        }
        if (!isset($option['id'])) {
            continue;
        }
        $id = get_option_name($option['id']);
        if (!isset($_POST[$id])) {
            continue;
        }
        $need_save = true;
        $new = isset($_POST[$id]) ? $_POST[$id] : '';
        $custom_options[$id] = $new ? $new : 'default';
    }
    if ($need_save) {
        update_post_meta($post_id, 'post_custom_options', $custom_options);
    }
}