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

UR-1049 profile details updated email to user #603

Merged
merged 5 commits into from
Oct 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions includes/admin/settings/class-ur-settings-email.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ public function __construct() {

$this->emails['UR_Settings_Profile_Details_Changed_Email'] = include 'emails/class-ur-settings-profile-details-changed-email.php';

$this->emails['UR_Settings_Profile_Details_Updated_Email'] = include 'emails/class-ur-settings-profile-details-updated-email.php';

$this->emails = apply_filters( 'user_registration_email_classes', $this->emails );
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
<?php
/**
* Configure User Email
*
* @package UR_Settings_Profile_Details_Updated_Email Class
* @since 3.0.5
*/

if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly.
}

if ( ! class_exists( 'UR_Settings_Profile_Details_Updated_Email', false ) ) :

/**
* UR_Settings_Profile_Details_Updated_Email Class.
*/
class UR_Settings_Profile_Details_Updated_Email {

/**
* Constructor.
*/
public function __construct() {
$this->id = 'profile_details_updated_email';
$this->title = __( 'Profile Details Updated Email', 'user-registration' );
$this->description = __( 'Email sent to the user when a user changed their profile information', 'user-registration' );
}

/**
* Get settings
*
* @return array
*/
public function get_settings() {

$settings = apply_filters(
'user_registration_profile_details_updated_email',
array(
'title' => __( 'Emails', 'user-registration' ),
'sections' => array(
'profile_details_updated_email' => array(
'title' => __( 'Profile Details Updated Email', 'user-registration' ),
'type' => 'card',
'desc' => '',
'back_link' => ur_back_link( __( 'Return to emails', 'user-registration' ), admin_url( 'admin.php?page=user-registration-settings&tab=email' ) ),
'preview_link' => ur_email_preview_link(
__( 'Preview', 'user-registration' ),
$this->id
),
'settings' => array(
array(
'title' => __( 'Enable this email', 'user-registration' ),
'desc' => __( 'Enable this email sent to the user when a user updated their profile information.', 'user-registration' ),
'id' => 'user_registration_enable_profile_details_changed_email',
'default' => 'false',
'type' => 'toggle',
'autoload' => false,
),
array(
'title' => __( 'Email Subject', 'user-registration' ),
'desc' => __( 'The email subject you want to customize.', 'user-registration' ),
'id' => 'user_registration_profile_details_updated_email_subject',
'type' => 'text',
'default' => __( 'Profile Details Updated Email: {{blog_info}}', 'user-registration' ),
'css' => 'min-width: 350px;',
'desc_tip' => true,
),
array(
'title' => __( 'Email Content', 'user-registration' ),
'desc' => __( 'The email content you want to customize.', 'user-registration' ),
'id' => 'user_registration_profile_details_Updated_email',
'type' => 'tinymce',
'default' => $this->ur_get_profile_details_updated_email(),
'css' => 'min-width: 350px;',
'desc_tip' => true,
),
),
),
),
)
);

return apply_filters( 'user_registration_get_settings_' . $this->id, $settings );
}

/**
* Email Message to be send to admin while profile detail changed.
*
* @return string message
*/
public function ur_get_profile_details_updated_email() {

$message = apply_filters(
'user_registration_profile_details_updated_email_message',
sprintf(
__(
'Your profile details have been successfully updated on {{blog_info}}.<br/>


{{all_fields}}
<br/>
Thank You!',
'user-registration'
)
)
);

return $message;
}
}
endif;

return new UR_Settings_Profile_Details_Updated_Email();
51 changes: 50 additions & 1 deletion includes/class-ur-emailer.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public static function init() {
__CLASS__,
'ur_profile_details_changed_mail',
),
10,
8,
2
);
}
Expand Down Expand Up @@ -218,6 +218,11 @@ public static function ur_profile_details_changed_mail( $user_id, $form_id ) {
$value = implode( ',',$upload_data );
}
}

if ( 'privacy_policy' === $form_data['field_key'] && '' !== $value ) {
$value = esc_html__( 'Accepted', 'user-registration' );
}

if ( 'country' === $form_data['field_key'] && '' !== $value ) {
$country_class = ur_load_form_field_class( $form_data['field_key'] );
$countries = $country_class::get_instance()->get_country();
Expand Down Expand Up @@ -254,6 +259,7 @@ public static function ur_profile_details_changed_mail( $user_id, $form_id ) {
do_action( 'user_registration_email_send_before' );

self::send_profile_changed_email_to_admin( $email, $username, $user_id, $data_html, $name_value, $attachments );
self::send_profile_changed_email_to_user( $email, $username, $user_id, $data_html, $name_value, $attachments );

do_action( 'user_registration_email_send_after' );
}
Expand Down Expand Up @@ -591,6 +597,49 @@ public static function send_profile_changed_email_to_admin( $user_email, $userna
}
}

/**
* Trigger the email after profile details changed by user.
*
* @param string $user_email Email of the user.
* @param string $username Username of the user.
* @param int $user_id User id.
* @param string $data_html String replaced with {{all_fields}} smart tag.
* @param array $name_value Array to replace with extra fields smart tag.
* @param array $attachments Email Attachement.
* @return void
* @since 3.0.5
*/
public static function send_profile_changed_email_to_user( $user_email, $username, $user_id, $data_html, $name_value, $attachments ) {

$header = array(
'Reply-To:' . $user_email,
'Content-Type: text/html; charset=UTF-8'
);

$attachment = isset( $attachments['user'] ) ? $attachments['user'] : '';
$subject = get_option( 'user_registration_profile_details_updated_email_subject', esc_html__( 'Profile Details Updated Email: {{blog_info}}', 'user-registration' ) );
$settings = new UR_Settings_Profile_Details_Updated_Email();
$message = $settings->ur_get_profile_details_updated_email();
$message = get_option( 'user_registration_profile_details_updated_email', $message );
$form_id = ur_get_form_id_by_userid( $user_id );

$values = array(
'username' => $username,
'email' => $user_email,
'all_fields' => $data_html,
'form_id' => $form_id,
);

list( $message, $subject ) = user_registration_email_content_overrider( $form_id, $settings, $message, $subject );
$message = self::parse_smart_tags( $message, $values, $name_value );
$subject = self::parse_smart_tags( $subject, $values, $name_value );

if ( ur_option_checked( 'user_registration_enable_profile_details_updated_email', true ) ) {
$template_id = ur_get_single_post_meta( $form_id, 'user_registration_select_email_template' );
self::user_registration_process_and_send_email( $user_email, $subject, $message, $header, $attachment, $template_id );
}
}

/**
* Process smart tags for status change emails.
*
Expand Down
2 changes: 2 additions & 0 deletions wpml-config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
<key name="user_registration_reset_password_email" />
<key name="user_registration_profile_details_changed_email_subject" />
<key name="user_registration_profile_details_changed_email" />
<key name="user_registration_profile_details_updated_email_subject" />
<key name="user_registration_profile_details_Updated_email" />

<key name="user_registration_general_setting_registration_label" />
<key name="user_registration_general_setting_registration_url_options"/>
Expand Down
Loading