Created
February 25, 2015 14:01
-
-
Save hissy/0973a6a9977129a6ebd0 to your computer and use it in GitHub Desktop.
[Really Simple CSV Importer] Example: import image from url to custom field
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
Plugin Name: Get Remote Image to Custom Field | |
*/ | |
add_filter('really_simple_csv_importer_post_saved', function($post) | |
{ | |
if (is_object($post)) { | |
// Get the meta data of which key is "image" | |
$image = $post->image; | |
// Create a instance of helper class | |
$h = RSCSV_Import_Post_Helper::getByID($post->ID); | |
// Get the remote image data | |
$file = $h->remoteGet($image); | |
// Then, attach it | |
$attachment_id = $h->setAttachment($file); | |
// Finally, replace the original data with the attachment id | |
$h->setMeta( array( 'image' => $attachment_id ) ); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@erikdemarco You can make a support thread on the official forum: https://wordpress.org/support/plugin/really-simple-csv-importer/