function menu_page() { if (!current_user_can('manage_options')) { wp_die(__('You do not have sufficient permissions to access this page.', 'seamless-donations')); } // Data driven ftw! $template_elements = array('fromname' => array('option' => 'dgx_donate_email_name', 'label' => __('From / Reply-To Name', 'seamless-donations'), 'description' => __('The name the thank you email should appear to come from (e.g. your organization name or your name).', 'seamless-donations'), 'type' => 'text', 'cols' => 40), 'frommail' => array('option' => 'dgx_donate_email_reply', 'label' => __('From / Reply-To Email Address', 'seamless-donations'), 'description' => __('The email address the thank you email should appear to come from.', 'seamless-donations'), 'type' => 'text', 'cols' => 40), 'subject' => array('option' => 'dgx_donate_email_subj', 'label' => __('Subject', 'seamless-donations'), 'description' => __('The subject of the email (e.g. Thank You for Your Donation).', 'seamless-donations'), 'type' => 'text', 'cols' => 40), 'bodytext' => array('option' => 'dgx_donate_email_body', 'label' => __('Body', 'seamless-donations'), 'description' => __('The body of the email message to all donors.', 'seamless-donations'), 'type' => 'textarea', 'cols' => 40, 'rows' => 3), 'recurringtext' => array('option' => 'dgx_donate_email_recur', 'label' => __('Recurring Donations', 'seamless-donations'), 'description' => __('This message will be included when the donor elects to make their donation recurring.', 'seamless-donations'), 'type' => 'textarea', 'cols' => 40, 'rows' => 3), 'designatedtext' => array('option' => 'dgx_donate_email_desig', 'label' => __('Designated Fund', 'seamless-donations'), 'description' => __('This message will be included when the donor designates their donation to a specific fund.', 'seamless-donations'), 'type' => 'textarea', 'cols' => 40, 'rows' => 3), 'anonymoustext' => array('option' => 'dgx_donate_email_anon', 'label' => __('Anonymous Donations', 'seamless-donations'), 'description' => __('This message will be included when the donor requests their donation get kept anonymous.', 'seamless-donations'), 'type' => 'textarea', 'cols' => 40, 'rows' => 3), 'mailinglistjointext' => array('option' => 'dgx_donate_email_list', 'label' => __('Mailing List Join', 'seamless-donations'), 'description' => __('This message will be included when the donor elects to join the mailing list.', 'seamless-donations'), 'type' => 'textarea', 'cols' => 40, 'rows' => 3), 'employertext' => array('option' => 'dgx_donate_email_empl', 'label' => __('Employer Match', 'seamless-donations'), 'description' => __('This message will be included when the donor selects the employer match.', 'seamless-donations'), 'type' => 'textarea', 'cols' => 40, 'rows' => 3), 'tributetext' => array('option' => 'dgx_donate_email_trib', 'label' => __('Tribute Gift', 'seamless-donations'), 'description' => __('This message will be included when the donor elects to make their donation a tribute gift.', 'seamless-donations'), 'type' => 'textarea', 'cols' => 40, 'rows' => 3), 'closingtext' => array('option' => 'dgx_donate_email_close', 'label' => __('Closing', 'seamless-donations'), 'description' => __('The closing text of the email message to all donors.', 'seamless-donations'), 'type' => 'textarea', 'cols' => 40, 'rows' => 3), 'signature' => array('option' => 'dgx_donate_email_sig', 'label' => __('Signature', 'seamless-donations'), 'description' => __('The signature at the end of the email message to all donors.', 'seamless-donations'), 'type' => 'textarea', 'cols' => 40, 'rows' => 3)); // If we have form arguments, we must validate the nonce if (count($_POST)) { $nonce = $_POST['dgx_donate_template_nonce']; if (!wp_verify_nonce($nonce, 'dgx_donate_template_nonce')) { wp_die(__('You do not have sufficient permissions to access this page.', 'seamless-donations')); } // If provided, get the form arguments and save them into options foreach ((array) $template_elements as $key => $element) { if (isset($_POST[$key])) { $value = strip_tags($_POST[$key]); if ('fromname' == $key) { $value = preg_replace("/[^a-zA-Z ]+/", "", $value); // letters and spaces only please } if ('frommail' == $key) { if (!is_email($value)) { $value = get_option('admin_email'); } } update_option($element['option'], $value); $message = __('Templates updated.', 'seamless-donations'); } } // Or, if they asked for a test email, send it $test_mail = isset($_POST['testmail']) ? $_POST['testmail'] : ''; $test_mail = strip_tags($test_mail); if (!empty($test_mail)) { dgx_donate_send_thank_you_email(0, $test_mail); $message = __('Test email sent.', 'seamless-donations'); } } do_action('dgx_donate_email_template_page_load'); // Otherwise, proceed echo "<div class='wrap'>\n"; echo "<div id='icon-edit-pages' class='icon32'></div>\n"; echo "<h2>" . esc_html__('Thank You Emails', 'seamless-donations') . "</h2>\n"; // Display any message if (!empty($message)) { echo "<div id='message' class='updated below-h2'>\n"; echo "<p>" . esc_html($message) . "</p>\n"; echo "</div>\n"; } // Read in each option from the database foreach ($template_elements as &$element) { $element['value'] = stripslashes(get_option($element['option'])); } unset($element); // break the lingering reference $nonce = wp_create_nonce('dgx_donate_template_nonce'); echo "<div id='col-container'>\n"; echo "<div id='col-right'>\n"; echo "<div class='col-wrap'>\n"; echo "<h3>" . esc_html__('Email Template', 'seamless-donations') . "</h3>\n"; echo "<p>" . esc_html__('The template on this page is used to generate thank you emails for each donation.' . 'seamless-donations') . ' '; echo esc_html__('You can include placeholders such as [firstname] [lastname] [fund] and/or [amount].', 'seamless-donations') . ' '; echo esc_html__('These placeholders will automatically be filled in with the donor and donation details.', 'seamless-donations') . ' '; echo "</p>\n"; // Emit the form echo "<form method='POST' action=''>\n"; echo "<input type='hidden' name='dgx_donate_template_nonce' value='" . esc_attr($nonce) . "' />\n"; foreach ((array) $template_elements as $key => $element) { echo "<div class='form-field'>\n"; echo "<p><strong>" . esc_html($element['label']) . "</strong> - "; echo "<span class='description'>" . esc_html($element['description']) . "</span></p>"; if ('text' == $element['type']) { echo "<input type='text' name='" . esc_attr($key) . "' size='" . esc_attr($element['cols']) . "' value = '" . esc_attr($element['value']) . "' />\n"; } else { echo "<textarea style='resize: none;' name='" . esc_attr($key) . "' rows='" . esc_attr($element['rows']) . "' cols='" . esc_attr($element['cols']) . "'>" . esc_textarea($element['value']) . "</textarea>\n"; } echo "<br/><br/>"; echo "</div>\n"; } echo "<p><input class='button' type='submit' value='" . esc_attr__('Save Changes', 'seamless-donations') . "' name='submit'></p>\n"; echo "</form>"; do_action('dgx_donate_email_template_page_right'); do_action('dgx_donate_admin_footer'); echo "</div>\n"; // col-wrap echo "</div>\n"; // col-right echo "<div id='col-left'>\n"; echo "<div class='col-wrap'>\n"; echo "<h3>" . esc_html__('Send a Test Email', 'seamless-donations') . "</h3>\n"; echo "<p>" . esc_html__('Enter an email address (e.g. your own) to have a test email sent using the template.', 'seamless-donations') . "</p>\n"; echo "<form method='POST' action=''>\n"; echo "<input type='hidden' name='dgx_donate_template_nonce' value='" . esc_attr($nonce) . "' />\n"; echo "<div class='form-field'>\n"; echo "<label for='testmail'>" . esc_html__('Email Address', 'seamless-donations') . "</label>\n"; echo "<input type='text' name='testmail' size='40' />\n"; echo "<p class='description'>" . esc_html__('The email address to receive the test message.', 'seamless-donations') . "</p>\n"; echo "</div>\n"; echo "<p><input id='submit' class='button' type='submit' value='" . esc_attr__('Send Test Email', 'seamless-donations') . "' name='submit'></p>\n"; echo "</form>"; do_action('dgx_donate_email_template_page_left'); echo "</div>\n"; // col wrap echo "</div>\n"; // col left echo "</div>\n"; // col container echo "</div>\n"; // wrap }
function handle_verified_ipn() { $sd4_mode = get_option('dgx_donate_start_in_sd4_mode'); $payment_status = $this->post_data["payment_status"]; dgx_donate_debug_log("IPN VERIFIED for session ID {$this->session_id}"); dgx_donate_debug_log("PayPal reports payment status: {$payment_status}"); if ("Completed" == $payment_status) { // Check if we've already logged a transaction with this same transaction id $donation_id = get_donations_by_meta('_dgx_donate_transaction_id', $this->transaction_id, 1); if (0 == count($donation_id)) { // We haven't seen this transaction ID already // See if a donation for this session ID already exists $donation_id = get_donations_by_meta('_dgx_donate_session_id', $this->session_id, 1); if (0 == count($donation_id)) { // We haven't seen this session ID already // Retrieve the data if ($sd4_mode == false) { // retrieve from transient $donation_form_data = get_transient($this->session_id); } else { // retrieve from audit db table $donation_form_data = seamless_donations_get_audit_option($this->session_id); } if (!empty($donation_form_data)) { // Create a donation record if ($sd4_mode == false) { dgx_donate_debug_log("Creating donation from transient data in pre-4.x mode."); $donation_id = dgx_donate_create_donation_from_transient_data($donation_form_data); } else { dgx_donate_debug_log("Creating donation from transaction audit data in 4.x mode."); $donation_id = seamless_donations_create_donation_from_transient_data($donation_form_data); } dgx_donate_debug_log("Created donation {$donation_id} for session ID {$this->session_id}"); if ($sd4_mode == false) { // Clear the transient delete_transient($this->session_id); } } else { // We have a session_id but no transient (the admin might have // deleted all previous donations in a recurring donation for // some reason) - so we will have to create a donation record // from the data supplied by PayPal if ($sd4_mode == false) { $donation_id = dgx_donate_create_donation_from_paypal_data($this->post_data); dgx_donate_debug_log("Created donation {$donation_id} " . "from PayPal data (no transient data found) in pre-4.x mode."); } else { $donation_id = seamless_donations_create_donation_from_paypal_data($this->post_data); dgx_donate_debug_log("Created donation {$donation_id} " . "from PayPal data (no audit db data found) in 4.x mode."); } } } else { // We have seen this session ID already, create a new donation record for this new transaction // But first, flatten the array returned by get_donations_by_meta for _dgx_donate_session_id $donation_id = $donation_id[0]; $old_donation_id = $donation_id; if ($sd4_mode == false) { $donation_id = dgx_donate_create_donation_from_donation($old_donation_id); } else { $donation_id = seamless_donations_create_donation_from_donation($old_donation_id); } dgx_donate_debug_log("Created donation {$donation_id} (recurring donation, donor data copied from donation {$old_donation_id}"); } } else { // We've seen this transaction ID already - ignore it $donation_id = ''; dgx_donate_debug_log("Transaction ID {$this->transaction_id} already handled - ignoring"); } if (!empty($donation_id)) { // Update the raw paypal data update_post_meta($donation_id, '_dgx_donate_transaction_id', $this->transaction_id); update_post_meta($donation_id, '_dgx_donate_payment_processor', 'PAYPALSTD'); update_post_meta($donation_id, '_dgx_donate_payment_processor_data', $this->post_data); // save the currency of the transaction $currency_code = $this->post_data['mc_currency']; dgx_donate_debug_log("Payment currency = {$currency_code}"); update_post_meta($donation_id, '_dgx_donate_donation_currency', $currency_code); } // @todo - send different notification for recurring? // Send admin notification dgx_donate_send_donation_notification($donation_id); // Send donor notification dgx_donate_send_thank_you_email($donation_id); } }
function validate_page_slug_seamless_donations_admin_templates_callback($_submitted_array, $_existing_array, $_setup_object) { $_submitted_array = apply_filters('validate_page_slug_seamless_donations_admin_templates_callback', $_submitted_array, $_existing_array, $_setup_object); $section = seamless_donations_get_submitted_admin_section($_submitted_array); switch ($section) { case 'seamless_donations_admin_templates_section_test': // SAVE EMAILS // $test_mail = $_submitted_array[$section]['email_test_address']; $test_mail = sanitize_email($test_mail); if (!is_email($test_mail)) { // check address $_aErrors[$section]['email_test_address'] = __('Valid email address required.', 'seamless-donations'); $_setup_object->setFieldErrors($_aErrors); $_setup_object->setSettingNotice(__('There were errors in your submission.', 'seamless-donations')); return $_existing_array; } dgx_donate_send_thank_you_email(0, $test_mail); $_setup_object->setSettingNotice('Test email sent.', 'updated'); break; case 'seamless_donations_admin_templates_section_template': // SAVE TEMPLATE // // check email address $email = $_submitted_array[$section]['dgx_donate_email_reply']; $email = sanitize_email($email); if (!is_email($email)) { $_aErrors[$section]['dgx_donate_paypal_email'] = __('Valid email address required.', 'seamless-donations'); $_setup_object->setFieldErrors($_aErrors); $_setup_object->setSettingNotice(__('There were errors in your submission.', 'seamless-donations')); return $_existing_array; } // check array fields for clean and not-empty for ($i = 0; $i < count($_submitted_array[$section]); ++$i) { $key = seamless_donations_name_of($_submitted_array[$section], $i); $value = trim($_submitted_array[$section][$key]); $value = wp_kses_post($value); if ($key == 'submit') { continue; // not a text field } if ($key == 'dgx_donate_email_reply') { continue; // already tested for validation } if ($value == "") { $_aErrors[$section][$key] = __('This field must not be empty.', 'seamless-donations'); $_setup_object->setFieldErrors($_aErrors); $_setup_object->setSettingNotice(__('There were errors in your submission.', 'seamless-donations')); return $_existing_array; } } // save array fields as clean, sanitized options for ($i = 0; $i < count($_submitted_array[$section]); ++$i) { $key = seamless_donations_name_of($_submitted_array[$section], $i); $value = trim($_submitted_array[$section][$key]); if ($key == 'dgx_donate_email_reply') { $value = sanitize_email($value); } else { $value = wp_kses_post($value); } if ($key == 'submit') { continue; // not a text field } update_option($key, $value); } $_setup_object->setSettingNotice('Form updated successfully.', 'updated'); break; case 'seamless_donations_admin_templates_section_extension': // LET EXTENSIONS DO THE PROCESSING break; default: $_setup_object->setSettingNotice(__('There was an unexpected error in your entry.', 'seamless-donations')); } }