@@ -39,6 +39,28 @@ function ccgn_close_update_details_applicant($applicant_id)
39
39
$ delete = wp_delete_user ($ applicant_id );
40
40
}
41
41
42
+ function ccgn_update_details_set_first_reminder ( $ applicant_id ) {
43
+ ccgn_registration_email_update_details_first_reminder ($ applicant_id );
44
+ $ update_details_meta = array (
45
+ 'state ' => 'first-reminder ' ,
46
+ 'updated ' => 0 ,
47
+ 'date ' => date ('Y-m-d H:i:s ' , strtotime ('now ' )),
48
+ 'done ' => true
49
+ );
50
+ update_user_meta ( $ applicant_id , 'ccgn_applicant_update_details_state ' , $ update_details_meta );
51
+ }
52
+
53
+ function ccgn_update_details_set_second_reminder ( $ applicant_id ) {
54
+ ccgn_registration_email_update_details_second_reminder ($ applicant_id );
55
+ $ update_details_meta = array (
56
+ 'state ' => 'second-reminder ' ,
57
+ 'updated ' => 0 ,
58
+ 'date ' => date ('Y-m-d H:i:s ' , strtotime ('now ' )),
59
+ 'done ' => true
60
+ );
61
+ update_user_meta ($ applicant_id , 'ccgn_applicant_update_details_state ' , $ update_details_meta );
62
+ }
63
+
42
64
// Send reminders to those that need them
43
65
44
66
function ccgn_email_update_details_reminders ()
@@ -49,10 +71,15 @@ function ccgn_email_update_details_reminders()
49
71
);
50
72
foreach ($ applicants as $ applicant_id ) {
51
73
$ status = get_user_meta ($ applicant_id , 'ccgn_applicant_update_details_state ' , true );
52
- $ days_in_state = ccgn_days_since_state_set ($ applicant_id , $ now );
74
+ $ state_date = new DateTime ($ status ['date ' ]);
75
+ $ days_in_state = $ state_date ->diff ($ now )->days ;
53
76
if ($ days_in_state > CCGN_CLOSE_UPDATE_DETAILS_AFTER_DAYS ) {
54
77
if ( ($ status ['state ' ] == 'second-reminder ' ) && ($ status ['done ' ]) ) {
55
78
ccgn_close_update_details_applicant ($ applicant_id );
79
+ } elseif ( $ status ['state ' ] == 'none ' ) {
80
+ ccgn_update_details_set_first_reminder ($ applicant_id );
81
+ } elseif ( $ status ['state ' ] == 'first-reminder ' ) {
82
+ ccgn_update_details_set_second_reminder ($ applicant_id );
56
83
} else {
57
84
//update user status date
58
85
update_user_meta (
@@ -64,26 +91,12 @@ function ccgn_email_update_details_reminders()
64
91
} elseif ( ($ days_in_state > CCGN_FIRST_REMINDER_UPDATE_DETAILS_AFTER_DAYS ) && ($ days_in_state <= CCGN_SECOND_REMINDER_UPDATE_DETAILS_AFTER_DAYS ) ) {
65
92
// Send first reminder
66
93
if (empty ($ status ['state ' ])) {
67
- ccgn_registration_email_update_details_first_reminder ($ applicant_id );
68
- $ update_details_meta = array (
69
- 'state ' => 'first-reminder ' ,
70
- 'updated ' => 0 ,
71
- 'date ' => date ('Y-m-d H:i:s ' , strtotime ('now ' )),
72
- 'done ' => true
73
- );
74
- update_user_meta ( $ applicant_id , 'ccgn_applicant_update_details_state ' , $ update_details_meta );
94
+ ccgn_update_details_set_first_reminder ($ applicant_id );
75
95
}
76
96
} elseif ( ($ days_in_state > CCGN_SECOND_REMINDER_UPDATE_DETAILS_AFTER_DAYS ) && ($ days_in_state <= CCGN_CLOSE_UPDATE_DETAILS_AFTER_DAYS ) ) {
77
97
// Send second reminder
78
98
if (($ status ['state ' ] == 'first-reminer ' ) && ($ status ['done ' ])) {
79
- ccgn_registration_email_update_details_second_reminder ($ applicant_id );
80
- $ update_details_meta = array (
81
- 'state ' => 'second-reminder ' ,
82
- 'updated ' => 0 ,
83
- 'date ' => date ('Y-m-d H:i:s ' , strtotime ('now ' )),
84
- 'done ' => true
85
- );
86
- update_user_meta ($ applicant_id , 'ccgn_applicant_update_details_state ' , $ update_details_meta );
99
+ ccgn_update_details_set_second_reminder ($ applicant_id );
87
100
}
88
101
}
89
102
}
@@ -103,4 +116,4 @@ function ccgn_schedule_email_upate_details_reminders()
103
116
function ccgn_schedule_remove_email_update_details_reminders ()
104
117
{
105
118
wp_clear_scheduled_hook ('ccgn_email_update_details_reminders_event ' );
106
- }
119
+ }
0 commit comments