Exemplo n.º 1
0
function validate_page_slug_seamless_donations_admin_forms_callback($_submitted_array, $_existing_array, $_setup_object)
{
    $_submitted_array = apply_filters('validate_page_slug_seamless_donations_admin_forms_callback', $_submitted_array, $_existing_array, $_setup_object);
    $section = seamless_donations_get_submitted_admin_section($_submitted_array);
    switch ($section) {
        case 'seamless_donations_admin_forms_section_levels':
            // SAVE LEVELS //
            $none_enabled = true;
            $giving_levels = dgx_donate_get_giving_levels();
            foreach ($giving_levels as $giving_level) {
                if ($_submitted_array[$section]['giving_levels'][$giving_level]) {
                    dgx_donate_enable_giving_level($giving_level);
                    $none_enabled = false;
                } else {
                    dgx_donate_disable_giving_level($giving_level);
                }
            }
            if ($none_enabled) {
                $_aErrors[$section]['giving_levels'] = __('At least one giving level is required.', 'seamless-donations');
                $_setup_object->setFieldErrors($_aErrors);
                $_setup_object->setSettingNotice(__('There were errors in your submission.', 'seamless-donations'));
                return $_existing_array;
            }
            $_setup_object->setSettingNotice('Form updated successfully.', 'updated');
            break;
        case 'seamless_donations_admin_forms_section_defaults':
            // SAVE DEFAULTS //
            update_option('dgx_donate_currency', $_submitted_array[$section]['dgx_donate_currency']);
            update_option('dgx_donate_default_country', $_submitted_array[$section]['dgx_donate_default_country']);
            $_setup_object->setSettingNotice('Form updated successfully.', 'updated');
            break;
        case 'seamless_donations_admin_forms_section_fields':
            // SAVE FIELDS //
            update_option('dgx_donate_show_designated_funds_section', $_submitted_array[$section]['dgx_donate_show_designated_funds_section']);
            update_option('dgx_donate_show_repeating_option', $_submitted_array[$section]['dgx_donate_show_repeating_option']);
            update_option('dgx_donate_show_tribute_section', $_submitted_array[$section]['dgx_donate_show_tribute_section']);
            update_option('dgx_donate_show_employer_section', $_submitted_array[$section]['dgx_donate_show_employer_section']);
            update_option('dgx_donate_show_donor_telephone_field', $_submitted_array[$section]['dgx_donate_show_donor_telephone_field']);
            update_option('dgx_donate_show_donor_employer_field', $_submitted_array[$section]['dgx_donate_show_donor_employer_field']);
            update_option('dgx_donate_show_donor_occupation_field', $_submitted_array[$section]['dgx_donate_show_donor_occupation_field']);
            update_option('dgx_donate_show_mailing_list_option', $_submitted_array[$section]['dgx_donate_show_mailing_list_option']);
            update_option('dgx_donate_show_anonymous_option', $_submitted_array[$section]['dgx_donate_show_anonymous_option']);
            update_option('dgx_donate_show_donor_address_fields', $_submitted_array[$section]['dgx_donate_show_donor_address_fields']);
            $_setup_object->setSettingNotice('Form updated successfully.', 'updated');
            break;
        case 'seamless_donations_admin_forms_section_tweaks':
            // SAVE TWEAKS //
            update_option('dgx_donate_labels_for_input', $_submitted_array[$section]['dgx_donate_labels_for_input']);
            $_setup_object->setSettingNotice('Form updated successfully.', 'updated');
            break;
        case 'seamless_donations_admin_forms_section_extension':
            // LET EXTENSIONS DO THE PROCESSING
            break;
        default:
            $_setup_object->setSettingNotice(__('There was an unexpected error in your entry.', 'seamless-donations'));
    }
}
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]);
    }
}