WP Smush - Image Optimization
[resolved] [Plugin: WP Smush.it] Problem Calling update (4 posts)

  1. Derek Perkins
    Posted 5 years ago #

    I have a plugin that attaches images automatically to my posts. It works just fine, except for when I have WP Smush.it enabled. It's an external php page to my basic WP theme, so it isn't running in the context of my site except for these two includes.

    require_once( "/home1/derekper/public_html/soccerreviews/wp-blog-header.php" );
    require_once( ABSPATH . 'wp-admin/includes/image.php' );

    Here is my code that attaches the meta data.

    $attach_id = wp_insert_attachment( $attachment, $filename, $postid );
    $attach_data = wp_generate_attachment_metadata( $attach_id, $filename );
    wp_update_attachment_metadata( $attach_id,  $attach_data );

    This is the error that I'm getting.
    Fatal error: Call to undefined function download_url() in /home1/derekper/public_html/soccerreviews/wp-content/plugins/wp-smushit/wp-smushit.php on line 172

    Any ideas why this is happening? I tried requiring the wp-smushit.php file directly, but it gave me the same error.


  2. Milan Dinić
    Posted 5 years ago #

    I had exactly the same problem last week and already wanted to post a code suggestion for Alex. You need to include file wp-admin/includes/file.php before you call functions for attachemnts.

    require_once(ABSPATH . 'wp-admin/includes/file.php');

    Alex should add conditional before download_url is used in WP Smush.it to check if download_url function exists, and if not, to load file like above.

  3. Derek Perkins
    Posted 5 years ago #

    I eventually figured that out too and I should have posted the answer back here. Thanks!

  4. Alex Dunae
    Plugin Contributor

    Posted 5 years ago #

    Thanks for the suggestion. The download_url check will be in the next update.

Topic Closed

This topic has been closed to new replies.

About this Plugin

  • WP Smush - Image Optimization
  • Frequently Asked Questions
  • Support Threads
  • Reviews

About this Topic