forked from allendav/seamless-donations
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdgx-donate-admin.php
305 lines (256 loc) · 8.92 KB
/
dgx-donate-admin.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
<?php
/* Copyright 2013 Allen Snook (email: [email protected]) */
require_once 'admin-views/main.php';
require_once 'admin-views/donor-detail.php';
require_once 'admin-views/donation-detail.php';
require_once 'admin-views/donations.php';
require_once 'admin-views/donors.php';
require_once 'admin-views/funds.php';
require_once 'admin-views/templates.php';
require_once 'admin-views/completed.php';
require_once 'admin-views/form-options.php';
require_once 'admin-views/settings.php';
require_once 'admin-views/log.php';
require_once 'admin-views/help.php';
/******************************************************************************************************/
function dgx_donate_echo_admin_footer()
{
$pluginVersion = dgx_donate_get_version();
echo "<p class=\"dgxdonateadminfooter\">Seamless Donations $pluginVersion</p>";
}
add_action('dgx_donate_admin_footer', 'dgx_donate_echo_admin_footer');
/******************************************************************************************************/
function dgx_donate_init_defaults()
{
// Thank you email option defaults
// validate name - replace with santized 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.", 'dgx-donate' );
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', 'true' );
}
// 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 get_donations_by_meta( $meta_key, $meta_value, $count ) {
$donation_ids = array();
if ( ! empty( $meta_value ) ) {
$args = array(
'numberposts' => $count,
'post_type' => 'dgx-donation',
'meta_key' => $meta_key,
'meta_value' => $meta_value,
'orderby' => 'post_date',
'order' => 'DESC'
);
$my_donations = get_posts( $args );
foreach( $my_donations as $donation ) {
$donation_ids[] = $donation->ID;
}
}
return $donation_ids;
}
function dgx_donate_sanitize_date( $mdy_string, $default_month, $default_date, $default_year ) {
$month = $default_month;
$date = $default_date;
$year = $default_year;
if ( ! empty( $mdy_string ) ) {
// Split on m/d/y
$date_array = explode( "/", $mdy_string );
$month = $date_array[0];
$date = $date_array[1];
$year = $date_array[2];
}
if ( $month < 1 ) {
$month = 1;
}
if ( $month > 12) {
$month = 12;
}
if ( $date < 1 ) {
$date = 1;
}
if ( $date > 31 ) {
$date = 31;
}
if ( $year < 100 ) {
$year = 2000 + $year;
}
return $month . '/' . $date . '/' . $year;
}
/******************************************************************************************************/
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]);
}
}