我有一个照片/ WordPress的网站,其中我的每个职位包括一个精选图像。我试图创建的是在发布帖子后自动将上传的精选图片发布到Twitter。我设法将一个函数添加到发布帖子时执行的Functions.php。WordPress的发布精选图片到Twitter
add_action('publish_post','postToTwitter');
postToTwitter函数使用Matt Harris OAuth 1.0A库创建推文。 这工作正常,如果我附加相对于postToTwitter函数的文件的图像。
// this is the jpeg file to upload. It should be in the same directory as this file.
$image = dirname(__FILE__) . '/image.jpg';
所以我想要$ image var来容纳我的精选图片我上传到WordPress的帖子。
但是,这只是从上传的图像中添加URL(因为WordPress上传文件夹不是相对于postToTwitter功能的文件): 使用媒体端点(Twitter)的更新仅支持直接上传的图像在POST中 - 它不会将远程URL作为参数。
所以我的问题是我如何可以参考在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'](http://codex.wordpress.org/Determining_Plugin_and_Content_Directories#Constants)怎么办? – brasofilo