function seamless_donations_get_donation_section() { $donation_section = array('id' => 'dgx-donate-form-donation-section', 'class' => 'dgx-donate-form-section', 'elements' => array('donation_header' => array('type' => 'static', 'before' => '<h2>', 'after' => '</h2>', 'value' => esc_html__('Donation Information', 'seamless-donations')), 'header_desc' => array('type' => 'static', 'before' => '<p>', 'after' => '</p>', 'value' => esc_html__('I would like to make a donation in the amount of:', 'seamless-donations')))); // assemble the radio buttons for the giving levels $index = 0; $giving_levels = dgx_donate_get_giving_levels(); foreach ($giving_levels as $giving_level) { $giving_level_key = "dgx_donate_giving_level_" . $giving_level; $giving_level_option = get_option($giving_level_key); if ($giving_level_option == 'yes') { $formatted_amount = seamless_donations_get_escaped_formatted_amount($giving_level, 0); $element = array('type' => 'radio', 'group' => '_dgx_donate_amount', 'conceal' => 'other-donation-level', 'wrapper' => 'span', 'value' => $giving_level, 'prompt' => $formatted_amount); if ($index == 0) { $element['select'] = true; } if ($index > 0) { $element['class'] = 'horiz'; } $donation_section['elements'][$giving_level_key] = $element; ++$index; } } // add the "other" button and the text zone for "other" entry $donation_section['elements']['other_radio_button'] = array('type' => 'radio', 'group' => '_dgx_donate_amount', 'prompt' => esc_html__('Other', 'seamless-donations'), 'reveal' => 'other-donation-level', 'wrapper' => 'span', 'value' => 'OTHER', 'class' => 'horiz', 'id' => 'dgx-donate-other-radio'); $donation_section['elements']['_dgx_donate_user_amount'] = array('type' => 'text', 'size' => 15, 'class' => 'aftertext', 'validation' => 'currency', 'cloak' => 'other-donation-level', 'id' => '_dgx_donate_user_amount', 'before' => esc_html__('Other: ', 'seamless-donations')); // Designated Funds if (get_option('dgx_donate_show_designated_funds_section') == 'true') { // in 4.0+ funds are a custom post type, not an option array $query_args = array('orderby' => 'title', 'order' => 'asc', 'post_type' => 'funds', 'post_status' => 'publish', 'numberposts' => -1, 'meta_query' => array(array('key' => '_dgx_donate_fund_show', 'value' => 'Yes'))); $posts_array = get_posts($query_args); $fund_count = count($posts_array); if ($fund_count > 0) { // designated fund checkbox $donation_section['elements']['_dgx_donate_designated'] = array('type' => 'checkbox', 'id' => 'dgx-donate-designated', 'reveal' => 'specific-fund', 'prompt' => esc_html__("I would like to designate this donation to a specific fund", 'seamless-donations')); $options_array = array(0 => 'No fund specified'); foreach ($posts_array as $post) { $title = $post->post_title; $id = $post->ID; $options_array[$id] = $title; } $funds_section = array('elements' => array('designated_fund_label' => array('type' => 'static', 'cloak' => 'specific-fund', 'value' => esc_html__('Designated Fund: ', 'seamless-donations') . " "), '_dgx_donate_designated_fund' => array('type' => 'select', 'cloak' => 'specific-fund', 'class' => '', 'options' => $options_array))); $donation_section['funds_section'] = $funds_section; } } // Repeating donations if (get_option('dgx_donate_show_repeating_option') == 'true') { $repeating_section = array('elements' => array('_dgx_donate_repeating' => array('type' => 'checkbox', 'id' => 'dgx-donate-repeating', 'prompt' => esc_html__("I would like this donation to automatically repeat each month", 'seamless-donations'), 'before' => '<p>', 'after' => '</p>'))); $donation_section['repeating_section'] = $repeating_section; } $donation_section = apply_filters('seamless_donations_form_donation_section', $donation_section); return $donation_section; }
function dgx_donate_get_donation_section($formContent) { $output = ""; $output .= "<div class='dgx-donate-form-section' id='dgx-donate-form-donation-section'>\n"; $output .= "<h2>" . esc_html__('Donation Information', 'dgx-donate') . "</h2>\n"; $output .= "<p>" . esc_html__('I would like to make a donation in the amount of:', 'dgx-donate') . "</p>"; $output .= "<p>"; $checked = " checked=\"checked\" "; $classmod = ""; $givingLevels = dgx_donate_get_giving_levels(); foreach ($givingLevels as $givingLevel) { $key = dgx_donate_get_giving_level_key($givingLevel); if (dgx_donate_is_giving_level_enabled($givingLevel)) { $formattedAmount = dgx_donate_get_escaped_formatted_amount($givingLevel, 0); $output .= "<input {$classmod} type=\"radio\" name=\"_dgx_donate_amount\" value=\"{$givingLevel}\" {$checked} /> {$formattedAmount} "; $checked = ""; // only select the first one $classmod = " class=\"horiz\" "; // only classmod the second and higher ones } } $output .= "</p>"; $output .= "<p><input type='radio' name='_dgx_donate_amount' value='OTHER' id='dgx-donate-other-radio' />"; $output .= esc_html__('Other: ', 'dgx-donate'); $output .= "<input type=\"text\" class=\"aftertext\" id=\"dgx-donate-other-input\" name=\"_dgx_donate_user_amount\" />"; $output .= "</p>\n"; // Designated Funds if ('true' == get_option('dgx_donate_show_designated_funds_section')) { $showFundCount = 0; $fundArray = get_option('dgx_donate_designated_funds'); if (!empty($fundArray)) { ksort($fundArray); foreach ((array) $fundArray as $key => $value) { if (strcasecmp($fundArray[$key], "SHOW") == 0) { $showFundCount = $showFundCount + 1; } } } if ($showFundCount > 0) { $output .= "<p>"; $output .= "<input type='checkbox' id='dgx-donate-designated' name='_dgx_donate_designated'/>"; $output .= esc_html__("I would like to designate this donation to a specific fund", "dgx-donate"); $output .= "</p>"; $output .= "<div class='dgx-donate-form-designated-box'>"; $output .= "<p>" . esc_html__('Designated Fund: ', 'dgx-donate') . " "; $output .= "<select class='aftertext' name='_dgx_donate_designated_fund'>"; foreach ((array) $fundArray as $key => $value) { if (strcasecmp($fundArray[$key], "SHOW") == 0) { $fundName = stripslashes($key); $output .= "<option value='" . esc_attr($fundName) . "' > " . esc_html($fundName) . "</option>"; } } $output .= "</select>"; $output .= "</p>"; $output .= "</div>"; /* dgx-donate-form-designated-box */ } } // Repeating donations if ('true' == get_option('dgx_donate_show_repeating_option')) { $output .= "<p>"; $output .= "<input type='checkbox' id='dgx-donate-repeating' name='_dgx_donate_repeating'/>"; $output .= esc_html__("I would like this donation to automatically repeat each month", "dgx-donate"); $output .= "</p>"; } $output .= "</div>"; /* dgx-donate-form-section */ $formContent .= $output; return $formContent; }
function seamless_donations_admin_forms_section_levels($_setup_object) { $section_desc = 'Select one or more suggested giving levels for your donors to choose from.'; $giving_levels_section = array('section_id' => 'seamless_donations_admin_forms_section_levels', 'page_slug' => 'seamless_donations_admin_forms', 'title' => __('Giving Levels', 'seamless-donations'), 'description' => __($section_desc, 'seamless-donations')); $giving_levels_section = apply_filters('seamless_donations_admin_forms_section_levels', $giving_levels_section); $giving_levels = dgx_donate_get_giving_levels(); $giving_level_labels = array(); for ($i = 0; $i < count($giving_levels); ++$i) { $value = $giving_levels[$i]; $giving_level_labels[$value] = $value; } $giving_level_defaults = array(); for ($i = 0; $i < count($giving_levels); ++$i) { $value = $giving_levels[$i]; $giving_level_defaults[$value] = dgx_donate_is_giving_level_enabled($value); } $giving_levels_options = array(array('field_id' => 'giving_levels', 'title' => __('Display Levels', 'seamless-donations'), 'type' => 'checkbox', 'label' => $giving_level_labels, 'default' => $giving_level_defaults, 'after_label' => '<br />'), array('field_id' => 'submit', 'type' => 'submit', 'label' => __('Save Giving Levels', 'seamless-donations'))); $giving_levels_options = apply_filters('seamless_donations_admin_forms_section_levels_options', $giving_levels_options); seamless_donations_process_add_settings_fields_with_options($giving_levels_options, $_setup_object, $giving_levels_section); }
function seamless_donations_init_defaults() { // functionally identical to dgx_donate_init_defaults, but likely to change over time // Thank you email option defaults // validate name - replace with sanitized blog name if needed $from_name = get_option('dgx_donate_email_name'); if (empty($from_name)) { $from_name = get_bloginfo('name'); $from_name = preg_replace("/[^a-zA-Z ]+/", "", $from_name); // letters and spaces only please update_option('dgx_donate_email_name', $from_name); } // validate email - replace with admin email if needed $from_email = get_option('dgx_donate_email_reply'); if (empty($from_email) || !is_email($from_email)) { $from_email = get_option('admin_email'); update_option('dgx_donate_email_reply', $from_email); } $thankSubj = get_option('dgx_donate_email_subj'); if (empty($thankSubj)) { $thankSubj = "Thank you for your donation"; update_option('dgx_donate_email_subj', $thankSubj); } $bodyText = get_option('dgx_donate_email_body'); if (empty($bodyText)) { $bodyText = "Dear [firstname] [lastname],\n\n"; $bodyText .= "Thank you for your generous donation of [amount]. Please note that no goods "; $bodyText .= "or services were received in exchange for this donation."; update_option('dgx_donate_email_body', $bodyText); } $recurring_text = get_option('dgx_donate_email_recur'); if (empty($recurring_text)) { $recurring_text = __("Thank you for electing to have your donation automatically repeated each month.", 'seamless-donations'); update_option('dgx_donate_email_recur', $recurring_text); } $designatedText = get_option('dgx_donate_email_desig'); if (empty($designatedText)) { $designatedText = "Your donation has been designated to the [fund] fund."; update_option('dgx_donate_email_desig', $designatedText); } $anonymousText = get_option('dgx_donate_email_anon'); if (empty($anonymousText)) { $anonymousText = "You have requested that your donation be kept anonymous. Your name will not be revealed to the public."; update_option('dgx_donate_email_anon', $anonymousText); } $mailingListJoinText = get_option('dgx_donate_email_list'); if (empty($mailingListJoinText)) { $mailingListJoinText = "Thank you for joining our mailing list. We will send you updates from time-to-time. If "; $mailingListJoinText .= "at any time you would like to stop receiving emails, please send us an email to be "; $mailingListJoinText .= "removed from the mailing list."; update_option('dgx_donate_email_list', $mailingListJoinText); } $tributeText = get_option('dgx_donate_email_trib'); if (empty($tributeText)) { $tributeText = "You have asked to make this donation in honor of or memory of someone else. Thank you! We will notify the "; $tributeText .= "honoree within the next 5-10 business days."; update_option('dgx_donate_email_trib', $tributeText); } $employer_text = get_option('dgx_donate_email_empl'); if (empty($employer_text)) { $employer_text = "You have specified that your employer matches some or all of your donation. "; update_option('dgx_donate_email_empl', $employer_text); } $closingText = get_option('dgx_donate_email_close'); if (empty($closingText)) { $closingText = "Thanks again for your support!"; update_option('dgx_donate_email_close', $closingText); } $signature = get_option('dgx_donate_email_sig'); if (empty($signature)) { $signature = "Director of Donor Relations"; update_option('dgx_donate_email_sig', $signature); } //// PayPal defaults $notifyEmails = get_option('dgx_donate_notify_emails'); if (empty($notifyEmails)) { $notifyEmails = get_option('admin_email'); update_option('dgx_donate_notify_emails', $notifyEmails); } $paymentGateway = get_option('dgx_donate_payment_gateway'); if (empty($paymentGateway)) { update_option('dgx_donate_payment_gateway', DGXDONATEPAYPALSTD); } $payPalServer = get_option('dgx_donate_paypal_server'); if (empty($payPalServer)) { update_option('dgx_donate_paypal_server', 'LIVE'); } $paypal_email = get_option('dgx_donate_paypal_email'); if (!is_email($paypal_email)) { update_option('dgx_donate_paypal_email', ''); } // Thank you page default $thankYouText = get_option('dgx_donate_thanks_text'); if (empty($thankYouText)) { $message = "Thank you for donating! A thank you email with the details of your donation "; $message .= "will be sent to the email address you provided."; update_option('dgx_donate_thanks_text', $message); } // Giving levels default $givingLevels = dgx_donate_get_giving_levels(); $noneChecked = true; foreach ($givingLevels as $givingLevel) { $levelEnabled = dgx_donate_is_giving_level_enabled($givingLevel); if ($levelEnabled) { $noneChecked = false; } } if ($noneChecked) { // Select 1000, 500, 100, 50 by default dgx_donate_enable_giving_level(1000); dgx_donate_enable_giving_level(500); dgx_donate_enable_giving_level(100); dgx_donate_enable_giving_level(50); } // Currency $currency = get_option('dgx_donate_currency'); if (empty($currency)) { update_option('dgx_donate_currency', 'USD'); } // Country default $default_country = get_option('dgx_donate_default_country'); if (empty($default_country)) { update_option('dgx_donate_default_country', 'US'); } // State default $default_state = get_option('dgx_donate_default_state'); if (empty($default_state)) { update_option('dgx_donate_default_state', 'WA'); } // Province default $default_province = get_option('dgx_donate_default_province'); if (empty($default_province)) { update_option('dgx_donate_default_province', 'AB'); } // Show Employer match section default $show_employer_section = get_option('dgx_donate_show_employer_section'); if (empty($show_employer_section)) { update_option('dgx_donate_show_employer_section', 'false'); } // Show occupation field default $show_occupation_section = get_option('dgx_donate_show_donor_occupation_field'); if (empty($show_occupation_section)) { update_option('dgx_donate_show_donor_occupation_field', 'false'); } // Show donor employer default $show_occupation_section = get_option('dgx_donate_show_donor_employer_field'); if (empty($show_occupation_section)) { update_option('dgx_donate_show_donor_employer_field', 'false'); } // Show Tribute Gift section default $show_tribute_section = get_option('dgx_donate_show_tribute_section'); if (empty($show_tribute_section)) { update_option('dgx_donate_show_tribute_section', 'true'); } // Scripts location default $scripts_in_footer = get_option('dgx_donate_scripts_in_footer'); if (empty($scripts_in_footer)) { update_option('dgx_donate_scripts_in_footer', 'false'); } }
function seamless_donations_admin_forms_section_levels($_setup_object) { $section_desc = 'Select one or more suggested giving levels for your donors to choose from.'; // promo $feature_desc = 'Giving Level Manager customizes donation levels, assigns labels for each level.'; $feature_url = 'http://zatzlabs.com/project/seamless-donations-giving-level-manager/'; $section_desc .= seamless_donations_get_feature_promo($feature_desc, $feature_url); $giving_levels_section = array('section_id' => 'seamless_donations_admin_forms_section_levels', 'page_slug' => 'seamless_donations_admin_forms', 'title' => __('Giving Levels', 'seamless-donations'), 'description' => __($section_desc, 'seamless-donations')); $giving_levels_section = apply_filters('seamless_donations_admin_forms_section_levels', $giving_levels_section); $giving_levels = dgx_donate_get_giving_levels(); $giving_level_labels = array(); for ($i = 0; $i < count($giving_levels); ++$i) { $value = $giving_levels[$i]; $giving_level_labels[$value] = $value; } $giving_level_defaults = array(); for ($i = 0; $i < count($giving_levels); ++$i) { $value = $giving_levels[$i]; $giving_level_defaults[$value] = dgx_donate_is_giving_level_enabled($value); } $giving_levels_options = array(array('field_id' => 'giving_levels', 'title' => __('Display Levels', 'seamless-donations'), 'type' => 'checkbox', 'label' => $giving_level_labels, 'default' => $giving_level_defaults, 'after_label' => '<br />'), array('field_id' => 'submit', 'type' => 'submit', 'label' => __('Save Giving Levels', 'seamless-donations'))); $giving_levels_options = apply_filters('seamless_donations_admin_forms_section_levels_options', $giving_levels_options); seamless_donations_process_add_settings_fields_with_options($giving_levels_options, $_setup_object, $giving_levels_section); }
function dgx_donate_save_giving_levels_settings() { $noneEnabled = true; $givingLevels = dgx_donate_get_giving_levels(); foreach ($givingLevels as $givingLevel) { $key = dgx_donate_get_giving_level_key($givingLevel); if (isset($_POST[$key])) { dgx_donate_enable_giving_level($givingLevel); $noneEnabled = false; } else { dgx_donate_disable_giving_level($givingLevel); } } // If they are all disabled, at least enable the first one if ($noneEnabled) { dgx_donate_enable_giving_level($givingLevels[0]); } }
function menu_page() { if (!current_user_can('manage_options')) { wp_die(__('You do not have sufficient permissions to access this page.', 'dgx-donate')); } $form_option_whitelist = array('false', 'true', 'required'); // If we have form arguments, we must validate the nonce if (count($_POST)) { $nonce = $_POST['dgx_donate_form_options_nonce']; if (!wp_verify_nonce($nonce, 'dgx_donate_form_options_nonce')) { wp_die(__('You do not have sufficient permissions to access this page.', 'dgx-donate')); } // Save options table settings (if present) foreach ((array) $this->form_options as $form_option) { $key = $form_option['key']; $new_option_value = isset($_POST[$key]) ? $_POST[$key] : ''; if (!empty($new_option_value)) { if (in_array($new_option_value, $form_option_whitelist)) { update_option($key, $new_option_value); $message = __('Settings updated.', 'dgx-donate'); } } } // Save giving level selections (if present) $giving_levels = isset($_POST['dgx_donate_giving_levels']) ? $_POST['dgx_donate_giving_levels'] : ''; if (!empty($giving_levels)) { dgx_donate_save_giving_levels_settings(); $message = __('Settings updated.', 'dgx-donate'); } // Save currency (if present) $currency = isset($_POST['dgx_donate_currency']) ? $_POST['dgx_donate_currency'] : ''; if (!empty($currency)) { update_option('dgx_donate_currency', $currency); $message = __('Settings updated.', 'dgx-donate'); } // Save default country (if present) $default_country = isset($_POST['dgx_donate_default_country']) ? $_POST['dgx_donate_default_country'] : ''; if (!empty($default_country)) { update_option('dgx_donate_default_country', $default_country); $message = __('Settings updated.', 'dgx-donate'); } // Save default state (if present) $default_state = isset($_POST['dgx_donate_default_state']) ? $_POST['dgx_donate_default_state'] : ''; if (!empty($default_state)) { update_option('dgx_donate_default_state', $default_state); $message = __('Settings updated.', 'dgx-donate'); } // Save default province (if present) $default_province = isset($_POST['dgx_donate_default_province']) ? $_POST['dgx_donate_default_province'] : ''; if (!empty($default_province)) { update_option('dgx_donate_default_province', $default_province); $message = __('Settings updated.', 'dgx-donate'); } } // Set up a nonce $nonce = wp_create_nonce('dgx_donate_form_options_nonce'); echo "<div class='wrap'>\n"; echo "<div id='icon-edit-pages' class='icon32'></div>"; echo "<h2>" . esc_html__('Form Options', 'dgx-donate') . "</h2>"; // Display any message if (!empty($message)) { echo "<div id='message' class='updated below-h2'>"; echo "<p>" . esc_html($message) . "</p>"; echo "</div>"; } echo "<div id='col-container'>"; echo "<div id='col-right'>"; echo "<div class='col-wrap'>"; // Fields and Sections Table echo "<h3>" . esc_html__('Form Fields and Sections', 'dgx-donate') . "</h3>"; echo "<p>" . esc_html__('Choose which form fields and sections you would like to show or require.', 'dgx-donate') . "</p>"; echo "<form method='POST' action=''>"; echo "<input type='hidden' name='dgx_donate_form_options_nonce' value='" . esc_attr($nonce) . "' />"; echo "<table class='widefat'>"; echo "<tbody>"; echo "<tr>"; echo "<th>" . esc_html__('Field/Section', 'dgx-donate') . "</th>"; echo "<th style='text-align: center;'>" . esc_html__("Don't Show", 'dgx-donate') . "</th>"; echo "<th style='text-align: center;'>" . esc_html__('Show', 'dgx-donate') . "</th>"; echo "<th style='text-align: center;'>" . esc_html__('Require', 'dgx-donate') . "</th>"; echo "</tr>"; foreach ((array) $this->form_options as $form_option) { echo "<tr>"; echo "<td>" . esc_html($form_option['prompt']) . "</td>"; foreach ($form_option_whitelist as $setting) { echo "<td style='text-align: center;'>"; $key = $form_option['key']; $current_setting = get_option($key); if ('required' !== $setting || $form_option['show_require_option']) { echo "<input type='radio' name='" . esc_attr($key) . "' value='" . esc_attr($setting) . "' " . checked($current_setting, $setting, false) . " />"; } echo "</td>"; } echo "</tr>"; } echo "</tbody>"; echo "</table>"; echo "<p><input id='submit' class='button' type='submit' value='" . esc_attr__('Update', 'dgx-donate') . "' name='submit'></p>\n"; echo "</form>"; echo "<br/>"; do_action('dgx_donate_admin_footer'); echo "</div>\n"; echo "</div>\n"; echo "<div id='col-left'>\n"; echo "<div class='col-wrap'>\n"; // Giving Levels echo "<h3>" . esc_html__('Giving Levels', 'dgx-donate') . "</h3>"; echo "<p>" . esc_html__('Select one or more suggested giving levels for your donors to choose from.', 'dgx-donate') . "</p>"; echo "<form method='POST' action=''>\n"; echo "<input type='hidden' name='dgx_donate_form_options_nonce' value='" . esc_attr($nonce) . "' />\n"; echo "<input type='hidden' name='dgx_donate_giving_levels' value='1' />"; $giving_levels = dgx_donate_get_giving_levels(); foreach ($giving_levels as $giving_level) { $key = dgx_donate_get_giving_level_key($giving_level); echo "<p><input type='checkbox' name='" . esc_attr($key) . "' value='yes' "; checked(dgx_donate_is_giving_level_enabled($giving_level)); echo " />" . esc_html($giving_level) . "</p>"; } echo "<p><input id='submit' class='button' type='submit' value='" . esc_attr__('Update', 'dgx-donate') . "' name='submit' /></p>\n"; echo "</form>"; echo "<br/>"; // Currency echo "<h3>" . esc_html__('Currency', 'dgx-donate') . "</h3>"; echo "<p>" . esc_html__("Select the currency you'd like to receive donations in.", 'dgx-donate') . "</p>"; echo "<form method='POST' action=''>\n"; echo "<input type='hidden' name='dgx_donate_form_options_nonce' value='" . esc_attr($nonce) . "' />\n"; $currency = get_option('dgx_donate_currency'); echo "<p>"; echo dgx_donate_get_currency_selector('dgx_donate_currency', $currency); echo "</p>"; echo "<p><input id='submit' class='button' type='submit' value='" . esc_attr__('Update', 'dgx-donate') . "' name='submit' /></p>\n"; echo "</form>"; echo "<br/>"; // Default country/state/province for donor // jQuery will take care of hiding / showing the state and province selector based on the country code echo "<h3>" . esc_html__('Default Country / State / Province', 'dgx-donate') . "</h3>"; echo "<p>" . esc_html__('Select the default country / state / province for the donation form.', 'dgx-donate') . "</p>"; echo "<div class='dgx_donate_geography_selects'>"; echo "<form method='POST' action=''>\n"; echo "<input type='hidden' name='dgx_donate_form_options_nonce' value='" . esc_attr($nonce) . "' />\n"; $default_country = get_option('dgx_donate_default_country'); echo "<p>"; echo dgx_donate_get_country_selector('dgx_donate_default_country', $default_country); echo "</p>"; $default_state = get_option('dgx_donate_default_state'); echo "<p>"; echo dgx_donate_get_state_selector('dgx_donate_default_state', $default_state); echo "</p>"; $default_province = get_option('dgx_donate_default_province'); echo "<p>"; echo dgx_donate_get_province_selector('dgx_donate_default_province', $default_province); echo "</p>"; echo "<p><input id='submit' class='button' type='submit' value='" . esc_attr__('Update', 'dgx-donate') . "' name='submit' /></p>\n"; echo "</form>"; echo "</div>"; // dgx_donate_geography_selects echo "<br/>"; echo "</div>\n"; echo "</div>\n"; echo "</div>\n"; echo "</div>\n"; }