Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function wpcf7_to_post($cfdata) {
- // Daten aus der Anfrage auslesen
- $submission = WPCF7_Submission::get_instance();
- if ( $submission ) {
- $formdata = $submission->get_posted_data();
- }
- // Post ID des Formulares angeben, welches "abgefangen" werden soll
- if ( $cfdata->id() == '126') {
- $newdraft = array(
- 'post_title'=> $formdata['your-name'],
- 'post_content'=> $formdata['your-message'],
- 'post_status' => 'draft', // Status
- 'post_type' => 'testimonials', // Post Type
- );
- // Eintrag als Entwurf anlegen
- $newpostid = wp_insert_post($newdraft);
- // Bild in die Mediathek kopieren/hochladen
- $random = date(DATE_ATOM, mktime(0, 0, 0, 7, 1, 2000)).rand(0,10000);
- $uploaded_files = $submission->uploaded_files();
- $cf7_image = $uploaded_files['file-772'];
- $cf7_image_clean = "/".$random.str_replace("/html/wp-content/uploads/cf7_images/","",$cf7_image);
- $wp_upload_dir = wp_upload_dir();
- copy($cf7_image, $wp_upload_dir['path'].'/'.$cf7_image_clean);
- $wp_filetype = wp_check_filetype($wp_upload_dir['path'].'/'.$cf7_image_clean, null);
- $attachment = array(
- 'post_mime_type' => $wp_filetype['type'],
- 'post_title' => sanitize_file_name($cf7_image_clean),
- 'post_content' => '',
- 'post_status' => 'inherit'
- );
- $image_id = wp_insert_attachment($attachment, $wp_upload_dir['path'].'/'.$cf7_image_clean, $newpostid);
- require_once(ABSPATH . 'wp-admin/includes/image.php');
- $image_data = wp_generate_attachment_metadata($image_id, $wp_upload_dir['path'].'/'.$cf7_image_clean);
- wp_update_attachment_metadata($image_id, $image_data);
- // Bild als Beitragsbild setzen
- set_post_thumbnail($newpostid, $image_id);
- }
- }
- add_action('wpcf7_before_send_mail', 'wpcf7_to_post',1);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement