guilleush (September 4th, 2013), silverscreen (May 20th, 2014), sindyskin (April 28th, 2014)
// ad poster sidebar contact form email function cp_contact_ad_owner_email( $post_id ) { $errors = new WP_Error(); // check for required post data $expected = array( 'from_name', 'from_email', 'subject', 'message' ); foreach ( $expected as $field_name ) { if ( empty( $_POST[ $field_name ] ) ) { $errors->add( 'empty_field', __( 'ERROR: All fields are required.', APP_TD ) ); return $errors; } } // check for required anti-spam post data $expected_numbers = array( 'rand_total', 'rand_num', 'rand_num2' ); foreach ( $expected_numbers as $field_name ) { if ( ! isset( $_POST[ $field_name ] ) || ! is_numeric( $_POST[ $field_name ] ) ) { $errors->add( 'invalid_captcha', __( 'ERROR: Incorrect captcha answer.', APP_TD ) ); return $errors; } } // verify captcha answer $rand_post_total = (int) $_POST['rand_total']; $rand_total = (int) $_POST['rand_num'] + (int) $_POST['rand_num2']; if ( $rand_total != $rand_post_total ) $errors->add( 'invalid_captcha', __( 'ERROR: Incorrect captcha answer.', APP_TD ) ); // verify email if ( ! is_email( $_POST['from_email'] ) ) $errors->add( 'invalid_email', __( 'ERROR: Incorrect email address.', APP_TD ) ); // verify post $post = get_post( $post_id ); if ( ! $post ) $errors->add( 'invalid_post', __( 'ERROR: Ad does not exist.', APP_TD ) ); if ( $errors->get_error_code() ) return $errors; $mailto = get_the_author_meta( 'user_email', $post->post_author ); $from_name = appthemes_filter( appthemes_clean( $_POST['from_name'] ) ); $from_email = appthemes_clean( $_POST['from_email'] ); $subject = appthemes_filter( appthemes_clean( $_POST['subject'] ) ); $posted_message = appthemes_filter( appthemes_clean( $_POST['message'] ) ); $sitename = wp_specialchars_decode( get_option('blogname'), ENT_QUOTES ); $siteurl = home_url('/'); $permalink = get_permalink( $post_id ); $message = sprintf( __( 'Someone is interested in your ad listing: %s', APP_TD ), $permalink ) . "\r\n\r\n"; $message .= '"' . wordwrap( $posted_message, 70 ) . '"' . "\r\n\r\n"; $message .= sprintf( __( 'Name: %s', APP_TD ), $from_name ) . "\r\n"; $message .= sprintf( __( 'E-mail: %s', APP_TD ), $from_email ) . "\r\n\r\n"; $message .= '-----------------------------------------' . "\r\n"; $message .= sprintf( __( 'This message was sent from %s', APP_TD ), $sitename ) . "\r\n"; $message .= $siteurl . "\r\n\r\n"; $message .= __( 'Sent from IP Address: ', APP_TD ) . appthemes_get_ip() . "\r\n\r\n"; $email = array( 'to' => $mailto, 'subject' => $subject, 'message' => $message, 'from' => $from_email, 'from_name' => $from_name ); $email = apply_filters( 'cp_email_user_ad_contact', $email, $post_id ); APP_Mail_From::apply_once( array( 'email' => $email['from'], 'name' => $email['from_name'], 'reply' => true ) ); wp_mail( $email['to'], $email['subject'], $email['message'] ); return $errors; }
guilleush (September 4th, 2013), silverscreen (May 20th, 2014), sindyskin (April 28th, 2014)
There are currently 1 users browsing this thread. (0 members and 1 guests)