Пример #1
0
function sb_slideshow_save($post_id)
{
    global $sb_slideshow_interface;
    if (!isset($_POST['sb_noncename']) || !wp_verify_nonce($_POST['sb_noncename'], plugin_basename(__FILE__)) || defined('DOING_AUTOSAVE') && DOING_AUTOSAVE || 'page' == $_POST['post_type'] && !(current_user_can('edit_page', $post_id) || current_user_can('edit_post', $post_id)) || !sb_verify_post_type('slideshow')) {
        return $post_id;
    }
    // verify post type
    delete_post_meta($post_id, 'slide');
    // flush all post meta entries with "slide" as their key
    // initialize default min and max image sizes
    $image_size = array('min' => array('width' => 1000, 'height' => 1000), 'max' => array('width' => 100, 'height' => 100));
    foreach ($_POST['slide'] as $slide) {
        // update attachment details for any slide
        wp_update_post(array('ID' => $slide['attachment_id'], 'post_excerpt' => apply_filters('sb_pre_link_url', $slide['post_excerpt'] != $sb_slideshow_interface['link_text'] ? $slide['post_excerpt'] : ''), 'post_content' => apply_filters('sb_link_description', $slide['post_content'])));
        if ($slide['box'] == 'library') {
            continue;
        }
        // stop here if slide is from library
        // create a post meta record with key "slide" to hold this slide's details
        add_post_meta($post_id, 'slide', array('attachment_id' => $slide['attachment_id'], 'order' => $slide['order']));
        // from here on is just doing some checks to figure out the max and min image heights and widths
        $image = wp_get_attachment_image_src($slide['attachment_id'], 'full');
        // min
        if ($image[1] < $image_size['min']['width']) {
            $image_size['min']['width'] = $image[1];
        }
        if ($image[2] < $image_size['min']['height']) {
            $image_size['min']['height'] = $image[2];
        }
        // max
        if ($image[1] > $image_size['max']['width']) {
            $image_size['max']['width'] = $image[1];
        }
        if ($image[2] > $image_size['max']['height']) {
            $image_size['max']['height'] = $image[2];
        }
    }
    // update post meta records for all of the options
    update_post_meta($post_id, 'ssorri', $_POST['sb_ssorri']);
    update_post_meta($post_id, 'effect', $_POST['sb_effect']);
    update_post_meta($post_id, 'control', $_POST['sb_control']);
    update_post_meta($post_id, 'pause', is_numeric($_POST['sb_pause']) ? $_POST['sb_pause'] : $sb_slideshow_interface['pause']);
    update_post_meta($post_id, 'opacity', is_numeric($_POST['sb_opacity']) ? $_POST['sb_opacity'] : $sb_slideshow_interface['opacity']);
    update_post_meta($post_id, 'size', $_POST['sb_size']);
    $size_custom = $_POST['sb_size_custom'];
    if ($size_custom['width'] == '') {
        $size_custom['width'] = $image_size['min']['width'];
    }
    if ($size_custom['height'] == '') {
        $size_custom['height'] = $image_size['min']['height'];
    }
    update_post_meta($post_id, 'size_custom', $size_custom);
    update_post_meta($post_id, 'size_min', $image_size['min']);
    update_post_meta($post_id, 'size_max', $image_size['max']);
    return $post_id;
}
Пример #2
0
/**
 * Save all the post data
 *
 * @since StartBox 2.5
 */
function sb_sidebars_save($post_id)
{
    // Verify we should actually be saving any data
    if (!sb_verify_post_type('sidebar') || defined('DOING_AUTOSAVE') && DOING_AUTOSAVE || !isset($_POST['sidebar_replaced']) || !current_user_can('edit_theme_options')) {
        return $post_id;
    }
    // skip the rest...
    // update post meta for the sidebar we're replacing
    update_post_meta($post_id, '_sidebar_replaced', $_POST['sidebar_replaced']);
    // update post meta for the sidebar we're replacing
    update_post_meta($post_id, '_sidebar_description', $_POST['description']);
    // save checked status for all post types
    delete_post_meta($post_id, '_post');
    if ($_POST['post']) {
        foreach ($_POST['post'] as $post => $value) {
            $data = (array) maybe_unserialize(get_post_meta($post_id, '_post', true));
            if (count($data) != 0) {
                if (!in_array($post, $data)) {
                    $data[] = $post;
                }
                $data = array_unique($data);
                // remove duplicates
                sort($data);
                // sort array
                $data = serialize($data);
                update_post_meta($post_id, '_post', $data);
            } else {
                $data = array();
                $data[0] = $post;
                $data = serialize($data);
                update_post_meta($post_id, '_post', $data);
            }
        }
    }
    // save checked status for all taxonomies
    delete_post_meta($post_id, '_tax');
    if ($_POST['tax']) {
        foreach ($_POST['tax'] as $tax => $value) {
            $data = (array) maybe_unserialize(get_post_meta($post_id, '_tax', true));
            if (count($data) != 0) {
                if (!in_array($tax, $data)) {
                    $data[] = $tax;
                }
                $data = array_unique($data);
                // remove duplicates
                sort($data);
                // sort array
                $data = serialize($data);
                update_post_meta($post_id, '_tax', $data);
            } else {
                $data = array();
                $data[0] = $tax;
                $data = serialize($data);
                update_post_meta($post_id, '_tax', $data);
            }
        }
    }
    // Delete transient data (used to cache all sidebars for front-end display)
    delete_transient('sb_sidebars_post_type');
    delete_transient('sb_sidebars_tax');
    return $post_id;
}