コード例 #1
0
ファイル: import.php プロジェクト: emtii/paula.wp
function compare_import_image($image_url, $product_id)
{
    if (!empty($image_url)) {
        $basename = basename($image_url);
        $image_id = compare_if_image_exists($basename);
        if (!$image_id) {
            $tmp = download_url((string) $image_url);
            compare_display_import_info(__('Downloading image: ', 'compare') . $basename);
            $file_array = array();
            preg_match('/[^\\?]+\\.(jpg|jpe|jpeg|gif|png)/i', $image_url, $matches);
            $file_array['name'] = basename($matches[0]);
            $file_array['tmp_name'] = $tmp;
            // If error storing temporarily, unlink
            if (is_wp_error($tmp)) {
                @unlink($file_array['tmp_name']);
                compare_display_import_info($tmp->get_error_message());
                $file_array['tmp_name'] = '';
                $image_id = '';
            }
            // do the validation and storage stuff
            $id = media_handle_sideload($file_array, 0);
            // If error storing permanently, unlink
            if (is_wp_error($id)) {
                compare_display_import_info($id->get_error_message());
                @unlink($file_array['tmp_name']);
                $image_id = '';
            }
            $image_id = $id;
        } else {
            compare_display_import_info(__('Image ', 'compare') . $basename . __(' exists, skipping import and using existing one.', 'compare'));
        }
        if (!empty($image_id)) {
            set_post_thumbnail($product_id, $image_id);
        }
    }
}
コード例 #2
0
ファイル: functions.php プロジェクト: emtii/paula.wp
function compare_import_store_logo($image_url)
{
    if (empty($image_url)) {
        return '';
    }
    $basename = basename($image_url);
    $image_id = compare_if_image_exists($basename);
    $tmp = download_url((string) $image_url);
    $file_array = array();
    preg_match('/[^\\?]+\\.(jpg|jpe|jpeg|gif|png)/i', $image_url, $matches);
    if (empty($matches[0])) {
        return '';
    }
    $file_array['name'] = basename($matches[0]);
    $file_array['tmp_name'] = $tmp;
    // If error storing temporarily, unlink
    if (is_wp_error($tmp)) {
        @unlink($file_array['tmp_name']);
        $file_array['tmp_name'] = '';
        return '';
    }
    // do the validation and storage stuff
    $id = media_handle_sideload($file_array, 0);
    // If error storing permanently, unlink
    if (is_wp_error($id)) {
        @unlink($file_array['tmp_name']);
        return '';
    }
    return $id;
}