I have a Photo/Wordpress site where each of my posts consist of a featured image. What i'm trying to create is to automatically post the uploaded featured image to Twitter after publishing the post. I managed to add a function to Functions.php that executes when publishing a post.
add_action('publish_post','postToTwitter');
The postToTwitter function creates a tweet with Matt Harris OAuth 1.0A library. This works fine if i attach an image that's relative to the file of the postToTwitter function.
// this is the jpeg file to upload. It should be in the same directory as this file.
$image = dirname(__FILE__) . '/image.jpg';
So i want the $image var to hold my Featured Image i uploaded to the Wordpress post.
But this doesn't work by just adding the URL from the uploaded image (since Wordpress upload folder is not relative to the file of the postToTwitter function): The update with media endpoint(Twitter) only supports images directly uploaded in the POST -- it will not take a remote URL as an argument.
So my question is how i can refer to the Featured Image uploaded in the POST?
// This is how it should work with an image upload form
$image = "@{$_FILES['image']['tmp_name']};type={$_FILES['image']['type']};filename={$_FILES['image']['name']}"
WP_CONTENT_DIR
? – brasofilo