• Resolved Derek Perkins

    (@ploobers)


    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.

    https://www.ads-software.com/extend/plugins/wp-smushit/

Viewing 3 replies - 1 through 3 (of 3 total)
  • 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.

    Thread Starter Derek Perkins

    (@ploobers)

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

    Plugin Contributor Alex Dunae

    (@alexdunae)

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

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘[Plugin: WP Smush.it] Problem Calling update’ is closed to new replies.