Plugin Directory

Changeset 3448007


Ignore:
Timestamp:
01/27/2026 03:44:04 PM (2 months ago)
Author:
eugenezolo
Message:

Release version 1.0.4 - Improved image downloading reliability and error handling

Location:
outrank
Files:
19 added
4 edited

Legend:

Unmodified
Added
Removed
  • outrank/trunk/includes/image-functions.php

    r3337904 r3448007  
    55    if (empty($image_url)) return false;
    66
    7     $filename = basename($image_url);
    8     $image_data = file_get_contents($image_url);
     7    $filename = basename(wp_parse_url($image_url, PHP_URL_PATH));
     8    if (empty($filename)) {
     9        $filename = 'image-' . time() . '.jpg';
     10    }
     11
     12    // Try file_get_contents first
     13    $image_data = @file_get_contents($image_url);
     14
     15    // Fallback to wp_remote_get if file_get_contents fails
     16    if (!$image_data) {
     17        $response = wp_remote_get($image_url, [
     18            'timeout' => 30,
     19            'sslverify' => false,
     20        ]);
     21
     22        if (!is_wp_error($response) && wp_remote_retrieve_response_code($response) === 200) {
     23            $image_data = wp_remote_retrieve_body($response);
     24        }
     25    }
     26
    927    if (!$image_data) return false;
    1028
    1129    $upload_dir = wp_upload_dir();
     30    $filename = wp_unique_filename($upload_dir['path'], $filename);
    1231    $filepath = $upload_dir['path'] . '/' . $filename;
    13     file_put_contents($filepath, $image_data);
     32
     33    if (!file_put_contents($filepath, $image_data)) return false;
    1434
    1535    $filetype = wp_check_filetype($filename, null);
     36    $mime_type = $filetype['type'] ?: 'image/jpeg';
    1637
    1738    $attachment = [
    18         'post_mime_type' => $filetype['type'],
    19         'post_title'     => sanitize_file_name($filename),
     39        'post_mime_type' => $mime_type,
     40        'post_title'     => sanitize_file_name(pathinfo($filename, PATHINFO_FILENAME)),
    2041        'post_content'   => '',
    2142        'post_status'    => 'inherit',
     
    2344
    2445    $attach_id = wp_insert_attachment($attachment, $filepath, $post_id);
     46    if (is_wp_error($attach_id) || !$attach_id) return false;
     47
    2548    require_once ABSPATH . 'wp-admin/includes/image.php';
    2649    $attach_data = wp_generate_attachment_metadata($attach_id, $filepath);
  • outrank/trunk/libs/api.php

    r3397401 r3448007  
    201201    // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery
    202202    $inserted = $wpdb->insert($table_name, [
    203         'image'            => $imageId,
    204         'slug'             => $final_slug,  // Use unique slug
     203        'image'            => $imageId ? (string) $imageId : '',
     204        'slug'             => $final_slug,
    205205        'title'            => $title,
    206206        'meta_description' => sanitize_text_field($params['meta_description'] ?? ''),
     
    210210
    211211    if (!$inserted) {
    212         // If custom table insert fails, we should probably delete the post to maintain consistency
     212        // If custom table insert fails, delete the post to maintain consistency
     213        $db_error = $wpdb->last_error;
    213214        wp_delete_post($post_id, true);
    214         return new WP_REST_Response(['error' => 'Failed to insert into tracking table'], 500);
     215        return new WP_REST_Response([
     216            'error' => 'Failed to insert into tracking table' . ( $db_error ? ': ' . $db_error : '' )
     217        ], 500);
    215218    }
    216219
  • outrank/trunk/outrank.php

    r3397401 r3448007  
    66 * Plugin URI: https://outrank.so
    77 * Description: Get traffic and outrank competitors with automatic SEO-optimized content generation published to your WordPress site.
    8  * Version: 1.0.3
     8 * Version: 1.0.4
    99 * Author: Outrank
    1010 * License: GPLv2 or later
  • outrank/trunk/readme.txt

    r3397401 r3448007  
    55Tested up to: 6.8 
    66Requires PHP: 8.0 
    7 Stable tag: 1.0.3 
     7Stable tag: 1.0.4 
    88License: GPLv2 or later 
    99License URI: https://www.gnu.org/licenses/gpl-2.0.html 
     
    7474== Changelog ==
    7575
     76= 1.0.4 =
     77* Improved image downloading reliability across different server configurations
     78* Fixed compatibility issues with strict database settings
     79* Better error messages when troubleshooting sync issues
     80* Improved handling of image filenames and file types
     81
    7682= 1.0.3 =
    7783* Add custom duplicate slugs handling
Note: See TracChangeset for help on using the changeset viewer.