Ok, so I'm working on a plugin and just ran into a problem.
Here's what I'm doing:
1. Using a metabox with Plupload to upload an image to an upload dir in the plugin folder.
2. Upon upload success a script is called and the image is initialized in jCrop.
3. The cropped image is processed and saved to another dir in the plugin folder using a form with ajax.
4. Upon image processing success the filename of this new, cropped file is passed back.
And here's where I'm stuck. What I want to do now is to use the filename that I passed back and use it for further processing within Wordpress.
Until now everything has been handled without any WP specific code being involved.
What I was thinking about now was to use $.get to pass the filename on to a standalone php file within the plugin folder and use require_once('wp-load.php'); in it to be able to use Wordpress functions. But while reading up on the I came a cross multiple posts that said that you shouldn't go about that way.
So basically, my question is, how do I go from here:
jQuery.ajax({
type: "POST",
url: plugin_path + "process.php",
data: dataString,
success: function (data) {
var obj = jQuery.parseJSON(data);
if (obj.response == 'success') {
return obj.tempfile; // PASS THIS ON FOR WP INTERACTION
} else {
alert('sorry there was an error');
}
}
});
To here:
$video_thumb_url = obj.tempfile; // THIS IS WRONG, BUT JUST TO PROVE POINT
$result = media_sideload_image($video_thumb_url, $post_id, 'video_thumbnail');
$attachments = get_posts(array('numberposts' => '1', 'post_parent' => $post_id, 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => 'ASC'));
if(sizeof($attachments) > 0){
// set image as the post thumbnail
set_post_thumbnail($post_id, $attachments[0]->ID);
}
Thanks in advance
P.S. Really had a hard time coming up with a title for this, if you know something better suited, just let me know/edit it, thanks.
wp_ajax_*orwp_ajax_nopriv_*hooks. – kaiser Sep 2 '12 at 23:08