pre_post_update fires on new post button
-
Hi,
I have a custom post type Termin (event) with starting dates etc. I want to generate a .ics file when the event is saved or updated. My problem is that sometimes the function is triggered also on new post giving me the download prompt of the browser instead of bringing me to the new post admin screen.
I don’t understand why my function is triggered on new post although I use pre_post_update. Here my function:
add_action('pre_post_update', 'ma_create_termin_ics',1,10); function ma_create_termin_ics($post_id) { if ($parent_id = wp_is_post_revision($post_id)) { $post_id = $parent_id; } $p_type = get_post_type($post_id); if ($p_type == 'termin') { $upload_dir = wp_upload_dir(); $ics_dir = $upload_dir['basedir'] . '/ics'; if (!file_exists($ics_dir)) { mkdir($ics_dir, 0755, true); } $filephad = $ics_dir . '/' . $post_id . '_ics.ics'; header('Content-Type: text/Calendar; charset=utf-8'); header('Content-Disposition: attachment; filename=' . $post_id . '_ics.ics'); header('Content-Transfer-Encoding: binary'); $ics_file = fopen($filephad, 'wb'); fwrite($ics_file, 'BEGIN:VCALENDAR' . "\n"); ................. fwrite($ics_file, 'END:VCALENDAR'); fclose($ics_file); } }Any ideas?
Thanks
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
The topic ‘pre_post_update fires on new post button’ is closed to new replies.