• Resolved rafax

    (@rafax)


    Hello, I have an error when importing images, it doesn’t work anymore.
    They are google images with this format:
    https://www.youtube.com/watch?v=YF1GMzGXGOA
    Before I used to import ads using .csv without problems, now the image is not imported and the error that shows the ad is this:

    Fatal error: Uncaught Error: Object of class WP_Error could not be converted to string
    in?/home/ndrvsxek/buscarrestaurantemex.com/wp-includes/formatting.php?on line?1108

    Call stack:

    1. wp_check_invalid_utf8()
      wp-includes/formatting.php:4707
    2. esc_attr()
      wp-content/plugins/directorist/views/admin-templates/listing-form/image_upload.php:32
    3. include()
      wp-content/plugins/directorist/includes/template-functions.php:54
    4. atbdp_get_admin_template()
      wp-content/plugins/directorist/includes/model/ListingForm.php:669
    5. Directorist\Directorist_Listing_Form::field_template()
      wp-content/plugins/directorist/templates/listing-form/section.php:20
    6. include()
      wp-content/plugins/directorist/includes/helpers/trait-uri-helper.php:70
    7. Directorist\Helper::get_template()
      wp-content/plugins/directorist/includes/model/ListingForm.php:547
    8. Directorist\Directorist_Listing_Form::section_template()
      wp-content/plugins/directorist/includes/classes/class-metabox.php:163
    9. ATBDP_Metabox::render_listing_meta_fields()
      wp-content/plugins/directorist/includes/classes/class-metabox.php:255
    10. ATBDP_Metabox::listing_form_info_meta()
      wp-admin/includes/template.php:1456
    11. do_meta_boxes()
      wp-admin/edit-form-advanced.php:714
    12. require()
      wp-admin/post.php:206

    I use query monnitor to debug errors.
    Any solution?

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Support Mahfuzul Alam

    (@mahfuz87)

    Hello @rafax

    Thank you for reaching out.

    Could you please provide the csv file or the image url you have tried to import? We will investigate and try to find a solution for you.

    Regards

    Thread Starter rafax

    (@rafax)

    Hello, this is the csv I use. Before it worked correctly.
    The image is the “image url” field, they are from google maps

    csv directorist

    • This reply was modified 1 year, 1 month ago by rafax.
    Plugin Support Mahfuzul Alam

    (@mahfuz87)

    Hello @rafax

    Please replace the function (“atbdp_insert_attachment_from_url”) with the following code –

    public static function atbdp_insert_attachment_from_url( $file_url ) {
    
                if (!filter_var($file_url, FILTER_VALIDATE_URL)) {
                    return false;
                }
                $contents = @file_get_contents($file_url);
        
                if ($contents === false) {
                    return false;
                }
        
                if( ! wp_check_filetype( $file_url )['ext'] ) {
        
                    $headers = array(
                        'Accept'     => 'application/json',
                    );
        
                    $config = array(
                        'method'      => 'GET',
                        'timeout'     => 30,
                        'redirection' => 5,
                        'httpversion' => '1.0',
                        'headers'     => $headers,
                        'cookies'     => array(),
                    );
        
                    $upload = array();
        
                    try {
                        $response = wp_remote_get( $file_url, $config );
        
                        if ( ! is_wp_error( $response ) ) {
                            $type = wp_remote_retrieve_header( $response, 'content-type' );
                            $extension = preg_replace("/\w+\//", '', $type );
                            $upload = wp_upload_bits(basename( $file_url . '.'. $extension ), '', wp_remote_retrieve_body($response));
        
                        }
                    } catch ( Exception $e ) {
        
                    }
                }else{
                    $upload = wp_upload_bits(basename($file_url), null, $contents);
                }
        
                if (isset($upload['error']) && $upload['error']) {
                    return false;
                }
        
                $type = '';
                if (!empty($upload['type'])) {
                    $type = $upload['type'];
                } else {
                    $mime = wp_check_filetype($upload['file']);
                    if ($mime) {
                        $type = $mime['type'];
                    }
                }
                $attachment = array('post_title' => basename($upload['file']), 'post_content' => '', 'post_type' => 'attachment', 'post_mime_type' => $type, 'guid' => $upload['url']);
                $id = wp_insert_attachment($attachment, $upload['file']);
                wp_update_attachment_metadata($id, wp_generate_attachment_metadata($id, $upload['file']));
                return $id;
        
            }

    You will find the function here – public/wp-content/plugins/directorist/includes/classes/class-tools.php

    Please let me know if you need further assistance.

    Regards

    Thread Starter rafax

    (@rafax)

    Thanks

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Error with the image importer’ is closed to new replies.