Last active
August 29, 2015 14:21
-
-
Save rfair404/f24a678914aa5f41f296 to your computer and use it in GitHub Desktop.
IR Crazy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* create_image_credits sets up the credits for an image | |
* @param $image string the attachment id | |
* @return string the image credit file url | |
*/ | |
function create_image_credits($image){ | |
$image_post = get_post($image); | |
$upload_dir = wp_upload_dir(); | |
$image_guid = explode('/', $image_post->guid); | |
$filename = end($image_guid); | |
$file = $upload_dir['path'] . '/' . $image . '-credit.txt'; | |
$credit_text = sprintf('%s: %s', __('Image Filename', 'rns-subscriber-enhancements'), $filename); | |
$credit_text .= ($image_post->post_content) ? "\n\n\n" . sprintf('%s: %s', __('Caption', 'rns-subscriber-enhancements'), $image_post->post_content) : ''; | |
$rns_credit_text = get_post_meta($image, 'rns_image_credit_text', true); | |
$credit_text .= ($rns_credit_text) ? "\n\n\n" . sprintf('%s: %s', __('Photo Credit', 'rns-subscriber-enhancements'), $rns_credit_text) : ''; | |
$rns_credit_url = get_post_meta($image, 'rns_image_credit_url', true); | |
$credit_text .= ($rns_credit_url) ? "\n\n\n" . sprintf('\n\n%s: %s', __('Credit Url', 'rns-subscriber-enhancements'), $rns_credit_url) : ''; | |
if(is_file($file)){ | |
$open = fopen($file, 'w'); | |
if($open){ | |
fwrite($open, $credit_text); | |
fclose($open); | |
} | |
} else { | |
$open = fopen($file, 'c'); | |
if($open){ | |
fwrite($open, $credit_text); | |
fclose($open); | |
} | |
} | |
return $upload_dir['url'] . '/' . $image . '-credit.txt'; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment