Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add new condition for organizer reminder #1328

Merged
merged 11 commits into from
Jun 3, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ public function test_timed_messages_sent( $send_when, $send_when_period, $send_w
'post_status' => $wordcamp_post_status,
) );

if ( in_array( $send_when, array( 'wcor_send_before', 'wcor_send_after', 'wcor_send_after_and_no_report' ) ) ) {
if ( in_array( $send_when, array( 'wcor_send_before', 'wcor_send_after' ) ) ) {
update_post_meta( self::$wordcamp_dayton_post_id, 'Start Date (YYYY-mm-dd)', $compare_date );
} elseif ( 'wcor_send_after_pending' === $send_when ) {
update_post_meta( self::$wordcamp_dayton_post_id, '_timestamp_added_to_planning_schedule', $compare_date );
Expand Down Expand Up @@ -235,15 +235,6 @@ public function data_timed_messages_sent() {
strtotime( 'now - 3 days' ),
'wcpt-scheduled',
),

// After the camp ends and no transparency report is received.
array(
'wcor_send_after_and_no_report',
'wcor_send_days_after_and_no_report',
3,
strtotime( 'now - 3 days' ),
'wcpt-scheduled',
),
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,11 @@
<th><input id="wcor_send_organizers" name="wcor_send_where[]" type="checkbox" value="wcor_send_organizers" <?php checked( in_array( 'wcor_send_organizers', $send_where ) ); ?>></th>
<td colspan="2"><label for="wcor_send_organizers">The organizing team</label>
<br>
(Will send to
<span>(Will send to
1. <code>[email protected]</code>
2. If specified, the email address under WordCamp Information section on WordCamp edit page
3. If specified, the email address of the lead organizer)
</span>
</td>
</tr>

Expand Down Expand Up @@ -122,6 +123,11 @@

<table>
<tbody>
<tr>
<th><input id="wcor_transparency_report" name="wcor_transparency_report" type="checkbox" value="wcor_transparency_report" <?php checked( $post->wcor_transparency_report, 'wcor_transparency_report' ); ?>></th>
<td><label for="wcor_transparency_report">For transparency report - triggered when <strong>NOT</strong> 'Running money through WPCS PBC'</label></td>
</tr>

<tr>
<th><input id="wcor_send_before" name="wcor_send_when" type="radio" value="wcor_send_before" <?php checked( $post->wcor_send_when, 'wcor_send_before' ); ?>></th>
<td><label for="wcor_send_before">before the camp starts: </label></td>
Expand Down Expand Up @@ -149,15 +155,6 @@
</td>
</tr>

<tr>
<th><input id="wcor_send_after_and_no_report" name="wcor_send_when" type="radio" value="wcor_send_after_and_no_report" <?php checked( $post->wcor_send_when, 'wcor_send_after_and_no_report' ); ?>></th>
<td><label for="wcor_send_after_and_no_report">after the camp ends and no transparency report is received: </label></td>
<td>
<input id="wcor_send_days_after_and_no_report" name="wcor_send_days_after_and_no_report" type="text" class="small-text" value="<?php echo esc_attr( $post->wcor_send_days_after_and_no_report ); ?>" />
<label for="wcor_send_days_after_and_no_report">days</label>
</td>
</tr>

<tr>
<th><input id="wcor_send_trigger" name="wcor_send_when" type="radio" value="wcor_send_trigger" <?php checked( $post->wcor_send_when, 'wcor_send_trigger' ); ?>></th>
<td><label for="wcor_send_trigger">on a trigger: </label></td>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -535,7 +535,7 @@ public function send_timed_emails() {
'meta_query' => array(
array(
'key' => 'wcor_send_when',
'value' => array( 'wcor_send_before', 'wcor_send_after', 'wcor_send_after_pending', 'wcor_send_after_and_no_report' ),
'value' => array( 'wcor_send_before', 'wcor_send_after', 'wcor_send_after_pending' ),
'compare' => 'IN'
),
),
Expand Down Expand Up @@ -595,6 +595,15 @@ protected function timed_email_is_ready_to_send( $wordcamp, $email, $sent_email_
return $ready;
}

/**
* Do not send emails if it's for transparency report and the camp is running money through WPCS PBC.
*/
$transparency_report = get_post_meta( $email->ID, 'wcor_transparency_report', true );
$through_wpcs_pbc = get_post_meta( $wordcamp->ID, 'Running money through WPCS PBC', true );
if ( $transparency_report && $through_wpcs_pbc ) {
return $ready;
}

$send_when = get_post_meta( $email->ID, 'wcor_send_when', true );
$start_date = get_post_meta( $wordcamp->ID, 'Start Date (YYYY-mm-dd)', true );
$end_date = get_post_meta( $wordcamp->ID, 'End Date (YYYY-mm-dd)', true );
Expand All @@ -618,13 +627,25 @@ protected function timed_email_is_ready_to_send( $wordcamp, $email, $sent_email_
* Do not send emails with "send X days after the camp ends" trigger if WordCamp didn't happen.
* All WordCamps that happen, should have public status.
*/
if ( in_array( $wordcamp->post_status, WordCamp_Loader::get_public_post_statuses() ) ) {
$days_after = absint( get_post_meta( $email->ID, 'wcor_send_days_after', true ) );
if ( ! in_array( $wordcamp->post_status, WordCamp_Loader::get_public_post_statuses() ) ) {
return $ready;
}

$days_after = absint( get_post_meta( $email->ID, 'wcor_send_days_after', true ) );

if ( $end_date && $days_after ) {
$send_date = $end_date + ( $days_after * DAY_IN_SECONDS );
if ( $end_date && $days_after ) {
$send_date = $end_date + ( $days_after * DAY_IN_SECONDS );

if ( $send_date <= current_time( 'timestamp' ) ) {
if ( $send_date <= current_time( 'timestamp' ) ) {
/**
* If this reminder is for transparency report, only send if the report hasn't been received yet.
*/
if ( $transparency_report ) {
$report_received = get_post_meta( $wordcamp->ID, 'Transparency Report Received', true );
if ( ! $report_received ) {
$ready = true;
}
} else {
$ready = true;
}
}
Expand All @@ -636,17 +657,6 @@ protected function timed_email_is_ready_to_send( $wordcamp, $email, $sent_email_
if ( $days_after_pending && $timestamp_added_to_pending_schedule ) {
$execution_timestamp = $timestamp_added_to_pending_schedule + ( $days_after_pending * DAY_IN_SECONDS );

if ( $execution_timestamp <= current_time( 'timestamp' ) ) {
$ready = true;
}
}
} elseif ( 'wcor_send_after_and_no_report' == $send_when ) {
$days_after_and_no_report = absint( get_post_meta( $email->ID, 'wcor_send_days_after_and_no_report', true ) );
$report_received = get_post_meta( $wordcamp->ID, 'Transparency Report Received', true );

if ( $end_date && $days_after_and_no_report && ! $report_received ) {
$execution_timestamp = $end_date + ( $days_after_and_no_report * DAY_IN_SECONDS );

if ( $execution_timestamp <= current_time( 'timestamp' ) ) {
$ready = true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,11 +194,16 @@ protected function save_post_meta( $post, $new_meta ) {
}

if ( isset( $new_meta['wcor_send_when'] ) ) {
if ( in_array( $new_meta['wcor_send_when'], array( 'wcor_send_before', 'wcor_send_after', 'wcor_send_after_pending', 'wcor_send_after_and_no_report', 'wcor_send_trigger' ) ) ) {
if ( in_array( $new_meta['wcor_send_when'], array( 'wcor_send_before', 'wcor_send_after', 'wcor_send_after_pending', 'wcor_send_trigger' ) ) ) {
update_post_meta( $post->ID, 'wcor_send_when', $new_meta['wcor_send_when'] );
}
}

delete_post_meta( $post->ID, 'wcor_transparency_report' );
if ( isset( $new_meta['wcor_transparency_report'] ) ) {
update_post_meta( $post->ID, 'wcor_transparency_report', sanitize_text_field( $new_meta['wcor_transparency_report'] ) );
}

if ( isset( $new_meta['wcor_send_days_before'] ) ) {
update_post_meta( $post->ID, 'wcor_send_days_before', absint( $new_meta['wcor_send_days_before'] ) );
}
Expand All @@ -211,10 +216,6 @@ protected function save_post_meta( $post, $new_meta ) {
update_post_meta( $post->ID, 'wcor_send_days_after_pending', absint( $new_meta['wcor_send_days_after_pending'] ) );
}

if ( isset( $new_meta['wcor_send_days_after_and_no_report'] ) ) {
update_post_meta( $post->ID, 'wcor_send_days_after_and_no_report', absint( $new_meta['wcor_send_days_after_and_no_report'] ) );
}

if ( isset( $new_meta['wcor_which_trigger'] ) ) {
if ( in_array( $new_meta['wcor_which_trigger'], array_merge( array( 'null' ), array_keys( $GLOBALS['WCOR_Mailer']->triggers ) ) ) ) {
update_post_meta( $post->ID, 'wcor_which_trigger', $new_meta['wcor_which_trigger'] );
Expand Down
Loading