function cfp_process_contact()
{
    // If POST, nonce and honeypot are not set, beat it
    if (empty($_POST) || empty($_POST['wordpress-nonce']) || !isset($_POST['honeypot'])) {
        return false;
    }
    // Session variable for form errors
    $_SESSION['cfp_contact_errors'] = array();
    // If nonce is not valid, beat it
    if (!wp_verify_nonce($_POST['wordpress-nonce'], get_bloginfo('admin_email'))) {
        $_SESSION['cfp_contact_errors']['nonce'] = __('Nonce failed!', 'proper-contact');
        return false;
    }
    // If the honeypot caught a bear, beat it
    if (!empty($_POST['honeypot'])) {
        $_SESSION['cfp_contact_errors']['honeypot'] = __('Form submission failed!', 'proper-contact');
        return false;
    }
    // Start the body of the contact email
    $body = "\n*** " . __('Contact form submission on', 'proper-contact') . " " . get_bloginfo('name') . " (" . site_url() . ") *** \n\n";
    // Sanitize and validate name
    $contact_name = isset($_POST['contact-name']) ? sanitize_text_field(trim($_POST['contact-name'])) : '';
    // Do we require an email address?
    if (proper_contact_get_key('propercfp_name_field') === 'req' && empty($contact_name)) {
        $_SESSION['cfp_contact_errors']['contact-name'] = proper_contact_get_key('propercfp_label_err_name');
    } elseif (!empty($contact_name)) {
        $body .= stripslashes(proper_contact_get_key('propercfp_label_name')) . ": {$contact_name} \r";
    }
    // Sanitize and validate email
    $contact_email = isset($_POST['contact-email']) ? sanitize_email($_POST['contact-email']) : '';
    // If required, is it valid?
    if (proper_contact_get_key('propercfp_email_field') === 'req' && !filter_var($contact_email, FILTER_VALIDATE_EMAIL)) {
        $_SESSION['cfp_contact_errors']['contact-email'] = proper_contact_get_key('propercfp_label_err_email');
    } elseif (!empty($contact_email)) {
        $body .= stripslashes(proper_contact_get_key('propercfp_label_email')) . ": {$contact_email} \r" . __('Google it', 'proper-contact') . ": https://www.google.com/#q={$contact_email} \r";
    }
    // Sanitize phone number
    $contact_phone = isset($_POST['contact-phone']) ? sanitize_text_field($_POST['contact-phone']) : '';
    // Do we require a phone number?
    if (proper_contact_get_key('propercfp_phone_field') === 'req' && empty($contact_phone)) {
        $_SESSION['cfp_contact_errors']['contact-phone'] = proper_contact_get_key('propercfp_label_err_phone');
        // If not required and empty, leave it out
    } elseif (!empty($contact_phone)) {
        $body .= stripslashes(proper_contact_get_key('propercfp_label_phone')) . ": {$contact_phone} \r" . __('Google it', 'proper-contact') . ": https://www.google.com/#q={$contact_phone}\r";
    }
    // Sanitize contact reason
    $contact_reason = isset($_POST['contact-reasons']) ? sanitize_text_field($_POST['contact-reasons']) : '';
    // If empty, leave it out
    if (!empty($contact_reason)) {
        $contact_reason = stripslashes($contact_reason);
        $body .= stripslashes(proper_contact_get_key('propercfp_label_reason')) . ": {$contact_reason} \r";
    }
    $body = apply_filters('pcf_process_above_comment', $body);
    // Sanitize and validate comments
    $contact_comment = sanitize_text_field(trim($_POST['question-or-comment']));
    if (empty($contact_comment)) {
        $_SESSION['cfp_contact_errors']['question-or-comment'] = sanitize_text_field(proper_contact_get_key('propercfp_label_err_no_content'));
    } else {
        $body .= "\n\n" . stripslashes(proper_contact_get_key('propercfp_label_comment')) . ": " . stripslashes($contact_comment) . " \n\n";
    }
    $body = apply_filters('pcf_process_below_comment', $body);
    $body = apply_filters('pcf_process_above_submit', $body);
    // Check the math CAPTCHA, if present
    if (proper_contact_get_key('propercfp_captcha_field')) {
        $captcha_sum = isset($_POST['math-captcha']) ? intval($_POST['math-captcha']) : 0;
        if ($captcha_sum != (int) $_POST['math-captcha-sum']) {
            $_SESSION['cfp_contact_errors']['math-captcha'] = sanitize_text_field(proper_contact_get_key('propercfp_label_err_captcha'));
        }
    }
    // Sanitize and validate IP
    $contact_ip = filter_var($_SERVER['REMOTE_ADDR'], FILTER_VALIDATE_IP);
    // If valid and present, create a link to an IP search
    if (!empty($contact_ip)) {
        $body .= "IP address: {$contact_ip} \r\nIP search: http://whatismyipaddress.com/ip/{$contact_ip} \n\n";
    }
    // Sanitize and prepare referrer;
    if (!empty($_POST['contact-referrer'])) {
        $body .= "Came from: " . sanitize_text_field($_POST['contact-referrer']) . " \r";
    }
    // Show the page this contact form was submitted on
    $body .= 'Sent from page: ' . get_permalink(get_the_id());
    // Check the blacklist
    $blocked = proper_get_blacklist();
    if (!empty($blocked)) {
        if (in_array($contact_email, $blocked) || in_array($contact_ip, $blocked)) {
            $_SESSION['cfp_contact_errors']['blacklist-blocked'] = 'Form submission blocked!';
            return false;
        }
    }
    // No errors? Go ahead and process the contact
    if (empty($_SESSION['cfp_contact_errors'])) {
        $site_email = sanitize_email(proper_contact_get_key('propercfp_email'));
        $site_name = htmlspecialchars_decode(get_bloginfo('name'));
        // Notification recipients
        $site_recipients = sanitize_text_field(proper_contact_get_key('propercfp_email_recipients'));
        $site_recipients = explode(',', $site_recipients);
        $site_recipients = array_map('trim', $site_recipients);
        $site_recipients = array_map('sanitize_email', $site_recipients);
        $site_recipients = implode(',', $site_recipients);
        // No name? Use the submitter email address, if one is present
        if (empty($contact_name)) {
            $contact_name = !empty($contact_email) ? $contact_email : '[None given]';
        }
        // Need an email address for the email notification
        if (proper_contact_get_key('propercfp_reply_to_admin') == 'yes') {
            $send_from = $site_email;
            $send_from_name = $site_name;
        } else {
            $send_from = !empty($contact_email) ? $contact_email : $site_email;
            $send_from_name = $contact_name;
        }
        // Sent an email notification to the correct address
        $headers = "From: {$send_from_name} <{$send_from}>\r\nReply-To: {$send_from_name} <{$send_from}>";
        wp_mail($site_recipients, 'Contact on ' . $site_name, $body, $headers);
        // Should a confirm email be sent?
        $confirm_body = stripslashes(trim(proper_contact_get_key('propercfp_confirm_email')));
        if (!empty($confirm_body) && !empty($contact_email)) {
            // Removing entities
            $confirm_body = htmlspecialchars_decode($confirm_body);
            $confirm_body = html_entity_decode($confirm_body);
            $confirm_body = str_replace('&#39;', "'", $confirm_body);
            $headers = "From: {$site_name} <{$site_email}>\r\nReply-To: {$site_name} <{$site_email}>";
            wp_mail($contact_email, proper_contact_get_key('propercfp_label_submit') . ' - ' . $site_name, $confirm_body, $headers);
        }
        // Should the entry be stored in the DB?
        if (proper_contact_get_key('propercfp_store') === 'yes') {
            $insert_post_args = array('post_type' => 'proper_contact', 'post_title' => date('l, M j, Y', time()) . ' by "' . $contact_name . '"', 'post_content' => $body, 'post_author' => 1, 'post_status' => 'private');
            $insert_post_args = apply_filters('pcf_process_insert_post_args', $insert_post_args);
            $new_post_id = wp_insert_post($insert_post_args);
            if (isset($contact_email) && !empty($contact_email)) {
                add_post_meta($new_post_id, 'Contact email', $contact_email);
            }
            do_action('pcf_process_after_insert_post', $new_post_id);
        }
        // Should the user get redirected?
        if (proper_contact_get_key('propercfp_result_url')) {
            $redirect_id = intval(proper_contact_get_key('propercfp_result_url'));
            $redirect = get_permalink($redirect_id);
        } else {
            $redirect = $_SERVER["HTTP_REFERER"] . (strpos($_SERVER["HTTP_REFERER"], '?') === FALSE ? '?' : '&') . 'pcf=1';
        }
        $redirect = apply_filters('pcf_process_redirect', $redirect);
        wp_safe_redirect($redirect);
    }
}
function proper_contact_plugin_options()
{
    return array('head1' => array(__('Fields to show', 'proper-contact'), '', 'title', ''), 'propercfp_name_field' => array(__('Name', 'proper-contact'), __('Should a name field be displayed?', 'proper-contact'), 'select', 'yes', array('' => __('None', 'proper-contact'), 'yes' => __('Yes but not required', 'proper-contact'), 'req' => __('Required', 'proper-contact'))), 'propercfp_email_field' => array(__('Email address', 'proper-contact'), __('Should an email address field be displayed?', 'proper-contact'), 'select', 'yes', array('' => __('None', 'proper-contact'), 'yes' => __('Yes but not required', 'proper-contact'), 'req' => __('Required', 'proper-contact'))), 'propercfp_phone_field' => array(__('Phone number', 'proper-contact'), __('Should a phone number field be displayed?', 'proper-contact'), 'select', 'yes', array('' => __('None', 'proper-contact'), 'yes' => __('Yes but not required', 'proper-contact'), 'req' => __('Required', 'proper-contact'))), 'propercfp_reason' => array(__('"Reason for contacting" options', 'proper-contact'), __('You can have people choose the reason for their contact from a drop-down list. If you would like this option to appear, enter the different reasons into the text box below, each one on its own line.', 'proper-contact'), 'textarea', ''), 'propercfp_captcha_field' => array(__('Add a math CAPTCHA', 'proper-contact'), __('Checking this box will add a math CAPTCHA to the form to discourage spam', 'proper-contact'), 'checkbox', ''), 'head2' => array(__('Form processing options', 'proper-contact'), '', 'title', ''), 'propercfp_email' => array(__('Contact notification sender email', 'proper-contact'), __('Email to use for the sender of the contact form emails both to the recipients below and the contact form submitter (if this is activated below). The domain for this email address should match your site\'s domain.', 'proper-contact'), 'email', get_bloginfo('admin_email')), 'propercfp_reply_to_admin' => array(__('Use the email address above as notification sender', 'proper-contact'), __('When this is on, the notification emails sent from your site will come from the email address above. When this is off, the emails will come from the form submitter, making it easy to reply. If you are not receiving notifications from the site, then turn this option off as your email server might be marking them as spam.', 'proper-contact'), 'checkbox', ''), 'propercfp_email_recipients' => array(__('Contact submission recipients', 'proper-contact'), __('Email address(es) to receive contact submission notifications. You can separate multiple emails with a comma.', 'proper-contact'), 'text', proper_contact_get_key('propercfp_email') ? proper_contact_get_key('propercfp_email') : get_bloginfo('admin_email')), 'propercfp_result_url' => array(__('"Thank You" URL', 'proper-contact'), __('Select the post-submit page for all forms submitted', 'proper-contact'), 'select', '', proper_get_content_array()), 'propercfp_css' => array(__('Add styles to the site', 'proper-contact'), __('Checking this box will add styles to the form. By default, this is off so you can add your own styles.', 'proper-contact'), 'checkbox', ''), 'propercfp_store' => array('Store submissions in the database', 'Should the submissions be stored in the admin area? If chosen, contact form submissions will be saved in Contacts on the left (appears after this option is activated).', 'checkbox', ''), 'propercfp_blacklist' => array(__('Use the comments blacklist to restrict submissions', 'proper-contact'), __('Should form submission IP and email addresses be compared against the Comment Blacklist, found in <strong>wp-admin > Settings > Discussion > Comment Blacklist?</strong>', 'proper-contact'), 'checkbox', 'yes'), 'propercfp_confirm_email' => array(__('Send email confirmation to form submitter', 'proper-contact'), __('Adding text here will send an email to the form submitter. The email uses the "Text to show when form is submitted..." field below as the subject line. Plain text only here, no HTML.', 'proper-contact'), 'textarea', ''), 'head3' => array('Label Fields', '', 'title', ''), 'propercfp_label_name' => array(__('Name field label', 'proper-contact'), '', 'text', __('Your full name', 'proper-contact')), 'propercfp_label_email' => array(__('Email field label', 'proper-contact'), '', 'text', __('Your email address', 'proper-contact')), 'propercfp_label_phone' => array(__('Phone field label', 'proper-contact'), '', 'text', __('Your phone number', 'proper-contact')), 'propercfp_label_reason' => array(__('Reason for contacting label', 'proper-contact'), '', 'text', __('Reason for contacting', 'proper-contact')), 'propercfp_label_comment' => array(__('Comment field label', 'proper-contact'), '', 'text', __('Question or comment', 'proper-contact')), 'propercfp_label_math' => array(__('Math CAPTCHA label', 'proper-contact'), '', 'text', __('Solve this equation: ', 'proper-contact')), 'propercfp_label_submit_btn' => array(__('Submit button text', 'proper-contact'), '', 'text', __('Submit', 'proper-contact')), 'propercfp_label_submit' => array(__('Successful form submission text', 'proper-contact'), __('This text is used on the page if no "Thank You" URL is set above. This is also used as the confirmation email title, if one is set to send out.', 'proper-contact'), 'text', __('Thank you for your contact!', 'proper-contact')), 'head4' => array(__('HTML5 validation', 'proper-contact'), '', '', 'title', ''), 'propercfp_html5_no_validate' => array(__('Use HTML5 validation', 'proper-contact'), '', 'checkbox', 'yes'), 'head5' => array(__('Error Messages', 'proper-contact'), '', 'title', ''), 'propercfp_label_err_name' => array(__('Name required and missing', 'proper-contact'), '', 'text', __('Enter your name', 'proper-contact')), 'propercfp_label_err_email' => array('E-mail required and missing', '', 'text', __('Enter a valid email', 'proper-contact')), 'propercfp_label_err_phone' => array(__('Phone required and missing', 'proper-contact'), '', 'text', __('Please enter a phone number', 'proper-contact')), 'propercfp_label_err_no_content' => array(__('Question/comment is missing', 'proper-contact'), '', 'text', __('Enter your question or comment', 'proper-contact')), 'propercfp_label_err_captcha' => array(__('Incorrect math CAPTCHA', 'proper-contact'), '', 'text', __('Check your math ...', 'proper-contact')));
}