From c35ac65975c32f98e96cde00072551c542b120f9 Mon Sep 17 00:00:00 2001 From: Moutushi Date: Tue, 30 Jun 2020 13:14:13 -0400 Subject: [PATCH 1/5] Email template settings added --- admin/class-gdpr-admin.php | 73 ++++++- admin/partials/emial_templates.php | 298 +++++++++++++++++++++++++++++ includes/class-gdpr.php | 2 + src/js/admin.js | 33 ++++ src/scss/admin.scss | 30 +++ 5 files changed, 434 insertions(+), 2 deletions(-) create mode 100755 admin/partials/emial_templates.php diff --git a/admin/class-gdpr-admin.php b/admin/class-gdpr-admin.php index 87011773..1c15fe76 100755 --- a/admin/class-gdpr-admin.php +++ b/admin/class-gdpr-admin.php @@ -77,6 +77,7 @@ public function __construct( $plugin_name, $version ) { */ public function enqueue_styles() { add_thickbox(); + wp_enqueue_style( 'wp-color-picker' ); wp_enqueue_style( $this->plugin_name, plugin_dir_url( dirname( __FILE__ ) ) . 'dist/css/admin.css', array(), $this->version, 'all' ); } @@ -87,7 +88,7 @@ public function enqueue_styles() { * @author Fernando Claussen */ public function enqueue_scripts() { - wp_enqueue_script( $this->plugin_name, plugin_dir_url( dirname( __FILE__ ) ) . 'dist/js/admin.js', array( 'jquery', 'wp-util', 'jquery-ui-sortable' ), $this->version, false ); + wp_enqueue_script( $this->plugin_name, plugin_dir_url( dirname( __FILE__ ) ) . 'dist/js/admin.js', array( 'jquery', 'wp-util', 'jquery-ui-sortable', 'wp-color-picker' ), $this->version, false ); } /** @@ -135,6 +136,12 @@ public function add_menu() { $settings_hook = add_submenu_page( $parent_slug, $menu_title, $menu_title, $capability, $menu_slug, $function ); + $menu_title = esc_html__( 'Email Templates', 'gdpr' ); + $menu_slug = 'gdpr-email-templates'; + $function = array( $this, 'email_template_page_template' ); + + $email_template_hook = add_submenu_page( $parent_slug, $menu_title, $menu_title, $capability, $menu_slug, $function ); + add_action( "load-{$requests_hook}", array( 'GDPR_Help', 'add_requests_help' ) ); add_action( "load-{$tools_hook}", array( 'GDPR_Help', 'add_tools_help' ) ); add_action( "load-{$settings_hook}", array( 'GDPR_Help', 'add_settings_help' ) ); @@ -200,7 +207,18 @@ public function register_settings() { 'gdpr_enable_privacy_bar' => 'boolval', 'gdpr_display_cookie_categories_in_bar' => 'boolval', 'gdpr_hide_from_bots' => 'boolval', - 'gdpr_reconsent_template' => 'sanitize_text_field', + 'gdpr_email_header_image_url' => 'sanitize_text_field', + 'gdpr_email_footer_text' => 'sanitize_text_field', + 'gdpr_email_base_color' => 'sanitize_text_field', + 'gdpr_email_background_color' => 'sanitize_text_field', + 'gdpr_email_body_background_color' => 'sanitize_text_field', + 'gdpr_email_body_text_color' => 'sanitize_text_field', + 'gdpr_email_from_address' => 'sanitize_text_field', + 'gdpr_email_form_name' => 'sanitize_text_field', + 'gdpr_new_request_email_subject' => 'sanitize_text_field', + 'gdpr_new_request_email_heading' => 'sanitize_text_field', + 'gdpr_new_request_additional_content' => 'sanitize_text_field', + 'gdpr_new_request_email_content_type' => 'sanitize_text_field', ); foreach ( $settings as $option_name => $sanitize_callback ) { register_setting( 'gdpr', $option_name, array( 'sanitize_callback' => $sanitize_callback ) ); @@ -319,6 +337,19 @@ public function tools_page_template() { include plugin_dir_path( __FILE__ ) . 'partials/tools.php'; } + /** + * Settings Page Template + * + * @since 2.1.0 + * @author Fernando Claussen + */ + public function email_template_page_template() { + + $pages = get_pages(); + + include plugin_dir_path( __FILE__ ) . 'partials/emial_templates.php'; + } + /** * The data markup on the access data page. * @since 1.0.0 @@ -1010,4 +1041,42 @@ public function sort_logic_for_consents_from_user_table( $query ) { } } + /** + * Save email settings + * @since 2.0.0 + * @author Moutushi Mandal + */ + public function manage_email_settings() { + + if ( empty( $_POST['gdpr_email_settings_nonce'] ) || ! wp_verify_nonce( sanitize_key( wp_unslash( $_POST['gdpr_email_settings_nonce'] ) ), 'gdpr_email_settings_action' ) ) { + wp_send_json_error( esc_html__( 'Invalid Security Token. Refresh the page and try again.', 'gdpr' ) ); + } + + $email_type = sanitize_text_field( wp_unslash( $_POST[ 'email_type' ] ) ); + + $email_subject_post_field = $email_type . '_email_subject'; + $email_subject_db_field = 'gdpr_' . $email_type . '_email_subject'; + $email_subject = sanitize_text_field( wp_unslash( $_POST[ $email_subject_post_field ] ) ); + + $email_heading_post_field = $email_type . '_email_heading'; + $email_heading_db_field = 'gdpr_' . $email_type . '_email_heading'; + $email_heading = sanitize_text_field( wp_unslash( $_POST[ $email_heading_post_field ] ) ); + + $email_additional_content_post_field = $email_type . '_additional_content'; + $email_additional_content_db_field = 'gdpr_' . $email_type . '_additional_content'; + $email_additional_content = sanitize_text_field( wp_unslash( $_POST[ $email_additional_content_post_field ] ) ); + + $email_content_type_post_field = $email_type . '_email_content_type'; + $email_content_type_db_field = 'gdpr_' . $email_type . '_email_content_type'; + $email_content_type = sanitize_text_field( wp_unslash( $_POST[ $email_content_type_post_field ] ) ); + + update_option( $email_subject_db_field, $email_subject ); + update_option( $email_heading_db_field, $email_heading ); + update_option( $email_additional_content_db_field, $email_additional_content ); + update_option( $email_content_type_db_field, $email_content_type ); + + $success_msg = esc_html( 'Your settings have been saved.', 'gdpr' ); + + wp_send_json_success( $success_msg ); + } } diff --git a/admin/partials/emial_templates.php b/admin/partials/emial_templates.php new file mode 100755 index 00000000..3918f118 --- /dev/null +++ b/admin/partials/emial_templates.php @@ -0,0 +1,298 @@ +
+

+ + + + +

+ +

+
+ + + + + + + + + + + + + + + + + + + + +
+ + + + + + +
+ + + + + + +
+ + + + + + +
+ + + + + + +
+ +
+ +
+ +

+

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + text/html + +
+ + text/html
+ + + text/html + +
+ + text/html + +
+ + text/html + +
+ + text/html + +
+ + text/html + +
+ + text/html + +
+ + text/html + +
+ + text/html +
+ text/html + +
+

+ + + + + + + + + + + +
+ + + + + + + +
+ + + + + + + +
+

+ + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + +
+ + + + + + + +
+ + + + + + + +
+ + + + + + + +
+ + + + + + + +
+ + + + + + + +
+ + +
+ + + +
diff --git a/includes/class-gdpr.php b/includes/class-gdpr.php index a19d2ca5..e65e7f96 100755 --- a/includes/class-gdpr.php +++ b/includes/class-gdpr.php @@ -222,6 +222,8 @@ private function define_admin_hooks() { add_action( 'clean_gdpr_user_request_key', array( $requests, 'clean_user_request_key' ), 10, 2 ); add_action( 'send_data_breach_emails', array( $plugin_emails, 'send_data_breach_emails' ), 10, 2 ); + + add_action( 'wp_ajax_gdpr_manage_email_settings', array( $plugin_admin, 'manage_email_settings' ) ); } /** diff --git a/src/js/admin.js b/src/js/admin.js index 8735d209..1372c7d6 100644 --- a/src/js/admin.js +++ b/src/js/admin.js @@ -314,5 +314,38 @@ $( function() { } ); } ); + + $( '.color_pick' ).wpColorPicker(); + + $( document ).on( 'click', '.show-settings', function( e ) { + e.preventDefault(); + const nextTr = $( this ).parents( 'tr' ).next( 'tr' ); + console.log( nextTr ); + nextTr.toggleClass( 'hide' ); + }); + + $( document ).on( 'submit', '.gdpr-email-settings', function( e ) { + e.preventDefault(); + const formData = new FormData( this ); + console.log( formData ); + + $.ajax( { + url: ajaxurl, + type: 'post', + data: formData, + contentType: false, + cache: false, + processData: false, + xhrFields: { + withCredentials: true + }, + success: ( response ) => { + let successDiv = '

' + response.data + '

'; + + $( '#gdpr_heading' ).after( successDiv ); + } + } ); + + }); } ); diff --git a/src/scss/admin.scss b/src/scss/admin.scss index 53339b97..fb3bdc87 100644 --- a/src/scss/admin.scss +++ b/src/scss/admin.scss @@ -220,3 +220,33 @@ } } } +.hide { + display: none; +} +.gdpr-emails { + background-color: #fff; + border: 1px solid #ccd0d4; + box-shadow: 0 1px 1px rgba(0,0,0,.04); + + thead th { + border-bottom: 1px solid #ccd0d4; + display: table-cell!important; + padding: 1em!important; + vertical-align: top; + line-height: 1.75em; + font-weight: 600; + } + tr:nth-child(odd) td { + background: #f9f9f9; + } + a { + text-decoration: none; + color: #0073aa; + transition-property: border,background,color; + transition-duration: .05s; + transition-timing-function: ease-in-out; + } + .gdpr-email-settings-table-name { + font-weight: 700; + } +} From c0e30a6ddd88c1c4d0198cb5dc89ab134b3a7790 Mon Sep 17 00:00:00 2001 From: Moutushi Date: Fri, 3 Jul 2020 11:26:09 -0400 Subject: [PATCH 2/5] Formatted complaint-request email template --- admin/class-gdpr-admin.php | 10 +- admin/partials/emial_templates.php | 134 +++++++++++++---- includes/class-gdpr-email.php | 120 ++++++++++++++- includes/compatibility-functions.php | 145 ++++++++++++++++++ public/class-gdpr-requests-public.php | 2 +- src/js/admin.js | 7 - templates/email/complaint-request.php | 52 ++++--- templates/email/email-footer.php | 56 +++++++ templates/email/email-header.php | 59 ++++++++ templates/email/email-styles.php | 205 ++++++++++++++++++++++++++ 10 files changed, 731 insertions(+), 59 deletions(-) create mode 100644 templates/email/email-footer.php create mode 100644 templates/email/email-header.php create mode 100644 templates/email/email-styles.php diff --git a/admin/class-gdpr-admin.php b/admin/class-gdpr-admin.php index 1c15fe76..29a9a09b 100755 --- a/admin/class-gdpr-admin.php +++ b/admin/class-gdpr-admin.php @@ -215,10 +215,7 @@ public function register_settings() { 'gdpr_email_body_text_color' => 'sanitize_text_field', 'gdpr_email_from_address' => 'sanitize_text_field', 'gdpr_email_form_name' => 'sanitize_text_field', - 'gdpr_new_request_email_subject' => 'sanitize_text_field', - 'gdpr_new_request_email_heading' => 'sanitize_text_field', - 'gdpr_new_request_additional_content' => 'sanitize_text_field', - 'gdpr_new_request_email_content_type' => 'sanitize_text_field', + 'gdpr_email_recipient_address' => 'sanitize_text_field', ); foreach ( $settings as $option_name => $sanitize_callback ) { register_setting( 'gdpr', $option_name, array( 'sanitize_callback' => $sanitize_callback ) ); @@ -1070,10 +1067,15 @@ public function manage_email_settings() { $email_content_type_db_field = 'gdpr_' . $email_type . '_email_content_type'; $email_content_type = sanitize_text_field( wp_unslash( $_POST[ $email_content_type_post_field ] ) ); + $email_content_post_field = $email_type . '_email_content'; + $email_content_db_field = 'gdpr_' . $email_type . '_email_content'; + $email_content = wp_kses_post( $_POST[ $email_content_post_field ] ); + update_option( $email_subject_db_field, $email_subject ); update_option( $email_heading_db_field, $email_heading ); update_option( $email_additional_content_db_field, $email_additional_content ); update_option( $email_content_type_db_field, $email_content_type ); + update_option( $email_content_db_field, $email_content ); $success_msg = esc_html( 'Your settings have been saved.', 'gdpr' ); diff --git a/admin/partials/emial_templates.php b/admin/partials/emial_templates.php index 3918f118..0bde3b03 100755 --- a/admin/partials/emial_templates.php +++ b/admin/partials/emial_templates.php @@ -6,6 +6,12 @@

@@ -23,7 +29,8 @@ - + + @@ -34,32 +41,49 @@ - + + - - + + - + + - + - - - - + + + "> + + + + "> + + + - + true, + 'media_buttons' => false, + 'textarea_name' => "{$email_type}_email_content", + 'editor_class' => 'my_custom_class', + 'textarea_rows' => 10 + ) ); + ?> @@ -86,16 +110,24 @@ - text/html + - + - text/html + + + @@ -103,7 +135,12 @@ - text/html + + + @@ -112,7 +149,10 @@ - text/html + @@ -121,7 +161,10 @@ - text/html + @@ -130,7 +173,10 @@ - text/html + @@ -139,7 +185,10 @@ - text/html + @@ -148,7 +197,10 @@ - text/html + @@ -157,7 +209,10 @@ - text/html + @@ -166,14 +221,20 @@ - text/html + - text/html + @@ -198,13 +259,30 @@ - + - + + + + + +

+ + + + + diff --git a/includes/class-gdpr-email.php b/includes/class-gdpr-email.php index 066555c0..a3392d59 100644 --- a/includes/class-gdpr-email.php +++ b/includes/class-gdpr-email.php @@ -21,6 +21,35 @@ * @author Fernando Claussen */ class GDPR_Email { + + public $emails = array(); + + /** + * Initialize the class and set its properties. + * + * @since 1.0.0 + * @param string $plugin_name The name of this plugin. + * @param string $version The version of this plugin. + * @author Moutushi + */ + public function __construct() { + + // Email Header, Footer hooks. + add_action( 'gdpr_email_header', array( $this, 'email_header' ) ); + add_action( 'gdpr_email_footer', array( $this, 'email_footer' ) ); + + } + + + /** + * Return the email classes - used in admin to load settings. + * + * @return GDPR_Email[] + */ + public function get_emails() { + return $this->emails; + } + /** * Get the email content from the correct file. * @since 1.0.0 @@ -32,6 +61,7 @@ class GDPR_Email { */ public static function get_email_content( $template_name, $args = array() ) { ob_start(); + GDPR_Templates::get_template( $template_name, $args ); return ob_get_clean(); } @@ -165,18 +195,106 @@ public static function send( $emails, $type, $args = array(), $attachments = arr $no_reply = self::get_do_not_reply_address(); $headers = array(); + foreach ( (array) $emails as $email ) { $headers[] = 'Bcc: ' . sanitize_email( $email ); } + $headers[] = 'Content-Type: ' . self::get_content_type( $type ); + + $email_subject_field = 'gdpr_' . str_replace( '-', '_', $type ) . '_email_subject'; + $subject = get_option( $email_subject_field ); + + $email_heading_field = 'gdpr_' . str_replace( '-', '_', $type ) . '_email_heading'; + $email_heading = get_option( $email_heading_field ); + + $args['email_heading'] = $email_heading; + + $email_content_field = 'gdpr_' . str_replace( '-', '_', $type ) . '_email_content'; + $email_content = get_option( $email_content_field ); + + $args['email_content'] = $email_content; $content = self::get_email_content( 'email/' . $type . '.php', $args ); return wp_mail( $no_reply, - $possible_types[ $type ], + $subject, html_entity_decode( $content, ENT_QUOTES, 'UTF-8' ), $headers, ( ! empty( $attachments ) ) ? $attachments : array() ); } + + public static function get_content_type( $type ) { + $email_content_type_field = 'gdpr_' . str_replace( '-', '_', $type ) . '_email_content_type'; + $email_content_type = get_option( $email_content_type_field ); + + switch ( $email_content_type ) { + case 'html': + $content_type = 'text/html'; + break; + default: + $content_type = 'text/plain'; + break; + } + + return apply_filters( 'gdpr_email_content_type', $content_type ); + } + + /** + * Get from name for email. + * + * @return string + */ + public function get_from_name() { + return wp_specialchars_decode( get_option( 'gdpr_email_form_name' ), ENT_QUOTES ); + } + + /** + * Get from email address. + * + * @return string + */ + public function get_from_address() { + return sanitize_email( get_option( 'gdpr_email_from_address' ) ); + } + + /** + * Get the email header. + * + * @param mixed $email_heading Heading for the email. + */ + public function email_header( $email_heading ) { + GDPR_Templates::get_template( 'email/email-header.php', array( 'email_heading' => $email_heading ) ); + } + + /** + * Get the email footer. + */ + public function email_footer() { + GDPR_Templates::get_template( 'email/email-footer.php' ); + } + + /** + * Get email content place holders + */ + public static function get_email_content_placeholders( $type ) { + $email_content_place_holders = apply_filters( + 'gdpr_email_content_place_holder', array( + 'new_request' => array( '{type}', '{review_url}' ), + 'delete_request' => array( '{confirm_url}', '{forgot_password_url}' ), + 'delete_resolved' => array( '{token}' ), + 'rectify_request' => array( '{data}', '{confirm_url}', '{forgot_password_url}' ), + 'rectify_resolved' => array(), + 'complaint_request' => array( '{data}', '{confirm_url}', '{forgot_password_url}' ), + 'complaint_resolved' => array(), + 'export_data_request' => array( '{confirm_url_xml}', '{confirm_url_json}', '{forgot_password_url}' ), + 'export_data_resolved' => array(), + 'data_breach_request' => array( '{requester}', '{nature}', '{office_contact}', '{consequences}', '{measures}', '{confirm_url}' ), + 'data_breach_notification' => array( '{content}', '{nature}', '{office_contact}', '{consequences}', '{measures}', '{confirm_url}' ), + ) + ); + + return $email_content_place_holders[$type]; + } } diff --git a/includes/compatibility-functions.php b/includes/compatibility-functions.php index c1089543..26519e72 100644 --- a/includes/compatibility-functions.php +++ b/includes/compatibility-functions.php @@ -10,3 +10,148 @@ function boolval( $var ) { return (bool) $var; } } + +/** + * Style related functions + */ + +if ( ! function_exists( 'gdpr_rgb_from_hex' ) ) { + + /** + * Convert RGB to HEX. + * + * @param mixed $color Color. + * + * @return array + */ + function gdpr_rgb_from_hex( $color ) { + $color = str_replace( '#', '', $color ); + // Convert shorthand colors to full format, e.g. "FFF" -> "FFFFFF". + $color = preg_replace( '~^(.)(.)(.)$~', '$1$1$2$2$3$3', $color ); + + $rgb = array(); + $rgb['R'] = hexdec( $color[0] . $color[1] ); + $rgb['G'] = hexdec( $color[2] . $color[3] ); + $rgb['B'] = hexdec( $color[4] . $color[5] ); + + return $rgb; + } +} + +if ( ! function_exists( 'gdpr_hex_darker' ) ) { + + /** + * Make HEX color darker. + * + * @param mixed $color Color. + * @param int $factor Darker factor. + * Defaults to 30. + * @return string + */ + function gdpr_hex_darker( $color, $factor = 30 ) { + $base = gdpr_rgb_from_hex( $color ); + $color = '#'; + + foreach ( $base as $k => $v ) { + $amount = $v / 100; + $amount = round( $amount * $factor ); + $new_decimal = $v - $amount; + + $new_hex_component = dechex( $new_decimal ); + if ( strlen( $new_hex_component ) < 2 ) { + $new_hex_component = '0' . $new_hex_component; + } + $color .= $new_hex_component; + } + + return $color; + } +} + +if ( ! function_exists( 'gdpr_hex_lighter' ) ) { + + /** + * Make HEX color lighter. + * + * @param mixed $color Color. + * @param int $factor Lighter factor. + * Defaults to 30. + * @return string + */ + function gdpr_hex_lighter( $color, $factor = 30 ) { + $base = gdpr_rgb_from_hex( $color ); + $color = '#'; + + foreach ( $base as $k => $v ) { + $amount = 255 - $v; + $amount = $amount / 100; + $amount = round( $amount * $factor ); + $new_decimal = $v + $amount; + + $new_hex_component = dechex( $new_decimal ); + if ( strlen( $new_hex_component ) < 2 ) { + $new_hex_component = '0' . $new_hex_component; + } + $color .= $new_hex_component; + } + + return $color; + } +} + +if ( ! function_exists( 'gdpr_hex_is_light' ) ) { + + /** + * Determine whether a hex color is light. + * + * @param mixed $color Color. + * @return bool True if a light color. + */ + function gdpr_hex_is_light( $color ) { + $hex = str_replace( '#', '', $color ); + + $c_r = hexdec( substr( $hex, 0, 2 ) ); + $c_g = hexdec( substr( $hex, 2, 2 ) ); + $c_b = hexdec( substr( $hex, 4, 2 ) ); + + $brightness = ( ( $c_r * 299 ) + ( $c_g * 587 ) + ( $c_b * 114 ) ) / 1000; + + return $brightness > 155; + } +} + +if ( ! function_exists( 'gdpr_light_or_dark' ) ) { + + /** + * Detect if we should use a light or dark color on a background color. + * + * @param mixed $color Color. + * @param string $dark Darkest reference. + * Defaults to '#000000'. + * @param string $light Lightest reference. + * Defaults to '#FFFFFF'. + * @return string + */ + function gdpr_light_or_dark( $color, $dark = '#000000', $light = '#FFFFFF' ) { + return gdpr_hex_is_light( $color ) ? $dark : $light; + } +} + +if ( ! function_exists( 'gdpr_format_hex' ) ) { + + /** + * Format string as hex. + * + * @param string $hex HEX color. + * @return string|null + */ + function gdpr_format_hex( $hex ) { + $hex = trim( str_replace( '#', '', $hex ) ); + + if ( strlen( $hex ) === 3 ) { + $hex = $hex[0] . $hex[0] . $hex[1] . $hex[1] . $hex[2] . $hex[2]; + } + + return $hex ? '#' . $hex : null; + } +} diff --git a/public/class-gdpr-requests-public.php b/public/class-gdpr-requests-public.php index b5e614f8..344286a5 100644 --- a/public/class-gdpr-requests-public.php +++ b/public/class-gdpr-requests-public.php @@ -227,7 +227,7 @@ public function send_request_email() { home_url() ); } - + if ( GDPR_Email::send( $user->user_email, "{$type}-request", diff --git a/src/js/admin.js b/src/js/admin.js index 1372c7d6..eaa0cbae 100644 --- a/src/js/admin.js +++ b/src/js/admin.js @@ -317,13 +317,6 @@ $( function() { $( '.color_pick' ).wpColorPicker(); - $( document ).on( 'click', '.show-settings', function( e ) { - e.preventDefault(); - const nextTr = $( this ).parents( 'tr' ).next( 'tr' ); - console.log( nextTr ); - nextTr.toggleClass( 'hide' ); - }); - $( document ).on( 'submit', '.gdpr-email-settings', function( e ) { e.preventDefault(); const formData = new FormData( this ); diff --git a/templates/email/complaint-request.php b/templates/email/complaint-request.php index 9c429f0d..a1789e29 100644 --- a/templates/email/complaint-request.php +++ b/templates/email/complaint-request.php @@ -1,27 +1,43 @@ + + + +
+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/templates/email/email-header.php b/templates/email/email-header.php new file mode 100644 index 00000000..5b5b8d1b --- /dev/null +++ b/templates/email/email-header.php @@ -0,0 +1,59 @@ + + +> + + + <?php echo get_bloginfo( 'name', 'display' ); ?> + + + ="0" marginwidth="0" topmargin="0" marginheight="0" offset="0"> +
+ + +
+
+ ' . get_bloginfo( 'name', 'display' ) . '

'; + } + ?> +
+ + + + + +
+ + + + + +
+

+
+ +
+ + + +
+ + + + - - - -
+
diff --git a/templates/email/email-styles.php b/templates/email/email-styles.php new file mode 100644 index 00000000..63ed1951 --- /dev/null +++ b/templates/email/email-styles.php @@ -0,0 +1,205 @@ + + * @since 2.0.0 + */ + +if ( ! defined( 'ABSPATH' ) ) { + exit; +} + +// Load colors. +$bg = get_option( 'gdpr_email_background_color' ); +$body = get_option( 'gdpr_email_body_background_color' ); +$base = get_option( 'gdpr_email_base_color' ); +$base_text = gdpr_light_or_dark( $base, '#202020', '#ffffff' ); +$text = get_option( 'gdpr_email_body_text_color' ); + +// Pick a contrasting color for links. +$link_color = gdpr_hex_is_light( $base ) ? $base : $base_text; + +if ( gdpr_hex_is_light( $body ) ) { + $link_color = gdpr_hex_is_light( $base ) ? $base_text : $base; +} + +$bg_darker_10 = gdpr_hex_darker( $bg, 10 ); +$body_darker_10 = gdpr_hex_darker( $body, 10 ); +$base_lighter_20 = gdpr_hex_lighter( $base, 20 ); +$base_lighter_40 = gdpr_hex_lighter( $base, 40 ); +$text_lighter_20 = gdpr_hex_lighter( $text, 20 ); +$text_lighter_40 = gdpr_hex_lighter( $text, 40 ); + +// !important; is a gmail hack to prevent styles being stripped if it doesn't like something. +// body{padding: 0;} ensures proper scale/positioning of the email in the iOS native email app. +?> + + Date: Fri, 3 Jul 2020 17:01:25 -0400 Subject: [PATCH 3/5] All email templates are updated --- templates/email/complaint-resolved.php | 16 +++- templates/email/data-breach-notification.php | 72 +++++++++------ templates/email/data-breach-request.php | 94 +++++++++++--------- templates/email/delete-request.php | 44 +++++---- templates/email/delete-resolved.php | 35 +++++--- templates/email/export-data-request.php | 44 +++++---- templates/email/new-request.php | 31 +++++-- templates/email/rectify-request.php | 50 +++++++---- templates/email/rectify-resolved.php | 16 +++- 9 files changed, 257 insertions(+), 145 deletions(-) diff --git a/templates/email/complaint-resolved.php b/templates/email/complaint-resolved.php index cbfc49e0..fe52a4e4 100644 --- a/templates/email/complaint-resolved.php +++ b/templates/email/complaint-resolved.php @@ -1,6 +1,14 @@ Date: Mon, 6 Jul 2020 16:24:52 -0400 Subject: [PATCH 4/5] Added default values for email settings --- admin/partials/settings.php | 104 +++++++++++++++--------------- includes/class-gdpr-activator.php | 17 +++++ 2 files changed, 69 insertions(+), 52 deletions(-) diff --git a/admin/partials/settings.php b/admin/partials/settings.php index 38247013..db941cd0 100755 --- a/admin/partials/settings.php +++ b/admin/partials/settings.php @@ -294,66 +294,66 @@
- - - - -
- -
-
- - $domain_arr ) : ?> -
-

-
- - - - - - - +
- - - -
- - -
- + + +
+
-
-
- - -
+
+ + $domain_arr ) : ?> +
+

+
+ + + + + + + + + +
+ + + +
+ + + +
+ +
+
+
+ + +
diff --git a/includes/class-gdpr-activator.php b/includes/class-gdpr-activator.php index b768a3ee..465635b8 100755 --- a/includes/class-gdpr-activator.php +++ b/includes/class-gdpr-activator.php @@ -35,6 +35,7 @@ public static function activate() { /* translators: 1: Current PHP version 2: Required PHP version. */ die( sprintf( esc_html__( 'Your current PHP version (%1$s) is below the plugin required version of %2$s.', 'gdpr' ), esc_html( phpversion() ), esc_html( GDPR_REQUIRED_PHP_VERSION ) ) ); } + $theme_settings = get_theme_mods(); add_option( 'gdpr_disable_css', false ); add_option( 'gdpr_use_recaptcha', false ); @@ -75,6 +76,22 @@ public static function activate() { add_option( 'gdpr_display_cookie_categories_in_bar', false ); add_option( 'gdpr_hide_from_bots', true ); add_option( 'gdpr_reconsent_template', 'modal' ); + add_option( 'gdpr_email_form_name', 'GDPR Team' ); + + $custom_logo_id = ( ! empty ( $theme_settings['custom_logo'] ) ) ? $theme_settings['custom_logo'] : ''; + $image = ( ! empty ( $custom_logo_id ) ) ? wp_get_attachment_image_src( $custom_logo_id , 'full' ) : ''; + add_option( 'gdpr_email_header_image_url', $image ); + + $admin_email = get_option( 'admin_email' ); + add_option( 'gdpr_email_from_address', $admin_email ); + + $email_base_color = ( ! empty ( $theme_settings[ 'header_footer_background_color' ] ) ) ? $theme_settings[ 'header_footer_background_color' ] : '#8e1c3b'; + add_option( 'gdpr_email_base_color', $email_base_color ); + + $email_background_color = ( ! empty ( $theme_settings[ 'background_color' ] ) ) ? $theme_settings[ 'background_color' ] : '#FFFFFF'; + add_option( 'gdpr_email_background_color', $email_background_color ); + add_option( 'gdpr_email_body_background_color', $email_background_color ); + add_option( 'gdpr_email_body_text_color', '#000000' ); } } From b2157865293405cad71c1ff881039f78f0e7ad6e Mon Sep 17 00:00:00 2001 From: Moutushi Date: Mon, 6 Jul 2020 17:20:11 -0400 Subject: [PATCH 5/5] Use email settings data for sending email --- includes/class-gdpr-email.php | 13 +++++++++++-- templates/email/complaint-request.php | 10 ++++++---- templates/email/complaint-resolved.php | 9 +++++++-- templates/email/data-breach-notification.php | 10 +++++++--- templates/email/data-breach-request.php | 9 +++++++-- templates/email/delete-request.php | 9 +++++++-- templates/email/delete-resolved.php | 9 +++++++-- templates/email/export-data-request.php | 9 +++++++-- templates/email/new-request.php | 9 +++++++-- templates/email/rectify-request.php | 9 ++++++--- templates/email/rectify-resolved.php | 9 +++++++-- 11 files changed, 79 insertions(+), 26 deletions(-) diff --git a/includes/class-gdpr-email.php b/includes/class-gdpr-email.php index a3392d59..450d7e49 100644 --- a/includes/class-gdpr-email.php +++ b/includes/class-gdpr-email.php @@ -79,8 +79,11 @@ private static function get_do_not_reply_address() { if ( substr( $sitename, 0, 4 ) === 'www.' ) { $sitename = substr( $sitename, 4 ); } + $no_reply = 'noreply@' . $sitename; - return apply_filters( 'gdpr_do_not_reply_address', 'noreply@' . $sitename ); + $no_reply_email = ( ! empty ( get_option( 'gdpr_email_recipient_address' ) ) ) ? get_option( 'gdpr_email_recipient_address' ) : $no_reply; + + return apply_filters( 'gdpr_do_not_reply_address', $no_reply_email ); } /** @@ -196,10 +199,15 @@ public static function send( $emails, $type, $args = array(), $attachments = arr $no_reply = self::get_do_not_reply_address(); $headers = array(); + $email_from_name = get_option( 'gdpr_email_form_name' ); + $email_from_address = get_option( 'gdpr_email_from_address' ); + + $headers[] = 'From: ' . $email_from_name . ' <' . $email_from_address . '>'; foreach ( (array) $emails as $email ) { $headers[] = 'Bcc: ' . sanitize_email( $email ); } - $headers[] = 'Content-Type: ' . self::get_content_type( $type ); + $email_content_type = self::get_content_type( $type ); + $headers[] = 'Content-Type: ' . $email_content_type; $email_subject_field = 'gdpr_' . str_replace( '-', '_', $type ) . '_email_subject'; $subject = get_option( $email_subject_field ); @@ -213,6 +221,7 @@ public static function send( $emails, $type, $args = array(), $attachments = arr $email_content = get_option( $email_content_field ); $args['email_content'] = $email_content; + $args['email_content_type'] = ( strpos( $email_content_type, 'html' ) !== FALSE ) ? 'html' : 'plain'; $content = self::get_email_content( 'email/' . $type . '.php', $args ); diff --git a/templates/email/complaint-request.php b/templates/email/complaint-request.php index a1789e29..228e1235 100644 --- a/templates/email/complaint-request.php +++ b/templates/email/complaint-request.php @@ -1,6 +1,8 @@