コード例 #1
0
function foxyshop_product_images_setup()
{
    global $post, $foxyshop_settings;
    $upload_dir = wp_upload_dir();
    if (array_key_exists('error', $upload_dir)) {
        if ($upload_dir['error'] != '') {
            echo '<p style="color: red;"><strong>Warning:</strong> Images cannot be uploaded at this time. The error given is below.<br />Please attempt to correct the error and reload this page.</p>';
            echo '<p>' . $upload_dir['error'] . '</p>';
            return;
        }
    }
    echo '<script type="text/javascript" src="' . FOXYSHOP_DIR . '/js/dropzone.js"></script>' . "\n";
    echo '<link rel="stylesheet" href="' . FOXYSHOP_DIR . '/css/dropzone.css" type="text/css" media="screen" />' . "\n";
    echo '<div id="foxyshop_new_product_image_container" class="dropzone"></div>' . "\n";
    echo '<input type="hidden" id="foxyshop_sortable_value" name="foxyshop_sortable_value" />' . "\n";
    echo '<ul id="foxyshop_product_image_list">' . foxyshop_redraw_images($post->ID) . '</ul>' . "\n";
    echo '<div style="clear: both;"></div>';
}
コード例 #2
0
function foxyshop_product_ajax()
{
    global $wpdb;
    $productID = isset($_POST['foxyshop_product_id']) ? (int) $_POST['foxyshop_product_id'] : 0;
    $imageID = isset($_POST['foxyshop_image_id']) ? (int) $_POST['foxyshop_image_id'] : 0;
    check_ajax_referer('foxyshop-product-image-functions-' . $productID, 'security');
    if (!isset($_POST['foxyshop_action'])) {
        die;
    }
    if ($_POST['foxyshop_action'] == "add_new_image") {
        echo foxyshop_redraw_images($productID);
    } elseif ($_POST['foxyshop_action'] == "delete_image") {
        wp_delete_attachment($imageID);
        echo foxyshop_redraw_images($productID);
    } elseif ($_POST['foxyshop_action'] == "featured_image") {
        delete_post_meta($productID, "_thumbnail_id");
        update_post_meta($productID, "_thumbnail_id", $imageID);
        echo foxyshop_redraw_images($productID);
    } elseif ($_POST['foxyshop_action'] == "toggle_visible") {
        if (get_post_meta($imageID, "_foxyshop_hide_image", 1)) {
            delete_post_meta($imageID, "_foxyshop_hide_image");
        } else {
            add_post_meta($imageID, "_foxyshop_hide_image", 1);
        }
        echo foxyshop_redraw_images($productID);
    } elseif ($_POST['foxyshop_action'] == "rename_image") {
        $update_post = array();
        $update_post['ID'] = $imageID;
        $update_post['post_title'] = $_POST['foxyshop_new_name'];
        wp_update_post($update_post);
    } elseif ($_POST['foxyshop_action'] == "update_image_order") {
        $foxyshop_order_array = $_POST['foxyshop_order_array'];
        $IDs = explode(",", $foxyshop_order_array);
        $result = count($IDs);
        for ($i = 0; $i < $result; $i++) {
            $update_post = array();
            $update_post['ID'] = str_replace("att_", "", $IDs[$i]);
            $update_post['menu_order'] = $i + 1;
            wp_update_post($update_post);
        }
        echo foxyshop_redraw_images($productID);
    } elseif ($_POST['foxyshop_action'] == "refresh_images") {
        echo foxyshop_redraw_images($productID);
    }
    die;
}