Пример #1
0
function grve_portfolio_options_save_postdata($post_id, $post)
{
    global $grve_portfolio_options;
    if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {
        return;
    }
    if (!isset($_POST['grve_portfolio_save_nonce']) || !wp_verify_nonce($_POST['grve_portfolio_save_nonce'], 'grve_nonce_save')) {
        return;
    }
    // Check permissions
    if ('portfolio' == $_POST['post_type']) {
        if (!current_user_can('edit_page', $post_id)) {
            return;
        }
    }
    foreach ($grve_portfolio_options as $value) {
        $new_meta_value = isset($_POST[$value['id']]) ? $_POST[$value['id']] : '';
        $meta_key = $value['id'];
        $meta_value = get_post_meta($post_id, $meta_key, true);
        if ($new_meta_value && '' == $meta_value) {
            add_post_meta($post_id, $meta_key, $new_meta_value, true);
        } elseif ($new_meta_value && $new_meta_value != $meta_value) {
            update_post_meta($post_id, $meta_key, $new_meta_value);
        } elseif ('' == $new_meta_value && $meta_value) {
            delete_post_meta($post_id, $meta_key, $meta_value);
        }
    }
    if (isset($_POST['grve_portfolio_media_save_nonce']) && wp_verify_nonce($_POST['grve_portfolio_media_save_nonce'], 'grve_nonce_save')) {
        //Media Slider Items
        $media_slider_items = array();
        if (isset($_POST['grve_media_slider_item_id'])) {
            $num_of_images = sizeof($_POST['grve_media_slider_item_id']);
            for ($i = 0; $i < $num_of_images; $i++) {
                $this_image = array('id' => $_POST['grve_media_slider_item_id'][$i]);
                array_push($media_slider_items, $this_image);
            }
        }
        if (empty($media_slider_items)) {
            delete_post_meta($post->ID, 'grve_portfolio_slider_items');
            delete_post_meta($post->ID, 'grve_portfolio_slider_settings');
        } else {
            update_post_meta($post->ID, 'grve_portfolio_slider_items', $media_slider_items);
            $media_slider_speed = 3500;
            $media_slider_direction_nav = 'yes';
            if (isset($_POST['grve_portfolio_slider_settings_speed'])) {
                $media_slider_speed = $_POST['grve_portfolio_slider_settings_speed'];
            }
            if (isset($_POST['grve_portfolio_slider_settings_direction_nav'])) {
                $media_slider_direction_nav = $_POST['grve_portfolio_slider_settings_direction_nav'];
            }
            $media_slider_settings = array('slideshow_speed' => $media_slider_speed, 'direction_nav' => $media_slider_direction_nav);
            update_post_meta($post->ID, 'grve_portfolio_slider_settings', $media_slider_settings);
        }
    }
    if (isset($_POST['grve_portfolio_feature_save_nonce']) && wp_verify_nonce($_POST['grve_portfolio_feature_save_nonce'], 'grve_nonce_save')) {
        grve_admin_save_feature_section($post_id);
    }
}
Пример #2
0
function grve_page_options_save_postdata($post_id, $post)
{
    global $grve_page_options;
    if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {
        return;
    }
    if (!isset($_POST['grve_page_save_nonce']) || !wp_verify_nonce($_POST['grve_page_save_nonce'], 'grve_nonce_save')) {
        return;
    }
    // Check permissions
    if ('page' == $_POST['post_type']) {
        if (!current_user_can('edit_page', $post_id)) {
            return;
        }
    }
    foreach ($grve_page_options as $value) {
        $new_meta_value = isset($_POST[$value['id']]) ? $_POST[$value['id']] : '';
        $meta_key = $value['id'];
        $meta_value = get_post_meta($post_id, $meta_key, true);
        if ($new_meta_value && '' == $meta_value) {
            add_post_meta($post_id, $meta_key, $new_meta_value, true);
        } elseif ($new_meta_value && $new_meta_value != $meta_value) {
            update_post_meta($post_id, $meta_key, $new_meta_value);
        } elseif ('' == $new_meta_value && $meta_value) {
            delete_post_meta($post_id, $meta_key, $meta_value);
        }
    }
    if (isset($_POST['grve_page_feature_save_nonce']) && wp_verify_nonce($_POST['grve_page_feature_save_nonce'], 'grve_nonce_save')) {
        grve_admin_save_feature_section($post_id);
    }
}