Hi all,
I'm working on a simple function that will check that a post is being published the first time, and if so make backup copies of all the images whose paths are stored in a specific custom field. I think the code will be pretty self-explanatory. It checks for a custom field that I create at the end of the function to act as a notice the images are backed up and to assure that the post is being published for the first time. Then it calls up custom fields and makes copies in a new directory.
Unfortunately, I'm getting the white screen. Maybe someone will see where I'm going wrong, I think it could be a useful function in a number of instances:
function process_gallery_images($post_ID){
$gallery_status_field = get_post_meta($post_ID,'gallery_status',true);
$gallery_status_meta = 'images_are_processed';
$gallery_image = get_post_meta($post_ID,'gallery_image',false);
$gallery_backup_path = 'http://www.mysite.com/backup/'
if ($gallery_status_field == '' && !wp_is_post_revision($post_ID)){
foreach($gallery_image as $gallery_image){
copy($gallery_image, $gallery_backup_path."backup-".basename($gallery_image))
}
}
if ($gallery_status_field == '' && !wp_is_post_revision($post_ID)){
add_post_meta($post_ID,'gallery_status',$gallery_status_meta,true);
}
}
add_action ( 'publish_post', 'process_gallery_images' );
Thanks for taking a look.