Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- if( isset( $_POST['submit_apply'] ) ) {
- global $post, $userdata;
- //echo '<pre>'; print_r( $_POST ); echo '</pre>';
- //echo '<pre>'; print_r( $_FILES ); echo '</pre>';
- $error = false;
- $attachments = array();
- $to = array();
- $uploads = wp_upload_dir();
- $uploads_dir = $uploads['path'];
- $mime = array(
- 'application/pdf', 'application/msword',
- 'application/vnd.openxmlformats-officedocument.wordprocessingml.document'
- );
- if( count( $_FILES ) ) {
- foreach( $_FILES as $file ) {
- if( $file ) {
- if( !in_array( $file['type'], $mime ) ) {
- $error = true;
- break;
- }
- //echo '<pre>'; print_r( $file ); echo '</pre>';
- //upload the files temporary and save the path in array
- $path = $uploads_dir . '/' . $file['name'];
- if( move_uploaded_file( $file['tmp_name'], $path ) ) {
- $attachments[] = $path;
- }
- }
- }
- //exit;
- }
- if( $error == false ) {
- if( $to_author = get_post_meta( $post->ID, 'job-email', true ) ) {
- $to[] = $to_author;
- }
- if( $_POST['send_copy'] == 'yes' ) {
- $to[] = $userdata->user_email;
- }
- $message = 'Iemand heeft zojuist gesolliciteerd op uw vacature:
- "%s"
- In de bijlage van deze e-mail staan de documenten van de kandidaat. U kunt deze vacature op elk ogenblik sluiten of verwijderen door naar uw dashboard te gaan.
- De vacature zelf kunt hier bekijken: "%s"
- ';
- $message = sprintf( $message, $post->post_title, get_permalink( $post->ID ) );
- $redir_url = '';
- if( $attachments ) {
- wp_mail( $to, 'Nieuwe sollicitant op Freelance.sr', $message, '', $attachments);
- $redir_url = add_query_arg( array( 'msg' => 'yes' ) );
- //update the applicant list
- $applicants = get_post_meta( $post->ID, 'applicants', true );
- if( $applicants == '' ) {
- $user_list = "{$userdata->ID}";
- } else {
- $user_list = $applicants . ",{$userdata->ID}";
- }
- update_post_meta( $post->ID, 'applicants', $user_list);
- }
- //echo '<pre>'; print_r( $to ); echo '</pre>';
- //echo '<pre>'; print_r( $attachments ); echo '</pre>';
- //now delete the uploaded files
- foreach( $attachments as $file ) {
- if( file_exists( $file ) ) {
- unlink( $file );
- }
- }
- if( $redir_url ) {
- wp_redirect( $redir_url );
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment