• Hi Getty Images Team,

    Could you please revise getty-images.php to fix the following?

    1) line 603: $url = sanitize_url( $_POST[‘url’] );
    The sanitize_url() function has been deprecated since version 2.8.0 – could you please replace it with esc_url_raw() as per https://developer.www.ads-software.com/reference/functions/sanitize_url/

    2) line 561: preg_match(“/filename=([^*]+)/”, $response[‘headers’][‘content-disposition’], $filename);

    This causes a 500 Internal Server Error if wp_safe_remote_get returns a WP_Error object. (For example, when our proxy settings were blocking downloads from https://download.gettyimages.com)

    Can you please move preg_match down a few lines, underneath the following code, so that this is avoided?

    if ( is_wp_error( $response ) ) {
    unlink( $tmpfname );
    return $response;
    }

    Extract from error log:

    [29-Nov-2018 01:51:09 UTC] PHP Fatal error: Uncaught Error: Cannot use object of type WP_Error as array in /opt/rh/httpd24/root/var/www/html/wp-content/plugins/getty-images/getty-images.php:561
    Stack trace:
    #0 /opt/rh/httpd24/root/var/www/html/wp-content/plugins/getty-images/getty-images.php(618): Getty_Images->getty_download_url(‘https://downloa…’)
    #1 /opt/rh/httpd24/root/var/www/html/wp-includes/class-wp-hook.php(286): Getty_Images->ajax_download(”)
    #2 /opt/rh/httpd24/root/var/www/html/wp-includes/class-wp-hook.php(310): WP_Hook->apply_filters(”, Array)
    #3 /opt/rh/httpd24/root/var/www/html/wp-includes/plugin.php(453): WP_Hook->do_action(Array)
    #4 /opt/rh/httpd24/root/var/www/html/wp-admin/admin-ajax.php(100): do_action(‘wp_ajax_getty_i…’)
    #5 {main}
    thrown in /opt/rh/httpd24/root/var/www/html/wp-content/plugins/getty-images/getty-images.php on line 561

    Thanks,
    Ben

  • The topic ‘Replace deprecated function and improve handling of WP_Error response’ is closed to new replies.