Title: Code improvement/correction ?
Last modified: August 20, 2016

---

# Code improvement/correction ?

 *  [angeloio](https://wordpress.org/support/users/angeloio/)
 * (@angeloio)
 * [13 years, 3 months ago](https://wordpress.org/support/topic/code-improvementcorrection/)
 * Dear Sir,
 * I am studying your code because I am trying to modify it to fit my needs. Some
   comments if I may, in order for me to know that I am in the right path.
    On line
   427 there is this line: `$file = media_sideload_image( $img, (int)$post->ID );`
   This line of code is executed when the option ‘Set Featured Images’ of the plugin
   is set. In most cases this means that the image sources that appear inside posts
   are not external but rather live in the same server as the post (namely they 
   are not external). Under this assumption, the code normally it should extract
   the url from the post’s content and then do something like: ` wp_insert_attachment(
   $attachment, $file, $post_id); wp_update_attachment_metadata( $id, wp_generate_attachment_metadata(
   $id, $file ) );  Instead in this case the media_sideload_image() function tries
   to re-upload the image back into the server and in many cases (for example if
   it tries in the same directory) it fails. Maybe it should check if the image 
   is local or external and then decide what to do.
 * What do you think ? Your feedback is important to me
 * Many thanks for your time
    ioannis
 * [http://wordpress.org/extend/plugins/media-tools/](http://wordpress.org/extend/plugins/media-tools/)

The topic ‘Code improvement/correction ?’ is closed to new replies.

 * ![](https://s.w.org/plugins/geopattern-icon/media-tools_d3d3d3.svg)
 * [Media Tools](https://wordpress.org/plugins/media-tools/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/media-tools/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/media-tools/)
 * [Active Topics](https://wordpress.org/support/plugin/media-tools/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/media-tools/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/media-tools/reviews/)

 * 0 replies
 * 1 participant
 * Last reply from: [angeloio](https://wordpress.org/support/users/angeloio/)
 * Last activity: [13 years, 3 months ago](https://wordpress.org/support/topic/code-improvementcorrection/)
 * Status: not resolved