Ticket #690: 690.patch
File 690.patch, 8.1 KB (added by , 10 years ago) |
---|
-
wp-content/plugins/wordcamp-organizer-reminders/wcor-mailer.php
6 6 */ 7 7 class WCOR_Mailer { 8 8 public $triggers; 9 9 10 10 /** 11 11 * Constructor 12 12 */ … … 60 60 ), 61 61 ), 62 62 ); 63 63 64 64 add_action( 'wcor_send_timed_emails', array( $this, 'send_timed_emails' ) ); 65 65 66 66 foreach ( $this->triggers as $trigger_id => $trigger ) { 67 67 foreach( $trigger['actions'] as $action ) { 68 68 add_action( $action['name'], array( $this, $action['callback'] ), $action['priority'], $action['parameters'] ); … … 71 71 } 72 72 73 73 /** 74 * Schedule cron job when plugin is activated 74 * Schedule cron job when plugin is activated 75 75 */ 76 76 public function activate() { 77 77 if ( wp_next_scheduled( 'wcor_send_timed_emails' ) === false ) { … … 82 82 ); 83 83 } 84 84 } 85 85 86 86 /** 87 87 * Clear cron job when plugin is deactivated 88 88 */ … … 93 93 /** 94 94 * Wrapper for wp_mail() that customizes the subject, body and headers 95 95 * 96 * We want to make sure that replies go to support@wordcamp.org, rather than the fake address that WordPress sends from, but 96 * We want to make sure that replies go to support@wordcamp.org, rather than the fake address that WordPress sends from, but 97 97 * we don't want to be flagged as spam for forging the From header, so we set the Sender header. 98 98 * @see http://stackoverflow.com/q/4728393/450127 99 99 * … … 222 222 empty( $wordcamp_meta['Website URL'][0] ) ? 'N/A' : $wordcamp_meta['Website URL'][0], 223 223 empty( $wordcamp_meta['Contact Information'][0] ) ? 'N/A' : $wordcamp_meta['Contact Information'][0], 224 224 ); 225 225 226 226 return str_replace( $search, $replace, $content ); 227 227 } 228 228 … … 244 244 global $multi_event_sponsors; 245 245 246 246 $recipient = $multi_event_sponsors->get_sponsor_emails( $multi_event_sponsors->get_wordcamp_me_sponsors( $wordcamp_id ) ); 247 } elseif ( 'wcor_send_sponsor_wrangler' == $send_where ) { 248 249 $wordcamp_meta = get_post_custom( $wordcamp->ID ); 250 // if the Sponsor Wrangler email is empty, use the default email address 251 if ( empty( $wordcamp_meta['Sponsor Wrangler E-mail Address'][0] ) ) { 252 $recipient = $wordcamp_meta['Sponsor Wrangler E-mail Address'][0]; 253 } else { 254 $recipient = $wordcamp_meta['Email Address'][0]; 255 } 256 247 257 } else { 248 258 $email_address_key = wcpt_key_to_str( 'E-mail Address', 'wcpt_' ); 249 259 … … 290 300 291 301 return $this->mail( $recipient, $email->post_title, $email->post_content, array(), $email, $wordcamp ); 292 302 } 293 303 294 304 /** 295 305 * Send e-mails that are scheduled to go out at a specific time (e.g., 3 days before the camp) 296 306 */ … … 326 336 ), 327 337 ), 328 338 ) ); 329 339 330 340 foreach ( $wordcamps as $wordcamp ) { 331 341 $sent_email_ids = (array) get_post_meta( $wordcamp->ID, 'wcor_sent_email_ids', true ); 332 342 333 343 foreach ( $reminder_emails as $email ) { 334 344 $recipient = $this->get_recipient( $wordcamp->ID, $email->ID ); 335 345 336 346 if ( $this->timed_email_is_ready_to_send( $wordcamp, $email, $sent_email_ids ) ) { 337 347 if ( $this->mail( $recipient, $email->post_title, $email->post_content, array(), $email, $wordcamp ) ) { 338 348 $sent_email_ids[] = $email->ID; … … 356 366 * 357 367 * @todo It'd be nice to have some unit tests for this function, since there are a lot of different cases, but it seems like that might be 358 368 * hard to do because of having to mock get_post_meta(), current_time(), etc. We could pass that info in, but that doesn't seem very elegant. 359 * 369 * 360 370 * @param WP_Post $wordcamp 361 371 * @param WP_Post $email 362 372 * @param array $sent_email_ids The IDs of emails that have already been sent to the $wordcamp post … … 380 390 if ( ! in_array( $email->ID, $sent_email_ids ) ) { 381 391 if ( 'wcor_send_before' == $send_when ) { 382 392 $days_before = absint( get_post_meta( $email->ID, 'wcor_send_days_before', true ) ); 383 393 384 394 if ( $start_date && $days_before ) { 385 395 $send_date = $start_date - ( $days_before * DAY_IN_SECONDS ); 386 396 387 397 if ( $send_date <= current_time( 'timestamp' ) ) { 388 398 $ready = true; 389 399 } … … 393 403 394 404 if ( $end_date && $days_after ) { 395 405 $send_date = $end_date + ( $days_after * DAY_IN_SECONDS ); 396 406 397 407 if ( $send_date <= current_time( 'timestamp' ) ) { 398 408 $ready = true; 399 409 } … … 411 421 } 412 422 } 413 423 } 414 424 415 425 return $ready; 416 426 } 417 427 -
wp-content/plugins/wordcamp-organizer-reminders/wcor-reminder.php
52 52 'query_var' => false, 53 53 'supports' => array( 'title', 'editor', 'author', 'revisions' ), 54 54 ); 55 55 56 56 register_post_type( self::POST_TYPE_SLUG, $params ); 57 57 } 58 58 … … 91 91 $send_days_after = get_post_meta( $post->ID, 'wcor_send_days_after', true ); 92 92 $send_days_after_pending = get_post_meta( $post->ID, 'wcor_send_days_after_pending', true ); 93 93 $which_trigger = get_post_meta( $post->ID, 'wcor_which_trigger', true ); 94 94 95 95 ?> 96 96 97 97 <h4>Who should this e-mail be sent to?</h4> … … 104 104 </tr> 105 105 106 106 <tr> 107 <th><input id="wcor_send_sponsor_wrangler" name="wcor_send_where" type="radio" value="wcor_send_sponsor_wrangler" <?php checked( $send_where, 'wcor_send_sponsor_wrangler' ); ?>></th> 108 <td colspan="2"><label for="wcor_send_sponsor_wrangler">The Sponsor Wrangler</label></td> 109 </tr> 110 111 <tr> 107 112 <th><input id="wcor_send_mes" name="wcor_send_where" type="radio" value="wcor_send_mes" <?php checked( $send_where, 'wcor_send_mes' ); ?>></th> 108 113 <td colspan="2"><label for="wcor_send_mes">The WordCamp's Multi-Event Sponsors</label></td> 109 114 </tr> … … 115 120 </tr> 116 121 </tbody> 117 122 </table> 118 119 123 124 120 125 <h4>When should this e-mail be sent?</h4> 121 126 122 127 <table> … … 154 159 <td> 155 160 <select name="wcor_which_trigger"> 156 161 <option value="null" <?php selected( $which_trigger, false ); ?>></option> 157 162 158 163 <?php foreach ( $GLOBALS['WCOR_Mailer']->triggers as $trigger_id => $trigger ) : ?> 159 164 <option value="<?php echo esc_attr( $trigger_id ); ?>" <?php selected( $which_trigger, $trigger_id ); ?>><?php echo esc_html( $trigger['name'] ); ?></option> 160 165 <?php endforeach; ?> … … 326 331 327 332 /** 328 333 * Checks to make sure the conditions for saving post meta are met 329 * 334 * 330 335 * @param int $post_id 331 336 * @param object $post 332 337 */ … … 344 349 if ( ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) || ! isset( $post->ID ) || $post->post_status == 'auto-draft' ) { 345 350 return; 346 351 } 347 352 348 353 $this->save_post_meta( $post, $_POST ); 349 354 $this->send_manual_email( $post, $_POST ); 350 355 } … … 351 356 352 357 /** 353 358 * Saves the meta data for the reminder post 354 * 359 * 355 360 * @param WP_Post $post 356 361 * @param array $new_meta 357 362 */ 358 363 protected function save_post_meta( $post, $new_meta ) { 359 364 if ( isset( $new_meta['wcor_send_where'] ) ) { 360 if ( in_array( $new_meta['wcor_send_where'], array( 'wcor_send_organizers', 'wcor_send_ mes', 'wcor_send_custom' ) ) ) {365 if ( in_array( $new_meta['wcor_send_where'], array( 'wcor_send_organizers', 'wcor_send_sponsor_wrangler', 'wcor_send_mes', 'wcor_send_custom' ) ) ) { 361 366 update_post_meta( $post->ID, 'wcor_send_where', $new_meta['wcor_send_where'] ); 362 367 } 363 368 } … … 364 369 365 370 if ( isset( $new_meta['wcor_send_custom_address'] ) && is_email( $new_meta['wcor_send_custom_address'] ) ) { 366 371 update_post_meta( $post->ID, 'wcor_send_custom_address', sanitize_email( $new_meta['wcor_send_custom_address'] ) ); 367 } 368 372 } 373 369 374 if ( isset( $new_meta['wcor_send_when'] ) ) { 370 375 if ( in_array( $new_meta['wcor_send_when'], array( 'wcor_send_before', 'wcor_send_after', 'wcor_send_after_pending', 'wcor_send_trigger' ) ) ) { 371 376 update_post_meta( $post->ID, 'wcor_send_when', $new_meta['wcor_send_when'] );