Beispiel #1
0
function pirate_forms_plugin_options()
{
    /*********************************************************/
    /************  Default values from Zerif Lite ************/
    /*********************************************************/
    $zerif_contactus_sitekey = get_theme_mod('zerif_contactus_sitekey');
    if (!empty($zerif_contactus_sitekey)) {
        $pirate_forms_contactus_sitekey = $zerif_contactus_sitekey;
    } else {
        $pirate_forms_contactus_sitekey = '';
    }
    $zerif_contactus_secretkey = get_theme_mod('zerif_contactus_secretkey');
    if (!empty($zerif_contactus_secretkey)) {
        $pirate_forms_contactus_secretkey = $zerif_contactus_secretkey;
    } else {
        $pirate_forms_contactus_secretkey = '';
    }
    $zerif_contactus_recaptcha_show = get_theme_mod('zerif_contactus_recaptcha_show');
    if (isset($zerif_contactus_recaptcha_show) && $zerif_contactus_recaptcha_show == '1') {
        $pirate_forms_contactus_recaptcha_show = '';
    } else {
        $pirate_forms_contactus_recaptcha_show = 'yes';
    }
    $zerif_contactus_button_label = get_theme_mod('zerif_contactus_button_label', __('Send Message', 'zerif-lite'));
    if (!empty($zerif_contactus_button_label)) {
        $pirate_forms_contactus_button_label = $zerif_contactus_button_label;
    } else {
        $pirate_forms_contactus_button_label = __('Send Message', 'pirate-forms');
    }
    $zerif_contactus_email = get_theme_mod('zerif_contactus_email');
    $zerif_email = get_theme_mod('zerif_email');
    $pirate_forms_contactus_email = '';
    if (!empty($zerif_contactus_email)) {
        $pirate_forms_contactus_email = $zerif_contactus_email;
    } elseif (!empty($zerif_email)) {
        $pirate_forms_contactus_email = $zerif_email;
    } else {
        $pirate_forms_contactus_email = get_bloginfo('admin_email');
    }
    return array('fourth_tab' => array('header_options' => array(__('Form processing options', 'pirate-forms'), '', 'title', ''), 'pirateformsopt_email' => array(__('Contact notification sender email', 'pirate-forms'), '<strong>' . __("Insert [email] to use the contact form submitter's email.", "pirate-forms") . '</strong><br>' . __("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.", "pirate-forms"), 'text', pirate_forms_from_email()), 'pirateformsopt_email_recipients' => array(__('Contact submission recipients', 'pirate-forms'), __('Email address(es) to receive contact submission notifications. You can separate multiple emails with a comma.', 'pirate-forms'), 'text', pirate_forms_get_key('pirateformsopt_email') ? pirate_forms_get_key('pirateformsopt_email') : $pirate_forms_contactus_email), 'pirateformsopt_store' => array(__('Store submissions in the database', 'pirate-forms'), __('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).', 'pirate-forms'), 'checkbox', ''), 'pirateformsopt_blacklist' => array(__('Use the comments blacklist to restrict submissions', 'pirate-forms'), __('Should form submission IP and email addresses be compared against the Comment Blacklist, found in', 'pirate-forms') . '<strong>' . __('wp-admin > Settings > Discussion > Comment Blacklist?', 'pirate-forms') . '</strong>', 'checkbox', 'yes'), 'pirateformsopt_confirm_email' => array(__('Send email confirmation to form submitter', 'pirate-forms'), __('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.', 'pirate-forms'), 'textarea', '')), 'first_tab' => array('header_fields' => array(__('Fields Settings', 'pirate-forms'), '', 'title', ''), 'pirateformsopt_name_field' => array(__('Name', 'pirate-forms'), __('Do you want the name field to be displayed?', 'pirate-forms'), 'select', 'req', array('' => __('None', 'pirate-forms'), 'yes' => __('Yes but not required', 'pirate-forms'), 'req' => __('Required', 'pirate-forms'))), 'pirateformsopt_email_field' => array(__('Email address', 'pirate-forms'), __('Do you want the email address field be displayed?', 'pirate-forms'), 'select', 'req', array('' => __('None', 'pirate-forms'), 'yes' => __('Yes but not required', 'pirate-forms'), 'req' => __('Required', 'pirate-forms'))), 'pirateformsopt_subject_field' => array(__('Subject', 'pirate-forms'), __('Do you want the subject field be displayed?', 'pirate-forms'), 'select', 'req', array('' => __('None', 'pirate-forms'), 'yes' => __('Yes but not required', 'pirate-forms'), 'req' => __('Required', 'pirate-forms'))), 'pirateformsopt_message_field' => array(__('Message', 'pirate-forms'), '', 'select', 'req', array('' => __('None', 'pirate-forms'), 'yes' => __('Yes but not required', 'pirate-forms'), 'req' => __('Required', 'pirate-forms'))), 'pirateformsopt_recaptcha_field' => array(__('Add a reCAPTCHA', 'pirate-forms'), '', 'checkbox', $pirate_forms_contactus_recaptcha_show), 'pirateformsopt_recaptcha_sitekey' => array(__('Site key', 'pirate-forms'), '<a href="https://www.google.com/recaptcha/admin#list" target="_blank">' . __('Create an account here ', 'pirate-forms') . '</a>' . __('to get the Site key and the Secret key for the reCaptcha.', 'pirate-forms'), 'text', $pirate_forms_contactus_sitekey), 'pirateformsopt_recaptcha_secretkey' => array(__('Secret key', 'pirate-forms'), '', 'text', $pirate_forms_contactus_secretkey)), 'second_tab' => array('header_labels' => array(__('Fields Labels', 'pirate-forms'), '', 'title', ''), 'pirateformsopt_label_name' => array(__('Name', 'pirate-forms'), '', 'text', __('Your Name', 'pirate-forms')), 'pirateformsopt_label_email' => array(__('Email', 'pirate-forms'), '', 'text', __('Your Email', 'pirate-forms')), 'pirateformsopt_label_subject' => array(__('Subject', 'pirate-forms'), '', 'text', __('Subject', 'pirate-forms')), 'pirateformsopt_label_message' => array(__('Message', 'pirate-forms'), '', 'text', __('Your message', 'pirate-forms')), 'pirateformsopt_label_submit_btn' => array(__('Submit button', 'pirate-forms'), '', 'text', $pirate_forms_contactus_button_label)), 'third_tab' => array('header_messages' => array(__('Alert Messages', 'pirate-forms'), '', 'title', ''), 'pirateformsopt_label_err_name' => array(__('Name required and missing', 'pirate-forms'), '', 'text', __('Enter your name', 'pirate-forms')), 'pirateformsopt_label_err_email' => array(__('E-mail required and missing', 'pirate-forms'), '', 'text', __('Enter a valid email', 'pirate-forms')), 'pirateformsopt_label_err_subject' => array(__('Subject required and missing', 'pirate-forms'), '', 'text', __('Please enter a subject', 'pirate-forms')), 'pirateformsopt_label_err_no_content' => array(__('Question/comment is missing', 'pirate-forms'), '', 'text', __('Enter your question or comment', 'pirate-forms')), 'pirateformsopt_label_submit' => array(__('Successful form submission text', 'pirate-forms'), __('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.', 'pirate-forms'), 'text', __('Thanks, your email was sent successfully!', 'pirate-forms'))), 'fifth_tab' => array('header_smtp' => array(__('SMTP Options', 'pirate-forms'), '', 'title', ''), 'pirateformsopt_use_smtp' => array(__('Use SMTP to send emails?', 'pirate-forms'), __('Instead of PHP mail function', 'pirate-forms'), 'checkbox', ''), 'pirateformsopt_smtp_host' => array(__('SMTP Host', 'pirate-forms'), '', 'text', ''), 'pirateformsopt_smtp_port' => array(__('SMTP Port', 'pirate-forms'), '', 'text', ''), 'pirateformsopt_use_smtp_authentication' => array(__('Use SMTP Authentication?', 'pirate-forms'), __('If you check this box, make sure the SMTP Username and SMTP Password are completed.', 'pirate-forms'), 'checkbox', 'yes'), 'pirateformsopt_smtp_username' => array(__('SMTP Username', 'pirate-forms'), '', 'text', ''), 'pirateformsopt_smtp_password' => array(__('SMTP Password', 'pirate-forms'), '', 'text', '')));
}
function pirate_forms_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['pirate_forms_contact_errors'] = array();
    // If nonce is not valid, beat it
    if (!wp_verify_nonce($_POST['wordpress-nonce'], get_bloginfo('admin_email'))) {
        $_SESSION['pirate_forms_contact_errors']['nonce'] = __('Nonce failed!', 'pirate-forms');
        return false;
    }
    // If the honeypot caught a bear, beat it
    if (!empty($_POST['honeypot'])) {
        $_SESSION['pirate_forms_contact_errors']['honeypot'] = __('Form submission failed!', 'pirate-forms');
        return false;
    }
    // Start the body of the contact email
    $body = "*** " . __('Contact form submission on', 'pirate-forms') . " " . get_bloginfo('name') . " (" . site_url() . ") *** \n\n";
    /***********************************************/
    /*********   Sanitize and validate name *******/
    /**********************************************/
    $pirate_forms_contact_name = isset($_POST['pirate-forms-contact-name']) ? sanitize_text_field(trim($_POST['pirate-forms-contact-name'])) : '';
    // if name is required and is missing
    if (pirate_forms_get_key('pirateformsopt_name_field') === 'req' && empty($pirate_forms_contact_name)) {
        $_SESSION['pirate_forms_contact_errors']['pirate-forms-contact-name'] = pirate_forms_get_key('pirateformsopt_label_err_name');
    } elseif (!empty($pirate_forms_contact_name)) {
        $body .= stripslashes(pirate_forms_get_key('pirateformsopt_label_name')) . ": {$pirate_forms_contact_name} \r";
    }
    /***********************************************/
    /*******  Sanitize and validate email **********/
    /***********************************************/
    $pirate_forms_contact_email = isset($_POST['pirate-forms-contact-email']) ? sanitize_email($_POST['pirate-forms-contact-email']) : '';
    // If required, is it valid?
    if (pirate_forms_get_key('pirateformsopt_email_field') === 'req' && !filter_var($pirate_forms_contact_email, FILTER_VALIDATE_EMAIL)) {
        $_SESSION['pirate_forms_contact_errors']['pirate-forms-contact-email'] = pirate_forms_get_key('pirateformsopt_label_err_email');
    } elseif (!empty($pirate_forms_contact_email)) {
        $body .= stripslashes(pirate_forms_get_key('pirateformsopt_label_email')) . ": {$pirate_forms_contact_email} \r";
    }
    /***********************************************/
    /*********   Sanitize and validate subject *****/
    /**********************************************/
    $pirate_forms_contact_subject = isset($_POST['pirate-forms-contact-subject']) ? sanitize_text_field(trim($_POST['pirate-forms-contact-subject'])) : '';
    // if subject is required and is missing
    if (pirate_forms_get_key('pirateformsopt_subject_field') === 'req' && empty($pirate_forms_contact_subject)) {
        $_SESSION['pirate_forms_contact_errors']['pirate-forms-contact-subject'] = pirate_forms_get_key('pirateformsopt_label_err_subject');
    } elseif (!empty($pirate_forms_contact_subject)) {
        $body .= stripslashes(pirate_forms_get_key('pirateformsopt_label_subject')) . ": {$pirate_forms_contact_subject} \r";
    }
    /***********************************************/
    /*********   Sanitize and validate message *****/
    /**********************************************/
    $pirate_forms_contact_message = isset($_POST['pirate-forms-contact-message']) ? sanitize_text_field(trim($_POST['pirate-forms-contact-message'])) : '';
    // if message is required and is missing
    if (pirate_forms_get_key('pirateformsopt_message_field') === 'req' && empty($pirate_forms_contact_message)) {
        $_SESSION['pirate_forms_contact_errors']['pirate-forms-contact-message'] = pirate_forms_get_key('pirateformsopt_label_err_message');
    } elseif (!empty($pirate_forms_contact_message)) {
        $body .= stripslashes(pirate_forms_get_key('pirateformsopt_label_message')) . ": {$pirate_forms_contact_message} \r";
    }
    /*************************************************/
    /************* Validate reCAPTCHA ****************/
    /*************************************************/
    $pirateformsopt_recaptcha_sitekey = pirate_forms_get_key('pirateformsopt_recaptcha_sitekey');
    $pirateformsopt_recaptcha_secretkey = pirate_forms_get_key('pirateformsopt_recaptcha_secretkey');
    $pirateformsopt_recaptcha_field = pirate_forms_get_key('pirateformsopt_recaptcha_field');
    if (!empty($pirateformsopt_recaptcha_secretkey) && !empty($pirateformsopt_recaptcha_sitekey) && !empty($pirateformsopt_recaptcha_field) && $pirateformsopt_recaptcha_field == 'yes') {
        if (isset($_POST['g-recaptcha-response'])) {
            $captcha = $_POST['g-recaptcha-response'];
        }
        if (!$captcha) {
            $_SESSION['pirate_forms_contact_errors']['pirate-forms-captcha'] = __('Wrong reCAPTCHA', 'pirate-forms');
        }
        $response = wp_remote_get("https://www.google.com/recaptcha/api/siteverify?secret=" . $pirateformsopt_recaptcha_secretkey . "&response=" . $captcha . "&remoteip=" . $_SERVER['REMOTE_ADDR']);
        if (!empty($response)) {
            $response_body = wp_remote_retrieve_body($response);
        }
        if (!empty($response_body)) {
            $result = json_decode($response_body, true);
        }
        if (isset($result['success']) && $result['success'] == false) {
            $_SESSION['pirate_forms_contact_errors']['pirate-forms-captcha'] = __('Wrong reCAPTCHA', 'pirate-forms');
        }
    }
    /************************************************/
    /********** Validate recipients email ***********/
    /************************************************/
    $site_recipients = sanitize_text_field(pirate_forms_get_key('pirateformsopt_email_recipients'));
    if (empty($site_recipients)) {
        $_SESSION['pirate_forms_contact_errors']['pirate-forms-recipients-email'] = __('Please enter one or more Contact submission recipients', 'pirate-forms');
    }
    /**********************************************/
    /********   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 IP search: http://whatismyipaddress.com/ip/{$contact_ip} \n\n";
    }
    // Sanitize and prepare referrer;
    if (!empty($_POST['pirate-forms-contact-referrer'])) {
        $body .= "Came from: " . sanitize_text_field($_POST['pirate-forms-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 = pirate_forms_get_blacklist();
    if (!empty($blocked)) {
        if (in_array($pirate_forms_contact_email, $blocked) || in_array($contact_ip, $blocked)) {
            $_SESSION['pirate_forms_contact_errors']['blacklist-blocked'] = __('Form submission blocked!', 'pirate-forms');
            return false;
        }
    }
    // No errors? Go ahead and process the contact
    if (empty($_SESSION['pirate_forms_contact_errors'])) {
        $site_email = sanitize_email(pirate_forms_get_key('pirateformsopt_email'));
        $site_name = htmlspecialchars_decode(get_bloginfo('name'));
        // Notification recipients
        $site_recipients = sanitize_text_field(pirate_forms_get_key('pirateformsopt_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($pirate_forms_contact_name)) {
            $pirate_forms_contact_name = !empty($pirate_forms_contact_email) ? $pirate_forms_contact_email : '[None given]';
        }
        // Need an email address for the email notification
        if (!empty($site_email)) {
            $send_from = $site_email;
        } else {
            $send_from = pirate_forms_from_email();
        }
        $send_from_name = $site_name;
        // Sent an email notification to the correct address
        $headers = "From: {$send_from_name} <{$send_from}>\r\nReply-To: {$pirate_forms_contact_name} <{$pirate_forms_contact_email}>";
        add_action('phpmailer_init', 'pirate_forms_phpmailer');
        function pirate_forms_phpmailer($phpmailer)
        {
            $pirateformsopt_use_smtp = pirate_forms_get_key('pirateformsopt_use_smtp');
            $pirateformsopt_smtp_host = pirate_forms_get_key('pirateformsopt_smtp_host');
            $pirateformsopt_smtp_port = pirate_forms_get_key('pirateformsopt_smtp_port');
            $pirateformsopt_smtp_username = pirate_forms_get_key('pirateformsopt_smtp_username');
            $pirateformsopt_smtp_password = pirate_forms_get_key('pirateformsopt_smtp_password');
            $pirateformsopt_use_smtp_authentication = pirate_forms_get_key('pirateformsopt_use_smtp_authentication');
            if (!empty($pirateformsopt_use_smtp) && $pirateformsopt_use_smtp == 'yes' && !empty($pirateformsopt_smtp_host) && !empty($pirateformsopt_smtp_port)) {
                $phpmailer->isSMTP();
                $phpmailer->Host = $pirateformsopt_smtp_host;
                if (!empty($pirateformsopt_use_smtp_authentication) && $pirateformsopt_use_smtp_authentication == 'yes' && !empty($pirateformsopt_smtp_username) && !empty($pirateformsopt_smtp_password)) {
                    $phpmailer->SMTPAuth = true;
                    // Force it to use Username and Password to authenticate
                    $phpmailer->Port = $pirateformsopt_smtp_port;
                    $phpmailer->Username = $pirateformsopt_smtp_username;
                    $phpmailer->Password = $pirateformsopt_smtp_password;
                }
            }
        }
        wp_mail($site_recipients, 'Contact on ' . $site_name, $body, $headers);
        // Should a confirm email be sent?
        $confirm_body = stripslashes(trim(pirate_forms_get_key('pirateformsopt_confirm_email')));
        if (!empty($confirm_body) && !empty($pirate_forms_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($pirate_forms_contact_email, pirate_forms_get_key('pirateformsopt_label_submit') . ' - ' . $site_name, $confirm_body, $headers);
        }
        /************************************************************/
        /*************   Store the entries in the DB ****************/
        /************************************************************/
        if (pirate_forms_get_key('pirateformsopt_store') === 'yes') {
            $new_post_id = wp_insert_post(array('post_type' => 'pf_contact', 'post_title' => date('l, M j, Y', time()) . ' by "' . $pirate_forms_contact_name . '"', 'post_content' => $body, 'post_author' => 1, 'post_status' => 'private'));
            if (isset($pirate_forms_contact_email) && !empty($pirate_forms_contact_email)) {
                add_post_meta($new_post_id, 'Contact email', $pirate_forms_contact_email);
            }
        }
        $redirect = $_SERVER["HTTP_REFERER"] . (strpos($_SERVER["HTTP_REFERER"], '?') === FALSE ? '?' : '&') . 'pcf=1#contact';
        wp_safe_redirect($redirect);
    }
}
function pirate_forms_process_contact()
{
    // If POST and honeypot are not set, beat it
    if (empty($_POST) || !isset($_POST['honeypot'])) {
        return false;
    }
    // Session variable for form errors
    $_SESSION['pirate_forms_contact_errors'] = array();
    // If nonce is not valid, beat it
    if ('yes' === pirate_forms_get_key('pirateformsopt_nonce')) {
        if (!wp_verify_nonce($_POST['wordpress-nonce'], get_bloginfo('admin_email'))) {
            $_SESSION['pirate_forms_contact_errors']['nonce'] = __('Nonce failed!', 'pirate-forms');
            return false;
        }
    }
    // If the honeypot caught a bear, beat it
    if (!empty($_POST['honeypot'])) {
        $_SESSION['pirate_forms_contact_errors']['honeypot'] = __('Form submission failed!', 'pirate-forms');
        return false;
    }
    // Start the body of the contact email
    $body = "*** " . __('Contact form submission from', 'pirate-forms') . " " . get_bloginfo('name') . " (" . site_url() . ") *** \n\n";
    /***********************************************/
    /*********   Sanitize and validate name *******/
    /**********************************************/
    $pirate_forms_contact_name = isset($_POST['pirate-forms-contact-name']) ? sanitize_text_field(trim($_POST['pirate-forms-contact-name'])) : '';
    // if name is required and is missing
    if (pirate_forms_get_key('pirateformsopt_name_field') === 'req' && empty($pirate_forms_contact_name)) {
        $_SESSION['pirate_forms_contact_errors']['pirate-forms-contact-name'] = pirate_forms_get_key('pirateformsopt_label_err_name');
    } elseif (!empty($pirate_forms_contact_name)) {
        $body .= stripslashes(pirate_forms_get_key('pirateformsopt_label_name')) . ": {$pirate_forms_contact_name} \r";
    }
    /***********************************************/
    /*******  Sanitize and validate email **********/
    /***********************************************/
    $pirate_forms_contact_email = isset($_POST['pirate-forms-contact-email']) ? sanitize_email($_POST['pirate-forms-contact-email']) : '';
    // If required, is it valid?
    if (pirate_forms_get_key('pirateformsopt_email_field') === 'req' && !filter_var($pirate_forms_contact_email, FILTER_VALIDATE_EMAIL)) {
        $_SESSION['pirate_forms_contact_errors']['pirate-forms-contact-email'] = pirate_forms_get_key('pirateformsopt_label_err_email');
    } elseif (!empty($pirate_forms_contact_email)) {
        $body .= stripslashes(pirate_forms_get_key('pirateformsopt_label_email')) . ": {$pirate_forms_contact_email} \r";
    }
    /***********************************************/
    /*********   Sanitize and validate subject *****/
    /**********************************************/
    $pirate_forms_contact_subject = isset($_POST['pirate-forms-contact-subject']) ? sanitize_text_field(trim($_POST['pirate-forms-contact-subject'])) : '';
    // if subject is required and is missing
    if (pirate_forms_get_key('pirateformsopt_subject_field') === 'req' && empty($pirate_forms_contact_subject)) {
        $_SESSION['pirate_forms_contact_errors']['pirate-forms-contact-subject'] = pirate_forms_get_key('pirateformsopt_label_err_subject');
    } elseif (!empty($pirate_forms_contact_subject)) {
        $body .= stripslashes(pirate_forms_get_key('pirateformsopt_label_subject')) . ": {$pirate_forms_contact_subject} \r";
    }
    /***********************************************/
    /*********   Sanitize and validate message *****/
    /**********************************************/
    $pirate_forms_contact_message = isset($_POST['pirate-forms-contact-message']) ? sanitize_text_field(trim($_POST['pirate-forms-contact-message'])) : '';
    // if message is required and is missing
    if (pirate_forms_get_key('pirateformsopt_message_field') === 'req' && empty($pirate_forms_contact_message)) {
        $_SESSION['pirate_forms_contact_errors']['pirate-forms-contact-message'] = pirate_forms_get_key('pirateformsopt_label_err_message');
    } elseif (!empty($pirate_forms_contact_message)) {
        $body .= stripslashes(pirate_forms_get_key('pirateformsopt_label_message')) . ": {$pirate_forms_contact_message} \r";
    }
    /*************************************************/
    /************* Validate reCAPTCHA ****************/
    /*************************************************/
    $pirateformsopt_recaptcha_sitekey = pirate_forms_get_key('pirateformsopt_recaptcha_sitekey');
    $pirateformsopt_recaptcha_secretkey = pirate_forms_get_key('pirateformsopt_recaptcha_secretkey');
    $pirateformsopt_recaptcha_field = pirate_forms_get_key('pirateformsopt_recaptcha_field');
    if (!empty($pirateformsopt_recaptcha_secretkey) && !empty($pirateformsopt_recaptcha_sitekey) && !empty($pirateformsopt_recaptcha_field) && $pirateformsopt_recaptcha_field == 'yes') {
        if (isset($_POST['g-recaptcha-response'])) {
            $captcha = $_POST['g-recaptcha-response'];
        }
        if (!$captcha) {
            $_SESSION['pirate_forms_contact_errors']['pirate-forms-captcha'] = __('Wrong reCAPTCHA', 'pirate-forms');
        }
        $response = wp_remote_get("https://www.google.com/recaptcha/api/siteverify?secret=" . $pirateformsopt_recaptcha_secretkey . "&response=" . $captcha . "&remoteip=" . $_SERVER['REMOTE_ADDR']);
        if (!empty($response)) {
            $response_body = wp_remote_retrieve_body($response);
        }
        if (!empty($response_body)) {
            $result = json_decode($response_body, true);
        }
        if (isset($result['success']) && $result['success'] == false) {
            $_SESSION['pirate_forms_contact_errors']['pirate-forms-captcha'] = __('Wrong reCAPTCHA', 'pirate-forms');
        }
    }
    /************************************************/
    /********** Validate recipients email ***********/
    /************************************************/
    $site_recipients = sanitize_text_field(pirate_forms_get_key('pirateformsopt_email_recipients'));
    if (empty($site_recipients)) {
        $_SESSION['pirate_forms_contact_errors']['pirate-forms-recipients-email'] = __('Please enter one or more Contact submission recipients', 'pirate-forms');
    }
    /**********************************************/
    /********   Sanitize and validate IP  *********/
    /**********************************************/
    $contact_ip = filter_var($_SERVER['REMOTE_ADDR'], FILTER_VALIDATE_IP);
    /* for the case of a Web server behind a reverse proxy */
    if (array_key_exists('HTTP_X_FORWARDED_FOR', $_SERVER)) {
        $contact_ip = array_pop(explode(',', $_SERVER['HTTP_X_FORWARDED_FOR']));
    }
    // If valid and present, create a link to an IP search
    if (!empty($contact_ip)) {
        $body .= __('IP address: ', 'pirate-forms') . $contact_ip . "\r " . __('IP search:', 'pirate-forms') . " http://whatismyipaddress.com/ip/{$contact_ip} \n\n";
    }
    // Sanitize and prepare referrer;
    if (!empty($_POST['pirate-forms-contact-referrer'])) {
        $body .= __('Came from: ', 'pirate-forms') . sanitize_text_field($_POST['pirate-forms-contact-referrer']) . " \r";
    }
    // Show the page this contact form was submitted on
    $body .= __('Sent from page: ', 'pirate-forms') . get_permalink(get_the_id());
    // Check the blacklist
    $blocked = pirate_forms_get_blacklist();
    if (!empty($blocked)) {
        if (in_array($pirate_forms_contact_email, $blocked) || in_array($contact_ip, $blocked)) {
            $_SESSION['pirate_forms_contact_errors']['blacklist-blocked'] = __('Form submission blocked!', 'pirate-forms');
            return false;
        }
    }
    // No errors? Go ahead and process the contact
    if (empty($_SESSION['pirate_forms_contact_errors'])) {
        $pirate_forms_options_tmp = get_option('pirate_forms_settings_array');
        if (isset($pirate_forms_options_tmp['pirateformsopt_email'])) {
            $site_email = $pirate_forms_options_tmp['pirateformsopt_email'];
        }
        if (!empty($pirate_forms_contact_name)) {
            $site_name = $pirate_forms_contact_name;
        } else {
            $site_name = htmlspecialchars_decode(get_bloginfo('name'));
        }
        // Notification recipients
        $site_recipients = sanitize_text_field(pirate_forms_get_key('pirateformsopt_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($pirate_forms_contact_name)) {
            $pirate_forms_contact_name = !empty($pirate_forms_contact_email) ? $pirate_forms_contact_email : '[None given]';
        }
        // Need an email address for the email notification
        if (!empty($site_email)) {
            if ($site_email == '[email]') {
                if (!empty($pirate_forms_contact_email)) {
                    $send_from = $pirate_forms_contact_email;
                } else {
                    $send_from = pirate_forms_from_email();
                }
            } else {
                $send_from = $site_email;
            }
        } else {
            $send_from = pirate_forms_from_email();
        }
        $send_from_name = $site_name;
        // Sent an email notification to the correct address
        $headers = "From: {$send_from_name} <{$send_from}>\r\nReply-To: {$pirate_forms_contact_name} <{$pirate_forms_contact_email}>";
        add_action('phpmailer_init', 'pirate_forms_phpmailer');
        function pirate_forms_phpmailer($phpmailer)
        {
            $pirateformsopt_use_smtp = pirate_forms_get_key('pirateformsopt_use_smtp');
            $pirateformsopt_smtp_host = pirate_forms_get_key('pirateformsopt_smtp_host');
            $pirateformsopt_smtp_port = pirate_forms_get_key('pirateformsopt_smtp_port');
            $pirateformsopt_smtp_username = pirate_forms_get_key('pirateformsopt_smtp_username');
            $pirateformsopt_smtp_password = pirate_forms_get_key('pirateformsopt_smtp_password');
            $pirateformsopt_use_smtp_authentication = pirate_forms_get_key('pirateformsopt_use_smtp_authentication');
            if (!empty($pirateformsopt_use_smtp) && $pirateformsopt_use_smtp == 'yes' && !empty($pirateformsopt_smtp_host) && !empty($pirateformsopt_smtp_port)) {
                $phpmailer->isSMTP();
                $phpmailer->Host = $pirateformsopt_smtp_host;
                if (!empty($pirateformsopt_use_smtp_authentication) && $pirateformsopt_use_smtp_authentication == 'yes' && !empty($pirateformsopt_smtp_username) && !empty($pirateformsopt_smtp_password)) {
                    $phpmailer->SMTPAuth = true;
                    // Force it to use Username and Password to authenticate
                    $phpmailer->Port = $pirateformsopt_smtp_port;
                    $phpmailer->Username = $pirateformsopt_smtp_username;
                    $phpmailer->Password = $pirateformsopt_smtp_password;
                }
            }
        }
        /*******************************************/
        /********* Validate Attachment *************/
        /*******************************************/
        $attachments = '';
        $pirate_forms_attach_file = isset($_FILES['pirate-forms-attachment']) ? $_FILES['pirate-forms-attachment'] : '';
        if (!empty($pirate_forms_attach_file) && !empty($pirate_forms_attach_file['name'])) {
            /* Validate file type */
            $pirate_forms_file_types_allowed = 'jpg|jpeg|png|gif|pdf|doc|docx|ppt|pptx|odt|avi|ogg|m4a|mov|mp3|mp4|mpg|wav|wmv';
            $pirate_forms_file_types_allowed = trim($pirate_forms_file_types_allowed, '|');
            $pirate_forms_file_types_allowed = '(' . $pirate_forms_file_types_allowed . ')';
            $pirate_forms_file_types_allowed = '/\\.' . $pirate_forms_file_types_allowed . '$/i';
            if (!preg_match($pirate_forms_file_types_allowed, $pirate_forms_attach_file['name'])) {
                $_SESSION['pirate_forms_contact_errors']['pirate-forms-upload-failed-type'] = __('Uploaded file is not allowed for file type', 'pirate-forms');
            }
            /* Validate file size */
            $pirate_forms_file_size_allowed = 1048576;
            // default size 1 MB
            if ($pirate_forms_attach_file['size'] > $pirate_forms_file_size_allowed) {
                $_SESSION['pirate_forms_contact_errors']['pirate-forms-upload-failed-size'] = __('Uploaded file is too large', 'pirate-forms');
            }
            pirate_forms_init_uploads();
            $uploads_dir = pirate_forms_upload_tmp_dir();
            $uploads_dir = pirate_forms_maybe_add_random_dir($uploads_dir);
            $filename = $pirate_forms_attach_file['name'];
            $filename = pirate_forms_canonicalize($filename);
            $filename = sanitize_file_name($filename);
            $filename = pirate_forms_antiscript_file_name($filename);
            $filename = wp_unique_filename($uploads_dir, $filename);
            $new_file = trailingslashit($uploads_dir) . $filename;
            if (false === @move_uploaded_file($pirate_forms_attach_file['tmp_name'], $new_file)) {
                $_SESSION['pirate_forms_contact_errors']['pirate-forms-upload-failed-general'] = __('There was an unknown error uploading the file.', 'pirate-forms');
            }
            // Make sure the uploaded file is only readable for the owner process
            @chmod($new_file, 0400);
            if (!empty($new_file)) {
                $attachments = $new_file;
            }
        }
        wp_mail($site_recipients, 'Contact on ' . htmlspecialchars_decode(get_bloginfo('name')), $body, $headers, $attachments);
        // Should a confirm email be sent?
        $confirm_body = stripslashes(trim(pirate_forms_get_key('pirateformsopt_confirm_email')));
        if (!empty($confirm_body) && !empty($pirate_forms_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($pirate_forms_contact_email, pirate_forms_get_key('pirateformsopt_label_submit') . ' - ' . $site_name, $confirm_body, $headers);
        }
        /************************************************************/
        /*************   Store the entries in the DB ****************/
        /************************************************************/
        if (pirate_forms_get_key('pirateformsopt_store') === 'yes') {
            $new_post_id = wp_insert_post(array('post_type' => 'pf_contact', 'post_title' => date('l, M j, Y', time()) . ' by "' . $pirate_forms_contact_name . '"', 'post_content' => $body, 'post_author' => 1, 'post_status' => 'private'));
            if (isset($pirate_forms_contact_email) && !empty($pirate_forms_contact_email)) {
                add_post_meta($new_post_id, 'Contact email', $pirate_forms_contact_email);
            }
        }
        $pirate_forms_current_theme = wp_get_theme();
        /* If a Thank you page is selected, redirect to that page */
        if (pirate_forms_get_key('pirateformsopt_thank_you_url')) {
            $redirect_id = intval(pirate_forms_get_key('pirateformsopt_thank_you_url'));
            $redirect = get_permalink($redirect_id);
            wp_safe_redirect($redirect);
        } elseif ('Zerif Lite' == $pirate_forms_current_theme->name || 'Zerif Lite' == $pirate_forms_current_theme->parent_theme || 'Zerif PRO' == $pirate_forms_current_theme->name || 'Zerif PRO' == $pirate_forms_current_theme->parent_theme) {
            $redirect = $_SERVER["HTTP_REFERER"] . (strpos($_SERVER["HTTP_REFERER"], '?') === FALSE ? '?' : '&') . 'pcf=1#contact';
            wp_safe_redirect($redirect);
        }
    }
}