Skip to content

Commit

Permalink
more code dedup
Browse files Browse the repository at this point in the history
  • Loading branch information
liedekef committed Oct 7, 2024
1 parent 7cbf55d commit e8fdde7
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 58 deletions.
24 changes: 3 additions & 21 deletions eme-gdpr.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,7 @@ function eme_rpi_ajax() {
$email = eme_sanitize_email( $_POST['eme_email'] );
// check if email is found, if so: send the gdpr url
if ( eme_count_persons_by_email( $email ) > 0 ) {
$contact_email = get_option( 'eme_mail_sender_address' );
$contact_name = get_option( 'eme_mail_sender_name' );
if ( empty( $contact_email ) ) {
$contact = eme_get_contact();
$contact_email = $contact->user_email;
$contact_name = $contact->display_name;
}
[$contact_name, $contact_email] = eme_get_default_mailer_info();
$gdpr_link = eme_gdpr_url( $email );
$gdpr_subject = eme_translate( get_option( 'eme_gdpr_subject' ) );
$gdpr_body = eme_translate( get_option( 'eme_gdpr_body' ) );
Expand Down Expand Up @@ -172,13 +166,7 @@ function eme_gdpr_approve_ajax() {
$email = eme_sanitize_email( $_POST['eme_email'] );
// check if email is found, if so: send the gdpr url
if ( eme_count_persons_by_email( $email ) > 0 ) {
$contact_email = get_option( 'eme_mail_sender_address' );
$contact_name = get_option( 'eme_mail_sender_name' );
if ( empty( $contact_email ) ) {
$contact = eme_get_contact();
$contact_email = $contact->user_email;
$contact_name = $contact->display_name;
}
[$contact_name, $contact_email] = eme_get_default_mailer_info();
$gdpr_link = eme_gdpr_approve_url( $email );
$gdpr_subject = eme_translate( get_option( 'eme_gdpr_approve_subject' ) );
$gdpr_body = eme_translate( get_option( 'eme_gdpr_approve_body' ) );
Expand Down Expand Up @@ -255,13 +243,7 @@ function eme_cpi_request_ajax() {
$mail_text_html = get_option( 'eme_mail_send_html' ) ? 'htmlmail' : 'text';
$person_ids = eme_get_personids_by_email( $email );
if ( ! empty( $person_ids ) ) {
$contact_email = get_option( 'eme_mail_sender_address' );
$contact_name = get_option( 'eme_mail_sender_name' );
if ( empty( $contact_email ) ) {
$contact = eme_get_contact();
$contact_email = $contact->user_email;
$contact_name = $contact->display_name;
}
[$contact_name, $contact_email] = eme_get_default_mailer_info();
$change_subject = eme_translate( get_option( 'eme_cpi_subject' ) );
$change_body = eme_translate( get_option( 'eme_cpi_body' ) );
if ( $mail_text_html == 'htmlmail' ) {
Expand Down
18 changes: 2 additions & 16 deletions eme-mailer.php
Original file line number Diff line number Diff line change
Expand Up @@ -1558,15 +1558,7 @@ function eme_send_mails_ajax_actions( $action ) {
$contact_name = eme_sanitize_request( $_POST['generic_mail_from_name'] );
$contact_email = eme_sanitize_request( $_POST['generic_mail_from_email'] );
} else {
$contact_email = get_option( 'eme_mail_sender_address' );
$contact_name = get_option( 'eme_mail_sender_name' );
if ( ! eme_is_email( $contact_email ) ) {
$contact = eme_get_contact();
$contact_email = $contact->user_email;
$contact_name = $contact->display_name;
}
$contact_name = eme_sanitize_request( $contact_name );
$contact_email = eme_sanitize_request( $contact_email );
[$contact_name, $contact_email] = eme_get_default_mailer_info();
}

if ( empty( $contact_email ) ) {
Expand Down Expand Up @@ -1961,13 +1953,7 @@ function eme_emails_page() {
#$attachment_ids = '';
#$attach_url_string = '';

$generic_mail_from_email = get_option( 'eme_mail_sender_address' );
$generic_mail_from_name = get_option( 'eme_mail_sender_name' );
if ( ! eme_is_email( $generic_mail_from_email ) ) {
$contact = eme_get_contact();
$generic_mail_from_email = $contact->user_email;
$generic_mail_from_name = $contact->display_name;
}
[$generic_mail_from_name, $generic_mail_from_email] = eme_get_default_mailer_info();

$peoplegroups = eme_get_groups();
$membergroups = eme_get_membergroups();
Expand Down
24 changes: 3 additions & 21 deletions eme-people.php
Original file line number Diff line number Diff line change
Expand Up @@ -3073,13 +3073,7 @@ function eme_people_birthday_emails() {

$mail_text_html = get_option( 'eme_mail_send_html' ) ? 'htmlmail' : 'text';

$contact_email = get_option( 'eme_mail_sender_address' );
$contact_name = get_option( 'eme_mail_sender_name' );
if ( empty( $contact_email ) ) {
$contact = eme_get_contact();
$contact_email = $contact->user_email;
$contact_name = $contact->display_name;
}
[$contact_name, $contact_email] = eme_get_default_mailer_info();

$subject_template = get_option( 'eme_bd_email_subject' );
$body_template = eme_translate( get_option( 'eme_bd_email_body' ) );
Expand Down Expand Up @@ -4731,13 +4725,7 @@ function eme_unsubform_shortcode( $atts = [] ) {
}

function eme_sub_send_mail( $lastname, $firstname, $email, $groups ) {
$contact_email = get_option( 'eme_mail_sender_address' );
$contact_name = get_option( 'eme_mail_sender_name' );
if ( empty( $contact_email ) ) {
$contact = eme_get_contact();
$contact_email = $contact->user_email;
$contact_name = $contact->display_name;
}
[$contact_name, $contact_email] = eme_get_default_mailer_info();
$sub_link = eme_sub_confirm_url( $lastname, $firstname, $email, $groups );
$sub_subject = eme_translate( get_option( 'eme_sub_subject' ) );
$sub_body = eme_translate( get_option( 'eme_sub_body' ) );
Expand All @@ -4753,13 +4741,7 @@ function eme_unsub_send_mail( $email, $groupids ) {
// find persons with matching email in the mentioned groups
$person_id = eme_get_person_by_email_in_groups( $email, $groupids );
if ( ! empty( $person_id ) ) {
$contact_email = get_option( 'eme_mail_sender_address' );
$contact_name = get_option( 'eme_mail_sender_name' );
if ( empty( $contact_email ) ) {
$contact = eme_get_contact();
$contact_email = $contact->user_email;
$contact_name = $contact->display_name;
}
[$contact_name, $contact_email] = eme_get_default_mailer_info();
$unsub_link = eme_unsub_confirm_url( $email, $groupids );
$unsub_subject = get_option( 'eme_unsub_subject' );
$unsub_body = eme_translate( get_option( 'eme_unsub_body' ) );
Expand Down

0 comments on commit e8fdde7

Please sign in to comment.