我有一個照片/ 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