我有一个Photo / Wordpress网站,我的每个帖子都包含精选图片。我要创建的是在发布帖子后自动将上传的特色图片发布到Twitter。我设法将一个函数添加到Functions.php中,该函数在发布帖子时执行。
add_action('publish_post','postToTwitter');
Run Code Online (Sandbox Code Playgroud)
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';
Run Code Online (Sandbox Code Playgroud)
所以我想让$ 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']}"
Run Code Online (Sandbox Code Playgroud)