Skip to content

Commit 1e80873

Browse files
timiwahalahtirenintw
authored andcommitted
send copy of call for speakers email to the speaker itself
1 parent fda9498 commit 1e80873

File tree

1 file changed

+102
-7
lines changed

1 file changed

+102
-7
lines changed

‎public_html/wp-content/plugins/wordcamp-forms-to-drafts/wordcamp-forms-to-drafts.php

+102-7
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,16 @@ class WordCamp_Forms_To_Drafts {
2222
* Constructor
2323
*/
2424
public function __construct() {
25-
add_action( 'wp_print_styles', array( $this, 'print_front_end_styles' ) );
26-
add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_inert_script' ) );
27-
add_filter( 'the_content', array( $this, 'force_login_to_use_form' ), 8 );
28-
add_action( 'template_redirect', array( $this, 'populate_form_based_on_user' ), 9 );
29-
add_action( 'grunion_pre_message_sent', array( $this, 'call_for_sponsors' ), 10, 3 );
30-
add_action( 'grunion_pre_message_sent', array( $this, 'call_for_speakers' ), 10, 3 );
31-
add_action( 'grunion_pre_message_sent', array( $this, 'call_for_volunteers' ), 10, 3 );
25+
add_action( 'wp_print_styles', array( $this, 'print_front_end_styles' ) );
26+
add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_inert_script' ) );
27+
add_filter( 'the_content', array( $this, 'force_login_to_use_form' ), 8 );
28+
add_action( 'template_redirect', array( $this, 'populate_form_based_on_user' ), 9 );
29+
add_action( 'grunion_pre_message_sent', array( $this, 'call_for_sponsors' ), 10, 3 );
30+
add_action( 'grunion_pre_message_sent', array( $this, 'call_for_speakers' ), 10, 3 );
31+
add_action( 'grunion_pre_message_sent', array( $this, 'call_for_volunteers' ), 10, 3 );
32+
add_filter( 'jetpack_contact_form_email_headers', array( $this, 'maybe_modify_email_headers' ), 10, 4 );
33+
add_filter( 'contact_form_subject', array( $this, 'maybe_modify_email_subject' ), 10, 2 );
34+
add_filter( 'contact_form_message', array( $this, 'maybe_modify_email_message' ), 10, 2 );
3235
}
3336

3437
/**
@@ -250,6 +253,17 @@ protected function get_form_key( $submission_id ) {
250253
return $key;
251254
}
252255

256+
/**
257+
* Help identify the form by key.
258+
*
259+
* @param int $form_id
260+
*
261+
* @return string | false
262+
*/
263+
protected function get_form_key_by_id( $form_id ) {
264+
return get_post_meta( $form_id, 'wcfd-key', true );
265+
}
266+
253267
/**
254268
* Get a user's ID based on their username.
255269
*
@@ -415,6 +429,87 @@ public function call_for_volunteers( $submission_id, $all_values, $extra_values
415429
}
416430
}
417431

432+
/**
433+
* Modify the email headers for cases where copy needs to be send for submitter.
434+
*
435+
* At least at the moment, Jetpack handles headers as a string.
436+
*
437+
* We can use $_POST['contact-form-id'] without nonce verification as at this point Jetpack has already taken care if it.
438+
*
439+
* @param string|array $headers Email headers.
440+
* @param string $comment_author Name of the author of the submitted feedback, if provided in form.
441+
* @param string $reply_to_addr Email of the author of the submitted feedback, if provided in form.
442+
* @param string|array $to Array of valid email addresses, or single email address, where the form is sent.
443+
*
444+
* @return string|array Email headers.
445+
*/
446+
public function maybe_modify_email_headers( $headers, $comment_author, $reply_to_addr, $to ) {
447+
// Get the key from submitted data.
448+
$form_key = $this->get_form_key_by_id( absint( $_POST['contact-form-id'] ) ); // phpcs:ignore WordPress.Security.NonceVerification.Missing
449+
450+
// Add speaker as a copy on the email.
451+
if ( 'call-for-speakers' === $form_key ) {
452+
$headers .= "Cc: {$reply_to_addr}\r\n";
453+
}
454+
455+
return $headers;
456+
}
457+
458+
/**
459+
* Modify the email subject for cases where more information is needed.
460+
*
461+
* We can use $_POST['contact-form-id'] without nonce verification as at this point Jetpack has already taken care if it.
462+
*
463+
* @param string $subject Feedback's subject line.
464+
* @param array $all_values Feedback's data from old fields.
465+
*
466+
* @return string Email subject line.
467+
*/
468+
public function maybe_modify_email_subject( $subject, $all_values ) {
469+
$form_key = $this->get_form_key_by_id( absint( $_POST['contact-form-id'] ) ); // phpcs:ignore WordPress.Security.NonceVerification.Missing
470+
// Add the site name and topic title on email subject.
471+
if ( 'call-for-speakers' === $form_key ) {
472+
$all_values = $this->get_unprefixed_grunion_form_values( $all_values );
473+
474+
/* translators: %1$s: site name; %2$s: topic title on submission; */
475+
$subject = sprintf(
476+
__( 'Your %1$s Call for Speakers submission: %2$s', 'wordcamporg' ),
477+
get_bloginfo( 'name' ),
478+
sanitize_text_field( $all_values['Topic Title'] )
479+
);
480+
}
481+
482+
return $subject;
483+
}
484+
485+
/**
486+
* Modify the email message for cases where more information is needed.
487+
*
488+
* We can use $_POST['contact-form-id'] without nonce verification as at this point Jetpack has already taken care if it.
489+
*
490+
* @param string $message Feedback email message.
491+
* @param array $message_array Feedback email message as an array.
492+
*
493+
* @return string Email message.
494+
*/
495+
public function maybe_modify_email_message( $message, $message_array ) {
496+
$form_key = $this->get_form_key_by_id( absint( $_POST['contact-form-id'] ) ); // phpcs:ignore WordPress.Security.NonceVerification.Missing
497+
498+
// Modify the message to thank you and note about organizers getting back.
499+
if ( 'call-for-speakers' === $form_key ) {
500+
$wordcamp = get_wordcamp_post();
501+
502+
/* translators: %1$s: email address for organizing team; %2$s: original message; */
503+
$message = sprintf(
504+
__( 'Hello,<br><br>Thank you for submitting on Call for Speakers! Here is an copy of your submission.<br/><br/>Please do not respond to this email, organizers will update you on the process. If you have any questions, send an email to organisers %1$s.<br/>%2$s', 'wordcamporg' ),
505+
$wordcamp->meta['E-mail Address'][0],
506+
$message
507+
);
508+
}
509+
510+
return $message;
511+
}
512+
418513
/**
419514
* Get speaker post based on WordPress.org user name
420515
*

0 commit comments

Comments
 (0)