PluginProbe
User Profile Builder – Beautiful User Registration Forms, User Profiles & User Role Editor / 4.0.3
User Profile Builder – Beautiful User Registration Forms, User Profiles & User Role Editor v4.0.3
4.0.3 4.0.2 4.0.1 4.0.0 3.16.6 3.16.5 3.16.4 3.16.3 3.16.2 3.16.1 3.16.0 3.15.9 3.9.9 3.9.5 3.9.6 3.9.7 3.9.8 1.1.7 1.1.8 1.1.9 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 All 341 releases
profile-builder / features / email-customizer / email-customizer.php

email-customizer.php in User Profile Builder – Beautiful User Registration Forms, User Profiles & User Role Editor 4.0.3, at features/email-customizer/email-customizer.php

1,290 lines 53.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 // Exit if accessed directly
3 if ( ! defined( 'ABSPATH' ) ) exit;
4
5 function wppb_email_customizer_generate_merge_tags( $special_merge_tags = null ){
6
7 $mustache_vars = array(
8 array(
9 'group-title' => __( 'Available Tags', 'profile-builder' ),
10 'variables' => wppb_email_customizer_generate_default_meta_merge_tags( $special_merge_tags )
11 ),
12 array(
13 'group-title' => __( 'User Fields Tags', 'profile-builder' ),
14 'variables' => wppb_email_customizer_generate_meta_merge_tags()
15 )
16 );
17
18 return $mustache_vars;
19 }
20
21
22 function wppb_email_customizer_generate_default_meta_merge_tags( $special_merge_tags ){
23 $merge_tags[] = array( 'name' => 'site_url', 'type' => 'ec_site_url', 'label' => __( 'Site Url', 'profile-builder' ) );
24 $merge_tags[] = array( 'name' => 'site_name', 'type' => 'ec_site_name', 'label' => __( 'Site Name', 'profile-builder' ) );
25
26 if ( $special_merge_tags != 'email_confirmation' ){
27 $merge_tags[] = array( 'name' => 'user_id', 'type' => 'ec_user_id', 'label' => __( 'User Id', 'profile-builder' ) );
28 }
29
30 $merge_tags[] = array( 'name' => 'username', 'type' => 'ec_username', 'label' => __( 'Username', 'profile-builder' ) );
31 $merge_tags[] = array( 'name' => 'user_email', 'type' => 'ec_user_email', 'label' => __( 'Email', 'profile-builder' ) );
32 $merge_tags[] = array( 'name' => 'password', 'type' => 'ec_password', 'label' => __( 'Password', 'profile-builder' ) );
33 $merge_tags[] = array( 'name' => 'role', 'type' => 'ec_role', 'label' => __( 'User Role', 'profile-builder' ) );
34 $merge_tags[] = array( 'name' => 'role_label', 'type' => 'ec_role_label', 'label' => __( 'User Role Label', 'profile-builder' ) );
35 $merge_tags[] = array( 'name' => 'website', 'type' => 'ec_website', 'label' => __( 'Website', 'profile-builder' ) );
36 $merge_tags[] = array( 'name' => 'reply_to', 'type' => 'ec_reply_to', 'label' => __( 'Reply To', 'profile-builder' ) );
37
38 if ( wppb_can_users_signup_blog() ) {
39 $merge_tags[] = array('name' => 'blog_url', 'type' => 'ec_blog_url', 'label' => __('Blog URL', 'profile-builder'));
40 }
41
42 if ( $special_merge_tags == 'email_confirmation' ){
43 $merge_tags[] = array( 'name' => 'activation_key', 'type' => 'ec_activation_key', 'label' => __( 'Activation Key', 'profile-builder' ) );
44 $merge_tags[] = array( 'name' => 'activation_url', 'type' => 'ec_activation_url', 'label' => __( 'Activation Url', 'profile-builder' ) );
45 $merge_tags[] = array( 'name' => 'activation_link', 'type' => 'ec_activation_link', 'unescaped' => true, 'label' => __( 'Activation Link', 'profile-builder' ) );
46 }
47
48 if ( $special_merge_tags == 'password_reset' ){
49 $merge_tags[] = array( 'name' => 'reset_key', 'type' => 'ec_reset_key', 'label' => __( 'Reset Key', 'profile-builder' ) );
50 $merge_tags[] = array( 'name' => 'reset_url', 'type' => 'ec_reset_url', 'label' => __( 'Reset Url', 'profile-builder' ) );
51 $merge_tags[] = array( 'name' => 'reset_link', 'type' => 'ec_reset_link', 'unescaped' => true, 'label' => __( 'Reset Link', 'profile-builder' ) );
52 }
53
54 if ( $special_merge_tags == 'change_email_address_request' ){
55 $merge_tags[] = array( 'name' => 'user_email_change_link', 'type' => 'ec_user_email_change_link', 'unescaped' => true, 'label' => __( 'Change Email Address Link', 'profile-builder' ) );
56 }
57
58 if ( $special_merge_tags == 'admin_approval' ){
59 $merge_tags[] = array( 'name' => 'approve_url', 'type' => 'ec_approve_url', 'label' => __( 'Approve User Url', 'profile-builder' ) );
60 $merge_tags[] = array( 'name' => 'approve_link', 'type' => 'ec_approve_link', 'unescaped' => true, 'label' => __( 'Approve User Link', 'profile-builder' ) );
61 $merge_tags[] = array( 'name' => 'unapprove_url', 'type' => 'ec_unapprove_url', 'label' => __( 'Unapprove User Url', 'profile-builder' ) );
62 $merge_tags[] = array( 'name' => 'unapprove_link', 'type' => 'ec_unapprove_link', 'unescaped' => true, 'label' => __( 'Unapprove User Link', 'profile-builder' ) );
63 }
64
65 if ( $special_merge_tags == 'epaa_notification' ){
66 $merge_tags[] = array( 'name' => 'approved_fields', 'type' => 'ec_epaa_approved_fields', 'label' => __( 'Approved Fields', 'profile-builder' ) );
67 $merge_tags[] = array( 'name' => 'unapproved_fields', 'type' => 'ec_epaa_unapproved_fields', 'label' => __( 'Unapproved Fields', 'profile-builder' ) );
68 }
69
70 if ( $special_merge_tags == 'epaa_notification_admin' ){
71 $merge_tags[] = array( 'name' => 'modified_fields', 'type' => 'ec_epaa_modified_fields', 'label' => __( 'Modified Fields', 'profile-builder' ) );
72 $merge_tags[] = array( 'name' => 'approval_url', 'type' => 'ec_epaa_approval_url', 'label' => __( 'Approval URL', 'profile-builder' ) );
73 $merge_tags[] = array( 'name' => 'approval_link', 'type' => 'ec_epaa_approval_link', 'unescaped' => true, 'label' => __( 'Approval Link', 'profile-builder' ) );
74 }
75
76 return $merge_tags;
77 }
78
79
80 function wppb_email_customizer_generate_meta_merge_tags(){
81 $wppb_manage_fields = apply_filters( 'wppb_email_customizer_get_fields' , get_option( 'wppb_manage_fields', 'not_found' ) );
82 $merge_tags = array();
83
84 if ( $wppb_manage_fields != 'not_found' ){
85 foreach( $wppb_manage_fields as $key => $value ){
86 if( !empty( $value['meta-name'] ) ){
87
88 // Skip all map fields
89 if( $value['field'] == 'Map' || $value['field'] == 'HTML' )
90 continue;
91
92 $merge_tags[] = array( 'name' => $value['meta-name'], 'type' => 'ec_user_meta', 'label' => $value['field-title'] );
93 if( $value['field'] == 'Select' || $value['field'] == 'Select (Multiple)' || $value['field'] == 'Select (Country)' || $value['field'] == 'Select (Currency)' || $value['field'] == 'Checkbox' || $value['field'] == 'Radio' )
94 $merge_tags[] = array( 'name' => $value['meta-name'] . '_labels', 'type' => 'ec_user_meta_labels', 'label' => $value['field-title'] . ' Labels' );
95 elseif( ( $value['field'] == 'Select (CPT)' ) )
96 $merge_tags[] = array( 'name' => $value['meta-name'].'_cpt_title_link', 'type' => 'user_meta_select_cpt', 'unescaped' => true, 'label' => $value['field-title'] );
97 elseif( ( $value['field'] == 'Select (Taxonomy)' ) )
98 $merge_tags[] = array( 'name' => $value['meta-name'].'_taxonomy_title_link', 'type' => 'user_meta_select_taxonomy', 'unescaped' => true, 'label' => $value['field-title'] );
99 }
100 }
101 }
102
103 return apply_filters( 'wppb_email_customizer_get_merge_tags', $merge_tags );
104 }
105
106 function wppb_email_customizer_admin_approval_new_user_signup_filter_handler( $default_string, $user_email, $user_password, $email_sent_from, $option_name ){
107 $email_customizer_option = get_option( $option_name, 'not_found' );
108 if ( $email_customizer_option != 'not_found' && !empty( $user_email ) ){
109 $user_data = get_user_by( 'email', $user_email );
110 $special_merge_tags = ( current_filter() == 'wppb_register_admin_email_message_with_admin_approval' ) ? 'admin_approval' : '';
111 wppb_change_email_from_headers();
112 return (string) new PB_Mustache_Generate_Template( wppb_email_customizer_generate_merge_tags($special_merge_tags), $email_customizer_option, array( 'user_id' => $user_data->ID, 'user_login' => $user_data->user_login, 'user_email' => $user_email, 'user_password' => $user_password, 'user_data' => $user_data, 'email_sent_from' => $email_sent_from ) );
113 }
114
115 return $default_string;
116 }
117
118 function wppb_email_customizer_admin_approval_new_user_signup_subject_filter_handler( $default_string, $user_email, $user_password, $email_sent_from, $option_name ){
119 if( current_user_can( 'delete_users') ) {
120 $email_customizer_option = get_option( 'wppb_user_emailc_admin_approval_notif_approved_email_subject', 'not_found' );
121 } else {
122 $email_customizer_option = get_option( $option_name, 'not_found' );
123 }
124
125 if ( $email_customizer_option != 'not_found' && !empty( $user_email ) ){
126 $user_data = get_user_by( 'email', $user_email );
127 wppb_change_email_from_headers();
128 return (string) new PB_Mustache_Generate_Template( wppb_email_customizer_generate_merge_tags(), $email_customizer_option, array( 'user_id' => $user_data->ID, 'user_login' => $user_data->user_login, 'user_email' => $user_email, 'user_password' => $user_password, 'user_data' => $user_data, 'email_sent_from' => $email_sent_from ) );
129 }
130
131 return $default_string;
132 }
133
134 function wppb_email_customizer_admin_approval_new_user_signup_message_filter_handler( $default_string, $user_email, $user_password, $email_sent_from, $option_name ){
135 if( current_user_can( 'delete_users') ) {
136 $email_customizer_option = get_option( 'wppb_user_emailc_admin_approval_notif_approved_email_content', 'not_found' );
137 } else {
138 $email_customizer_option = get_option( $option_name, 'not_found' );
139 }
140
141 if ( $email_customizer_option != 'not_found' && !empty( $user_email ) ){
142 $user_data = get_user_by( 'email', $user_email );
143 wppb_change_email_from_headers();
144 return (string) new PB_Mustache_Generate_Template( wppb_email_customizer_generate_merge_tags(), $email_customizer_option, array( 'user_id' => $user_data->ID, 'user_login' => $user_data->user_login, 'user_email' => $user_email, 'user_password' => $user_password, 'user_data' => $user_data, 'email_sent_from' => $email_sent_from ) );
145 }
146
147 return $default_string;
148 }
149
150 function wppb_email_customizer_admin_approval_new_user_status_filter_handler( $default_string, $user_data, $new_status, $email_sent_from, $option_name ){
151 $email_customizer_option = get_option( $option_name, 'not_found' );
152
153 if ( $email_customizer_option != 'not_found' ){
154 if( !empty( $user_data ) ){
155 wppb_change_email_from_headers();
156 return (string) new PB_Mustache_Generate_Template( wppb_email_customizer_generate_merge_tags(), $email_customizer_option, array( 'user_id' => $user_data->ID, 'user_login' => $user_data->user_login, 'user_email' => $user_data->user_email, 'user_password' => $user_data->user_pass, 'user_data' => $user_data, 'email_sent_from' => $email_sent_from ) );
157 }
158 }
159
160 return $default_string;
161 }
162
163 function wppb_email_customizer_email_confirmation_filter_handler( $default_string, $user_email, $username, $key, $activation_url, $serialized_data, $email_sent_from, $option_name ){
164 $email_customizer_option = get_option( $option_name, 'not_found' );
165 if ( $email_customizer_option != 'not_found' ){
166 $unserialized_data = unserialize( $serialized_data );
167 if( !empty( $unserialized_data ) ){
168 wppb_change_email_from_headers();
169 return (string) new PB_Mustache_Generate_Template( wppb_email_customizer_generate_merge_tags( 'email_confirmation' ), $email_customizer_option, array( 'user_login' => $unserialized_data['user_login'], 'user_email' => $user_email, 'user_password' => $unserialized_data['user_pass'], 'email_confirmation_unserialized_data' => $unserialized_data, 'email_confirmation_key' => $key, 'email_confirmation_url' => $activation_url, 'email_sent_from' => $email_sent_from ) );
170 }
171 }
172
173 return $default_string;
174 }
175
176 function wppb_email_customizer_password_reset_content_filter_handler( $default_string, $user_id, $user_login, $user_email ) {
177 $email_customizer_option = get_option( 'wppb_user_emailc_reset_email_content', 'not_found' );
178 $user = new WP_User( $user_id );
179 $key = get_password_reset_key( $user );
180 $url = add_query_arg( array( 'key' => $key, 'login' => urlencode( $user->user_login ) ), wppb_curpageurl() );
181
182 if( $email_customizer_option != 'not_found' ) {
183 wppb_change_email_from_headers();
184 return (string) new PB_Mustache_Generate_Template( wppb_email_customizer_generate_merge_tags( 'password_reset' ), $email_customizer_option, array( 'user_login' => $user_login, 'reset_key' => $key, 'reset_url' => $url, 'user_email' => $user_email, 'user_id' => $user_id ) );
185 }
186
187 return $default_string;
188 }
189
190 function wppb_email_customizer_password_reset_title_filter_handler( $default_string, $username ) {
191 $email_customizer_option = get_option( 'wppb_user_emailc_reset_email_subject', 'not_found' );
192
193 if( $email_customizer_option != 'not_found' && !empty( $username ) ) {
194 wppb_change_email_from_headers();
195 $user_info = get_user_by( 'login', $username );
196 if( !empty( $user_info->data->user_email ) )
197 $user_email = $user_info->data->user_email;
198 else
199 $user_email = '';
200 return (string) new PB_Mustache_Generate_Template( wppb_email_customizer_generate_merge_tags( 'password_reset' ), $email_customizer_option, array( 'user_login' => $username, 'user_email' => $user_email, 'user_id' => $user_info->data->ID ) );
201 }
202
203 return $default_string;
204 }
205
206 function wppb_email_customizer_password_reset_success_content_filter_handler( $default_string, $username, $new_password, $userID ) {
207 $email_customizer_option = get_option( 'wppb_user_emailc_reset_success_email_content', 'not_found' );
208
209 if( $email_customizer_option != 'not_found' && !empty( $userID ) ) {
210 $user_info = get_userdata( $userID );
211 wppb_change_email_from_headers();
212 return (string) new PB_Mustache_Generate_Template( wppb_email_customizer_generate_merge_tags(), $email_customizer_option, array( 'user_login' => $username, 'user_password' => $new_password, 'user_id' => $userID, 'user_email' => $user_info->user_email ) );
213 }
214
215 return $default_string;
216 }
217
218 function wppb_email_customizer_password_reset_success_title_filter_handler( $default_string, $username ) {
219 $email_customizer_option = get_option( 'wppb_user_emailc_reset_success_email_subject', 'not_found' );
220
221 if( $email_customizer_option != 'not_found' && !empty( $username ) ) {
222 $user_info = get_user_by( 'login', $username );
223 /* we could have email instead of username in $username */
224 if( !$user_info )
225 $user_info = get_user_by( 'email', $username );
226
227 if( !empty( $user_info->data->user_email ) )
228 $user_email = $user_info->data->user_email;
229 else
230 $user_email = '';
231 wppb_change_email_from_headers();
232 return (string) new PB_Mustache_Generate_Template( wppb_email_customizer_generate_merge_tags(), $email_customizer_option, array( 'user_login' => $username, 'user_email' => $user_email, 'user_id' => $user_info->data->ID ) );
233 }
234
235 return $default_string;
236 }
237
238 function wppb_admin_email_customizer_password_reset_content_filter_handler( $default_string, $username, $new_password, $userID ) {
239 $email_customizer_option = get_option( 'wppb_admin_emailc_user_password_reset_email_content', 'not_found' );
240
241 if( $email_customizer_option != 'not_found' && !empty( $userID ) ) {
242 $user_info = get_userdata( $userID );
243 wppb_change_email_from_headers();
244 return (string) new PB_Mustache_Generate_Template( wppb_email_customizer_generate_merge_tags(), $email_customizer_option, array( 'user_login' => $username, 'user_password' => $new_password, 'user_id' => $userID, 'user_email' => $user_info->user_email ) );
245 }
246
247 return $default_string;
248 }
249
250 function wppb_admin_email_customizer_password_reset_title_filter_handler( $default_string, $username ) {
251 $email_customizer_option = get_option( 'wppb_admin_emailc_user_password_reset_email_subject', 'not_found' );
252
253 if( $email_customizer_option != 'not_found' && !empty( $username ) ) {
254 $user_info = get_user_by( 'login', $username );
255 /* we could have email instead of username in $username */
256 if( !$user_info )
257 $user_info = get_user_by( 'email', $username );
258
259 if( !empty( $user_info->data->user_email ) )
260 $user_email = $user_info->data->user_email;
261 else
262 $user_email = '';
263 wppb_change_email_from_headers();
264 return (string) new PB_Mustache_Generate_Template( wppb_email_customizer_generate_merge_tags(), $email_customizer_option, array( 'user_login' => $username, 'user_email' => $user_email, 'user_id' => $user_info->data->ID ) );
265 }
266
267 return $default_string;
268 }
269
270 function wppb_email_customizer_user_email_change_request_subject_filter_handler($default_string, $user) {
271 $email_customizer_option = get_option( 'wppb_user_emailc_change_email_address_request_subject', 'not_found' );
272
273 if( $email_customizer_option != 'not_found' && class_exists( 'PB_Mustache_Generate_Template' ) ) {
274 wppb_change_email_from_headers();
275 return (string) new PB_Mustache_Generate_Template( wppb_email_customizer_generate_merge_tags( 'change_email_address_request' ), $email_customizer_option, array( 'user_login' => $user->user_login, 'user_email' => $user->user_email, 'user_id' => $user->ID ));
276 }
277
278 return $default_string;
279 }
280
281 function wppb_email_customizer_user_email_change_request_content_filter_handler($default_string, $user, $email_change_request_url) {
282 $email_customizer_option = get_option( 'wppb_user_emailc_change_email_address_request_content', 'not_found' );
283
284 if( $email_customizer_option != 'not_found' && class_exists( 'PB_Mustache_Generate_Template' ) ) {
285 wppb_change_email_from_headers();
286
287 return (string) new PB_Mustache_Generate_Template( wppb_email_customizer_generate_merge_tags( 'change_email_address_request' ), $email_customizer_option, array( 'user_login' => $user->user_login, 'user_email' => $user->user_email, 'user_id' => $user->ID, 'change_email_url' => $email_change_request_url ));
288 }
289
290 return $default_string;
291 }
292
293 function wppb_email_customizer_change_email_address_title_filter_handler ( $default, $old_user_data, $new_user_data ){
294 $email_customizer_option = get_option( 'wppb_user_emailc_change_email_address_subject', 'not_found' );
295
296 if( $email_customizer_option != 'not_found' && class_exists( 'PB_Mustache_Generate_Template' ) ) {
297 $email_change_email = $default;
298 $subject = (string) new PB_Mustache_Generate_Template( wppb_email_customizer_generate_merge_tags(), $email_customizer_option, array( 'user_login' => $old_user_data['user_login'], 'user_email' => $old_user_data['user_email'], 'user_id' => $old_user_data['ID'] ) );
299 $email_change_email['subject'] = html_entity_decode( htmlspecialchars_decode( $subject, ENT_QUOTES ), ENT_QUOTES );
300
301 wppb_change_email_from_headers();
302 return $email_change_email;
303 }
304
305 return $default;
306 }
307
308 function wppb_email_customizer_change_email_address_header_filter_handler( $email_change_email, $user, $userdata ){
309 $email_change_email['headers'] = array( 'Content-Type: text/html; charset=UTF-8' );
310 return $email_change_email;
311 }
312
313 function wppb_email_customizer_change_email_address_content_filter_handler ( $default, $old_user_data, $new_user_data ){
314 $email_customizer_option = get_option( 'wppb_user_emailc_change_email_address_content', 'not_found' );
315
316 if( file_exists( WPPB_PLUGIN_DIR . '/assets/lib/class-mustache-templates/class-mustache-templates.php' ) )
317 require_once( WPPB_PLUGIN_DIR . '/assets/lib/class-mustache-templates/class-mustache-templates.php' );
318
319 if( $email_customizer_option != 'not_found' && class_exists( 'PB_Mustache_Generate_Template' ) ) {
320
321 $email_change_email = $default;
322 $email_content = (string) new PB_Mustache_Generate_Template( wppb_email_customizer_generate_merge_tags(), $email_customizer_option, array( 'user_login' => $old_user_data['user_login'], 'user_email' => $old_user_data['user_email'], 'user_id' => $old_user_data['ID'] ) );
323 $email_change_email['message'] = $email_content;
324
325 wppb_change_email_from_headers();
326 return $email_change_email;
327 }
328
329 return $default;
330 }
331
332 function wppb_email_customizer_epaa_title_filter_handler ( $default, $user_id, $approved_field_names, $unapproved_field_names ){
333 $email_customizer_option = get_option( 'wppb_user_emailc_epaa_notification_subject', 'not_found' );
334
335 if( $email_customizer_option != 'not_found' && class_exists( 'PB_Mustache_Generate_Template' ) && !empty( $user_id ) ) {
336 $user_info = get_user_by( 'id', $user_id );
337 $subject = (string) new PB_Mustache_Generate_Template( wppb_email_customizer_generate_merge_tags( 'epaa_notification' ), $email_customizer_option, array( 'user_login' => $user_info->data->user_login, 'user_email' => $user_info->data->user_email, 'user_id' => $user_info->data->ID, 'approved_field_names' => $approved_field_names, 'unapproved_field_names' => $unapproved_field_names ) );
338
339 wppb_change_email_from_headers();
340 return $subject;
341 }
342
343 return $default;
344 }
345
346 function wppb_email_customizer_epaa_content_filter_handler ( $default, $user_id, $approved_field_names, $unapproved_field_names ){
347 $email_customizer_option = get_option( 'wppb_user_emailc_epaa_notification_content', 'not_found' );
348
349 if( $email_customizer_option != 'not_found' && class_exists( 'PB_Mustache_Generate_Template' ) && !empty( $user_id ) ) {
350 $user_info = get_user_by( 'id', $user_id );
351 $email_content = (string) new PB_Mustache_Generate_Template( wppb_email_customizer_generate_merge_tags( 'epaa_notification' ), $email_customizer_option, array( 'user_login' => $user_info->data->user_login, 'user_email' => $user_info->data->user_email, 'user_id' => $user_info->data->ID, 'approved_field_names' => $approved_field_names, 'unapproved_field_names' => $unapproved_field_names ) );
352
353 wppb_change_email_from_headers();
354 return $email_content;
355 }
356
357 return $default;
358 }
359
360 function wppb_admin_email_customizer_epaa_title_filter_handler ( $default, $user_id, $fields, $approve_url ){
361 $email_customizer_option = get_option( 'wppb_admin_emailc_epaa_notification_subject', 'not_found' );
362
363 if( $email_customizer_option != 'not_found' && class_exists( 'PB_Mustache_Generate_Template' ) && !empty( $user_id ) ) {
364 $user_info = get_user_by( 'id', $user_id );
365 $subject = (string) new PB_Mustache_Generate_Template( wppb_email_customizer_generate_merge_tags( 'epaa_notification_admin' ), $email_customizer_option, array( 'user_login' => $user_info->data->user_login, 'user_email' => $user_info->data->user_email, 'user_id' => $user_info->data->ID, 'modified_fields' => $fields, 'approval_url' => $approve_url ) );
366
367 wppb_change_email_from_headers();
368 return $subject;
369 }
370
371 return $default;
372 }
373
374 function wppb_admin_email_customizer_epaa_content_filter_handler ( $default, $user_id, $fields, $approve_url ){
375 $email_customizer_option = get_option( 'wppb_admin_emailc_epaa_notification_content', 'not_found' );
376
377 if( $email_customizer_option != 'not_found' && class_exists( 'PB_Mustache_Generate_Template' ) && !empty( $user_id ) ) {
378 $user_info = get_user_by( 'id', $user_id );
379 $email_content = (string) new PB_Mustache_Generate_Template( wppb_email_customizer_generate_merge_tags( 'epaa_notification_admin' ), $email_customizer_option, array( 'user_login' => $user_info->data->user_login, 'user_email' => $user_info->data->user_email, 'user_id' => $user_info->data->ID, 'modified_fields' => $fields, 'approval_url' => $approve_url ) );
380
381 wppb_change_email_from_headers();
382 return html_entity_decode( htmlspecialchars_decode( $email_content, ENT_QUOTES ), ENT_QUOTES );
383 }
384
385 return $default;
386 }
387
388 // user emails
389 add_filter ( 'wppb_register_user_email_subject_without_admin_approval', 'wppb_email_customizer_admin_approval_new_user_signup_filter_handler', 10, 5 );
390 add_filter ( 'wppb_register_user_email_message_without_admin_approval', 'wppb_email_customizer_admin_approval_new_user_signup_filter_handler', 10, 5 );
391
392 add_filter ( 'wppb_register_user_email_subject_with_admin_approval', 'wppb_email_customizer_admin_approval_new_user_signup_subject_filter_handler', 10, 5 );
393 add_filter ( 'wppb_register_user_email_message_with_admin_approval', 'wppb_email_customizer_admin_approval_new_user_signup_message_filter_handler', 10, 5 );
394
395 add_filter ( 'wppb_new_user_status_subject_approved', 'wppb_email_customizer_admin_approval_new_user_status_filter_handler', 10, 5 );
396 add_filter ( 'wppb_new_user_status_message_approved', 'wppb_email_customizer_admin_approval_new_user_status_filter_handler', 10, 5 );
397
398 add_filter ( 'wppb_new_user_status_subject_unapproved', 'wppb_email_customizer_admin_approval_new_user_status_filter_handler', 10, 5 );
399 add_filter ( 'wppb_new_user_status_message_unapproved', 'wppb_email_customizer_admin_approval_new_user_status_filter_handler', 10, 5 );
400
401 add_filter ( 'wppb_signup_user_notification_email_subject', 'wppb_email_customizer_email_confirmation_filter_handler', 10, 8 );
402 add_filter ( 'wppb_signup_user_notification_email_content', 'wppb_email_customizer_email_confirmation_filter_handler', 10, 8 );
403
404 add_filter ( 'wppb_recover_password_message_content_sent_to_user1', 'wppb_email_customizer_password_reset_content_filter_handler', 10, 4 );
405 add_filter ( 'wppb_recover_password_message_title_sent_to_user1', 'wppb_email_customizer_password_reset_title_filter_handler', 10, 2 );
406
407 add_filter ( 'wppb_recover_password_message_content_sent_to_user2', 'wppb_email_customizer_password_reset_success_content_filter_handler', 10, 4 );
408 add_filter ( 'wppb_recover_password_message_title_sent_to_user2', 'wppb_email_customizer_password_reset_success_title_filter_handler', 10, 2 );
409
410 add_filter ( 'wppb_user_email_change_request_notification_subject', 'wppb_email_customizer_user_email_change_request_subject_filter_handler', 10, 3);
411 add_filter ( 'wppb_user_email_change_request_notification_content', 'wppb_email_customizer_user_email_change_request_content_filter_handler', 10, 3);
412
413 add_filter ( 'email_change_email', 'wppb_email_customizer_change_email_address_content_filter_handler', 10, 3);
414 add_filter ( 'email_change_email', 'wppb_email_customizer_change_email_address_title_filter_handler', 10, 3);
415 add_filter ( 'email_change_email', 'wppb_email_customizer_change_email_address_header_filter_handler', 10, 3);
416
417 // using filters, we overwrite the old content with the new one from the email customizer (for the admin)
418 add_filter ( 'wppb_register_admin_email_subject_without_admin_approval', 'wppb_email_customizer_admin_approval_new_user_signup_filter_handler', 10, 5 );
419 add_filter ( 'wppb_register_admin_email_message_without_admin_approval', 'wppb_email_customizer_admin_approval_new_user_signup_filter_handler', 10, 5 );
420
421 add_filter ( 'wppb_register_admin_email_subject_with_admin_approval', 'wppb_email_customizer_admin_approval_new_user_signup_filter_handler', 10, 5 );
422 add_filter ( 'wppb_register_admin_email_message_with_admin_approval', 'wppb_email_customizer_admin_approval_new_user_signup_filter_handler', 10, 5 );
423
424 add_filter ( 'wppb_recover_password_message_content_sent_to_admin', 'wppb_admin_email_customizer_password_reset_content_filter_handler', 10, 4 );
425 add_filter ( 'wppb_recover_password_message_title_sent_to_admin', 'wppb_admin_email_customizer_password_reset_title_filter_handler', 10, 2 );
426
427 // Mustache variables
428
429 /**
430 * Function that overwrites the default reply-to with the one set in the Email Customizer
431 *
432 * @since v.2.0
433 *
434 * @param string $sender_email
435 *
436 * @return string
437 */
438 function wppb_ec_website_email( $value, $merge_tag_name, $merge_tag, $extra_data ){
439 $admin_email_address = get_bloginfo( 'admin_email' );
440
441 $emailc_common_settings_from_reply_to_email = get_option( 'wppb_emailc_common_settings_from_reply_to_email', 'not_found' );
442 if ( $emailc_common_settings_from_reply_to_email != 'not_found' ) {
443 if( strpos( $emailc_common_settings_from_reply_to_email, '{{reply_to}}' ) === false ) {
444 if( is_email( trim( $emailc_common_settings_from_reply_to_email ) ) )
445 $admin_email_address = trim( $emailc_common_settings_from_reply_to_email );
446 }
447 }
448
449 return apply_filters( 'wppb_ec_sender_email_filter', trim( $admin_email_address ) );
450 }
451 add_filter( 'mustache_variable_ec_reply_to', 'wppb_ec_website_email', 10, 4 );
452
453
454 /**
455 * Function that filters and returns the site_url in the Email Customizer
456 *
457 * @since v.2.0
458 *
459 * @param string $value
460 * @param string $merge_tag_name
461 * @param string $merge_tag
462 * @param array $extra_data
463 *
464 * @return string
465 */
466 function wppb_ec_replace_site_url( $value, $merge_tag_name, $merge_tag, $extra_data ){
467 return apply_filters( 'wppb_ec_site_url_filter', get_bloginfo( 'url' ) );
468 }
469 add_filter( 'mustache_variable_ec_site_url', 'wppb_ec_replace_site_url', 10, 4 );
470
471
472 /**
473 * Function that filters and returns the site_name in the Email Customizer
474 *
475 * @since v.2.0
476 *
477 * @param string $value
478 * @param string $merge_tag_name
479 * @param string $merge_tag
480 * @param array $extra_data
481 *
482 * @return string
483 */
484 function wppb_ec_replace_site_name( $value, $merge_tag_name, $merge_tag, $extra_data ){
485 return apply_filters( 'wppb_ec_site_name_filter', html_entity_decode( htmlspecialchars_decode( get_bloginfo( 'name' ), ENT_QUOTES ), ENT_QUOTES ) );
486 }
487 add_filter( 'mustache_variable_ec_site_name', 'wppb_ec_replace_site_name', 10, 4 );
488
489
490 /**
491 * Function that filters and returns the user_id in the Email Customizer
492 *
493 * @since v.2.0
494 *
495 * @param string $value
496 * @param string $merge_tag_name
497 * @param string $merge_tag
498 * @param array $extra_data
499 *
500 * @return string
501 */
502 function wppb_ec_replace_user_id( $value, $merge_tag_name, $merge_tag, $extra_data ){
503 if( !empty( $extra_data['user_id'] ) )
504 return $extra_data['user_id'];
505 else
506 return '';
507 }
508 add_filter( 'mustache_variable_ec_user_id', 'wppb_ec_replace_user_id', 10, 4 );
509
510
511 /**
512 * Function that filters and returns the username in the Email Customizer
513 *
514 * @since v.2.0
515 *
516 * @param string $value
517 * @param string $merge_tag_name
518 * @param string $merge_tag
519 * @param array $extra_data
520 *
521 * @return string
522 */
523 function wppb_ec_replace_username( $value, $merge_tag_name, $merge_tag, $extra_data ){
524 $wppb_general_settings = get_option( 'wppb_general_settings' );
525
526 if ( isset( $extra_data['email_confirmation_unserialized_data']['user_login'] ) ){
527 if( isset( $wppb_general_settings['loginWith'] ) && ( $wppb_general_settings['loginWith'] == 'email' ) )
528 return $extra_data['email_confirmation_unserialized_data']['user_email'];
529 else
530 return $extra_data['email_confirmation_unserialized_data']['user_login'];
531 }
532
533 if( isset( $wppb_general_settings['loginWith'] ) && ( $wppb_general_settings['loginWith'] == 'email' ) )
534 return $extra_data['user_email'];
535 else
536 return $extra_data['user_login'];
537
538 }
539 add_filter( 'mustache_variable_ec_username', 'wppb_ec_replace_username', 10, 4 );
540
541
542 /**
543 * Function that filters and returns the user_email in the Email Customizer
544 *
545 * @since v.2.0
546 *
547 * @param string $value
548 * @param string $merge_tag_name
549 * @param string $merge_tag
550 * @param array $extra_data
551 *
552 * @return string
553 */
554 function wppb_ec_replace_user_email( $value, $merge_tag_name, $merge_tag, $extra_data ){
555 if ( isset( $extra_data['email_confirmation_unserialized_data']['user_email'] ) )
556 return $extra_data['email_confirmation_unserialized_data']['user_email'];
557
558 if( !empty( $extra_data['user_email'] ) )
559 return $extra_data['user_email'];
560 else
561 return '';
562 }
563 add_filter( 'mustache_variable_ec_user_email', 'wppb_ec_replace_user_email', 10, 4 );
564
565 /**
566 * Function that filters and returns the users password in the Email Customizer
567 *
568 * @since v.2.0
569 *
570 * @param string $value
571 * @param string $merge_tag_name
572 * @param string $merge_tag
573 * @param array $extra_data
574 *
575 * @return string
576 */
577 function wppb_ec_replace_password( $value, $merge_tag_name, $merge_tag, $extra_data ){
578 /* don't send the password to the admin */
579 global $wp_current_filter;
580 if( !empty( $wp_current_filter ) && is_array( $wp_current_filter ) ){
581 foreach( $wp_current_filter as $filter ){
582 if( $filter == 'wppb_register_admin_email_subject_without_admin_approval' ||
583 $filter == 'wppb_register_admin_email_message_without_admin_approval' ||
584 $filter == 'wppb_register_admin_email_subject_with_admin_approval' ||
585 $filter == 'wppb_register_admin_email_message_with_admin_approval' ||
586 $filter == 'wppb_recover_password_message_content_sent_to_admin' ||
587 $filter == 'wppb_recover_password_message_title_sent_to_admin'
588 ){
589 return __( 'The users selected password at signup', 'profile-builder' );
590 }
591 }
592 }
593
594 $wppb_general_settings = get_option( 'wppb_general_settings' );
595
596 if( empty( $extra_data['email_confirmation_unserialized_data']['user_pass'] ) && empty( $extra_data['user_password'] ) ){
597 return __( 'Your selected password at signup', 'profile-builder' );
598 }
599
600 if ( isset( $extra_data['email_confirmation_unserialized_data']['user_pass'] ) ) {
601 if( base64_encode( base64_decode($extra_data['email_confirmation_unserialized_data']['user_pass'] ) ) === $extra_data['email_confirmation_unserialized_data']['user_pass'] )
602 return base64_decode($extra_data['email_confirmation_unserialized_data']['user_pass']);
603 else
604 return __( 'Your selected password at signup', 'profile-builder' );
605 }
606
607 if( wppb_get_admin_approval_option_value() === 'yes' ){
608 if ( isset( $extra_data['user_password'] ) ) {
609 global $wpdb;
610
611 $search_for_password = $wpdb->get_results( $wpdb->prepare(
612 "SELECT user_pass FROM $wpdb->users WHERE user_pass = '%s'",
613 $extra_data['user_password']
614 ));
615
616 if( !empty( $search_for_password ) )
617 return __( 'Your selected password at signup', 'profile-builder' );
618 }
619 }
620
621 return $extra_data['user_password'];
622 }
623 add_filter( 'mustache_variable_ec_password', 'wppb_ec_replace_password', 10, 4 );
624
625
626 /**
627 * Function that filters and returns the users website in the Email Customizer
628 *
629 * @since v.2.0
630 *
631 * @param string $value
632 * @param string $merge_tag_name
633 * @param string $merge_tag
634 * @param array $extra_data
635 *
636 * @return string
637 */
638 function wppb_ec_replace_website( $value, $merge_tag_name, $merge_tag, $extra_data ){
639 if ( isset( $extra_data['email_confirmation_unserialized_data']['user_url'] ) )
640 return $extra_data['email_confirmation_unserialized_data']['user_url'];
641 if( !empty( $extra_data['user_data'] ) )
642 return $extra_data['user_data']->user_url;
643 }
644 add_filter( 'mustache_variable_ec_website', 'wppb_ec_replace_website', 10, 4 );
645
646
647 /**
648 * Function that filters and returns the users blog url in the Email Customizer
649 *
650 * @since v.2.5.5
651 *
652 * @param string $value
653 * @param string $merge_tag_name
654 * @param string $merge_tag
655 * @param array $extra_data
656 *
657 * @return string
658 */
659 function wppb_ec_replace_blog_url( $value, $merge_tag_name, $merge_tag, $extra_data ){
660 if ( isset( $extra_data['email_confirmation_unserialized_data']['wppb_create_new_site_checkbox'] ) && $extra_data['email_confirmation_unserialized_data']['wppb_create_new_site_checkbox'] == 'yes' ) {
661 $blog_details = wpmu_validate_blog_signup( $extra_data['email_confirmation_unserialized_data']['wppb_blog_url'], $extra_data['email_confirmation_unserialized_data']['wppb_blog_title'] );
662 if ( empty($blog_details['errors']->errors['blogname']) && empty($blog_details['errors']->errors['blog_title']))
663 return $blog_details['domain'] . $blog_details['path'];
664 }
665
666 if( !empty( $extra_data['user_data'] ) ) {
667 return wppb_get_blog_url_of_user_id($extra_data['user_data']->ID);
668 }
669 }
670 add_filter( 'mustache_variable_ec_blog_url', 'wppb_ec_replace_blog_url', 10, 4 );
671
672
673 /**
674 * Function that filters and returns the users role in the Email Customizer
675 *
676 * @since v.2.0
677 *
678 * @param string $value
679 * @param string $merge_tag_name
680 * @param string $merge_tag
681 * @param array $extra_data
682 *
683 * @return string
684 */
685 function wppb_ec_replace_role( $value, $merge_tag_name, $merge_tag, $extra_data ){
686 if( isset( $extra_data['email_confirmation_unserialized_data']['role'] ) ) {
687 return $extra_data['email_confirmation_unserialized_data']['role'];
688 }
689
690 if( ! empty( $extra_data['user_data'] ) ) {
691 $user_role = implode( ', ', $extra_data['user_data']->roles );
692 return $user_role;
693 }
694
695 if( ! empty ( $extra_data['user_id'] ) ) {
696 $user_data = get_user_by( 'id', $extra_data['user_id'] );
697 $user_role = implode( ', ', $user_data->roles );
698 return $user_role;
699 }
700 }
701 add_filter( 'mustache_variable_ec_role', 'wppb_ec_replace_role', 10, 4 );
702
703 /**
704 * Function that filters and returns the users role label in the Email Customizer
705 *
706 * @since v.2.7.1
707 *
708 * @param string $value
709 * @param string $merge_tag_name
710 * @param string $merge_tag
711 * @param array $extra_data
712 *
713 * @return string
714 */
715 function wppb_ec_replace_role_label( $value, $merge_tag_name, $merge_tag, $extra_data ){
716 $roles = explode(', ', wppb_ec_replace_role( $value, $merge_tag_name, $merge_tag, $extra_data ) );
717 $role_labels = '';
718
719 foreach ($roles as $role) {
720 $role_labels .= wppb_get_role_name( $role ) . ', ';
721 }
722
723 return rtrim($role_labels, ', ');
724 }
725 add_filter( 'mustache_variable_ec_role_label', 'wppb_ec_replace_role_label', 10, 4 );
726
727 /**
728 * Function that filters and returns the users activation_key in the Email Customizer
729 *
730 * @since v.2.0
731 *
732 * @param string $value
733 * @param string $merge_tag_name
734 * @param string $merge_tag
735 * @param array $extra_data
736 *
737 * @return string
738 */
739 function wppb_ec_replace_activation_key( $value, $merge_tag_name, $merge_tag, $extra_data ){
740 if ( isset( $extra_data['email_confirmation_key'] ) )
741 return $extra_data['email_confirmation_key'];
742 }
743 add_filter( 'mustache_variable_ec_activation_key', 'wppb_ec_replace_activation_key', 10, 4 );
744
745
746 /**
747 * Function that filters and returns the users activation_url in the Email Customizer
748 *
749 * @since v.2.0
750 *
751 * @param string $value
752 * @param string $merge_tag_name
753 * @param string $merge_tag
754 * @param array $extra_data
755 *
756 * @return string
757 */
758 function wppb_ec_replace_activation_url( $value, $merge_tag_name, $merge_tag, $extra_data ){
759 if ( isset( $extra_data['email_confirmation_url'] ) )
760 return $extra_data['email_confirmation_url'];
761 }
762 add_filter( 'mustache_variable_ec_activation_url', 'wppb_ec_replace_activation_url', 10, 4 );
763
764
765 /**
766 * Function that filters and returns the users activation_link in the Email Customizer
767 *
768 * @since v.2.0
769 *
770 * @param string $value
771 * @param string $merge_tag_name
772 * @param string $merge_tag
773 * @param array $extra_data
774 *
775 * @return string
776 */
777 function wppb_ec_replace_activation_link( $value, $merge_tag_name, $merge_tag, $extra_data ){
778 if ( isset( $extra_data['email_confirmation_url'] ) )
779 return '<a href="'.$extra_data['email_confirmation_url'].'" target="_blank">'.$extra_data['email_confirmation_url'].'</a>';
780 }
781 add_filter( 'mustache_variable_ec_activation_link', 'wppb_ec_replace_activation_link', 10, 4 );
782
783
784 /**
785 * Function that filters and returns the users reset_key in the Email Customizer
786 *
787 * @since v.2.0
788 *
789 * @param string $value
790 * @param string $merge_tag_name
791 * @param string $merge_tag
792 * @param array $extra_data
793 *
794 * @return string
795 */
796 function wppb_ec_replace_reset_key( $value, $merge_tag_name, $merge_tag, $extra_data ){
797 if ( isset( $extra_data['reset_key'] ) )
798 return $extra_data['reset_key'];
799 }
800 add_filter( 'mustache_variable_ec_reset_key', 'wppb_ec_replace_reset_key', 10, 4 );
801
802
803 /**
804 * Function that filters and returns the users reset_url in the Email Customizer
805 *
806 * @since v.2.0
807 *
808 * @param string $value
809 * @param string $merge_tag_name
810 * @param string $merge_tag
811 * @param array $extra_data
812 *
813 * @return string
814 */
815 function wppb_ec_replace_reset_url( $value, $merge_tag_name, $merge_tag, $extra_data ){
816 if ( isset( $extra_data['reset_url'] ) )
817 return $extra_data['reset_url'];
818 }
819 add_filter( 'mustache_variable_ec_reset_url', 'wppb_ec_replace_reset_url', 10, 4 );
820
821
822 /**
823 * Function that filters and returns the users reset_link in the Email Customizer
824 *
825 * @since v.2.0
826 *
827 * @param string $value
828 * @param string $merge_tag_name
829 * @param string $merge_tag
830 * @param array $extra_data
831 *
832 * @return string
833 */
834 function wppb_ec_replace_reset_link( $value, $merge_tag_name, $merge_tag, $extra_data ){
835 if ( isset( $extra_data['reset_url'] ) )
836 return '<a href="'.$extra_data['reset_url'].'" target="_blank">'.$extra_data['reset_url'].'</a>';
837 }
838 add_filter( 'mustache_variable_ec_reset_link', 'wppb_ec_replace_reset_link', 10, 4 );
839
840
841 /**
842 * Function that filters and returns the users user_email_change_link in the Email Customizer
843 *
844 * @since v.
845 *
846 * @param string $value
847 * @param string $merge_tag_name
848 * @param string $merge_tag
849 * @param array $extra_data
850 *
851 * @return string
852 */
853 function wppb_ec_generate_user_email_change_link( $value, $merge_tag_name, $merge_tag, $extra_data ){
854 if ( isset( $extra_data['change_email_url'] ) )
855 // return $extra_data['change_email_url'];
856 return '<a href="'. $extra_data['change_email_url'] .'">'. __( 'Change Email Address Link', 'profile-builder' ) .'</a>';
857 }
858 add_filter( 'mustache_variable_ec_user_email_change_link', 'wppb_ec_generate_user_email_change_link', 10, 4 );
859
860
861 /**
862 * Function that filters and returns the approve user link in the (Admin) Email Customizer.
863 * This allows the admin to approve directly from his email a newly registered user.
864 *
865 * @since v.2.7.3
866 *
867 * @param string $value
868 * @param string $merge_tag_name
869 * @param string $merge_tag
870 * @param array $extra_data
871 *
872 * @return string
873 */
874 function wppb_ec_replace_approve_user_link( $value, $merge_tag_name, $merge_tag, $extra_data ){
875
876 if( ! empty ( $extra_data['user_id'] ) ) {
877
878 $approve_url = add_query_arg( 'pbaction', 'approve', wppb_ec_get_approve_url( $extra_data['user_id'] ) );
879
880 if ( !empty($approve_url) )
881
882 return '<a href="' . $approve_url . '" target="_blank">' . $approve_url . '</a>';
883 }
884 }
885 add_filter( 'mustache_variable_ec_approve_link', 'wppb_ec_replace_approve_user_link', 10, 4 );
886
887
888 /**
889 * Function that filters and returns the approve user url in the (Admin) Email Customizer.
890 *
891 * @since v.2.7.3
892 *
893 * @param string $value
894 * @param string $merge_tag_name
895 * @param string $merge_tag
896 * @param array $extra_data
897 *
898 * @return string
899 */
900 function wppb_ec_replace_approve_user_url( $value, $merge_tag_name, $merge_tag, $extra_data ){
901
902 if( ! empty ( $extra_data['user_id'] ) ) {
903
904 $approve_url = add_query_arg( 'pbaction', 'approve', wppb_ec_get_approve_url( $extra_data['user_id'] ) );
905
906 if ( !empty( $approve_url ) )
907 return $approve_url;
908
909 }
910 }
911 add_filter( 'mustache_variable_ec_approve_url', 'wppb_ec_replace_approve_user_url', 10, 4 );
912
913 /**
914 * Function that filters and returns the approve user link in the (Admin) Email Customizer.
915 * This allows the admin to approve directly from his email a newly registered user.
916 *
917 * @since v.3.4.7
918 *
919 * @param string $value
920 * @param string $merge_tag_name
921 * @param string $merge_tag
922 * @param array $extra_data
923 *
924 * @return string
925 */
926 function wppb_ec_replace_unapprove_user_link( $value, $merge_tag_name, $merge_tag, $extra_data ){
927
928 if( ! empty ( $extra_data['user_id'] ) ) {
929
930 $approve_url = add_query_arg( 'pbaction', 'unapprove', wppb_ec_get_approve_url( $extra_data['user_id'] ) );
931
932 if ( !empty($approve_url) )
933
934 return '<a href="' . $approve_url . '" target="_blank">' . $approve_url . '</a>';
935 }
936 }
937 add_filter( 'mustache_variable_ec_unapprove_link', 'wppb_ec_replace_unapprove_user_link', 10, 4 );
938
939
940 /**
941 * Function that filters and returns the approve user url in the (Admin) Email Customizer.
942 *
943 * @since v.3.4.7
944 *
945 * @param string $value
946 * @param string $merge_tag_name
947 * @param string $merge_tag
948 * @param array $extra_data
949 *
950 * @return string
951 */
952 function wppb_ec_replace_unapprove_user_url( $value, $merge_tag_name, $merge_tag, $extra_data ){
953
954 if( ! empty ( $extra_data['user_id'] ) ) {
955
956 $approve_url = add_query_arg( 'pbaction', 'unapprove', wppb_ec_get_approve_url( $extra_data['user_id'] ) );
957
958 if ( !empty( $approve_url ) )
959 return $approve_url;
960
961 }
962 }
963 add_filter( 'mustache_variable_ec_unapprove_url', 'wppb_ec_replace_unapprove_user_url', 10, 4 );
964
965 /**
966 * Function that returns the approve user url to include in the admin email
967 *
968 * @since v.2.7.3
969 *
970 * @param $user_id The ID of the user that is pending approval
971 *
972 * @return string Approve URL
973 */
974 function wppb_ec_get_approve_url ( $user_id ){
975
976 $approve_url = '';
977
978 // If the user is "unaproved" the user meta below will contain a (hashed) value that we need to attach to the admin approval email link for validating it
979 $approve_url_param = get_user_meta( $user_id, '_wppb_admin_approval_link_param', true );
980
981 if ( !empty( $approve_url_param ) ) {
982 $approve_url = esc_url( add_query_arg( 'pbapprove', $approve_url_param, get_site_url() ) );
983 }
984
985 return $approve_url;
986 }
987
988
989 /**
990 * Function that filters and returns the approved fields for Edit Profile Approved by Admin.
991 *
992 * @since v.2.7.3
993 *
994 * @param string $value
995 * @param string $merge_tag_name
996 * @param string $merge_tag
997 * @param array $extra_data
998 *
999 * @return string
1000 */
1001 function wppb_epaa_replace_approved_fields( $value, $merge_tag_name, $merge_tag, $extra_data ){
1002
1003 if( ! empty ( $extra_data['approved_field_names'] ) ) {
1004 return $extra_data['approved_field_names'];
1005 }
1006
1007 return '';
1008 }
1009 add_filter( 'mustache_variable_ec_epaa_approved_fields', 'wppb_epaa_replace_approved_fields', 10, 4 );
1010
1011
1012 /**
1013 * Function that filters and returns the unapproved fields for Edit Profile Approved by Admin.
1014 *
1015 * @since v.2.7.3
1016 *
1017 * @param string $value
1018 * @param string $merge_tag_name
1019 * @param string $merge_tag
1020 * @param array $extra_data
1021 *
1022 * @return string
1023 */
1024 function wppb_epaa_replace_unapproved_fields( $value, $merge_tag_name, $merge_tag, $extra_data ){
1025
1026 if( ! empty ( $extra_data['unapproved_field_names'] ) ) {
1027 return $extra_data['unapproved_field_names'];
1028 }
1029
1030 return '';
1031 }
1032 add_filter( 'mustache_variable_ec_epaa_unapproved_fields', 'wppb_epaa_replace_unapproved_fields', 10, 4 );
1033
1034
1035 /**
1036 * Function that filters and returns the modified fields for Edit Profile Approved by Admin.
1037 *
1038 * @since v.2.7.3
1039 *
1040 * @param string $value
1041 * @param string $merge_tag_name
1042 * @param string $merge_tag
1043 * @param array $extra_data
1044 *
1045 * @return string
1046 */
1047 function wppb_epaa_replace_modified_fields( $value, $merge_tag_name, $merge_tag, $extra_data ){
1048
1049 if( ! empty ( $extra_data['modified_fields'] ) ) {
1050 return $extra_data['modified_fields'];
1051 }
1052
1053 return '';
1054 }
1055 add_filter( 'mustache_variable_ec_epaa_modified_fields', 'wppb_epaa_replace_modified_fields', 10, 4 );
1056
1057
1058 /**
1059 * Function that filters and returns the approval_url for Edit Profile Approved by Admin.
1060 *
1061 * @since v.2.7.3
1062 *
1063 * @param string $value
1064 * @param string $merge_tag_name
1065 * @param string $merge_tag
1066 * @param array $extra_data
1067 *
1068 * @return string
1069 */
1070 function wppb_epaa_replace_approval_url( $value, $merge_tag_name, $merge_tag, $extra_data ){
1071
1072 if( isset( $extra_data['approval_url'] ) )
1073 return $extra_data['approval_url'];
1074 }
1075 add_filter( 'mustache_variable_ec_epaa_approval_url', 'wppb_epaa_replace_approval_url', 10, 4 );
1076
1077
1078 /**
1079 * Function that filters and returns the approval_link for Edit Profile Approved by Admin.
1080 *
1081 * @since v.2.0
1082 *
1083 * @param string $value
1084 * @param string $merge_tag_name
1085 * @param string $merge_tag
1086 * @param array $extra_data
1087 *
1088 * @return string
1089 */
1090 function wppb_epaa_replace_approval_link( $value, $merge_tag_name, $merge_tag, $extra_data ){
1091 if ( isset( $extra_data['approval_url'] ) )
1092 return '<a href="'.$extra_data['approval_url'].'" target="_blank">'.$extra_data['approval_url'].'</a>';
1093 }
1094 add_filter( 'mustache_variable_ec_epaa_approval_link', 'wppb_epaa_replace_approval_link', 10, 4 );
1095
1096
1097
1098 /**
1099 * Function that filters and returns the users user_meta values in the Email Customizer
1100 *
1101 * @since v.2.0
1102 *
1103 * @param string $value
1104 * @param string $merge_tag_name
1105 * @param string $merge_tag
1106 * @param array $extra_data
1107 *
1108 * @return string
1109 */
1110 function wppb_ec_replace_user_meta( $value, $merge_tag_name, $merge_tag, $extra_data ){
1111 if ( isset( $extra_data['email_confirmation_unserialized_data'][$merge_tag_name] ) )
1112 $value = $extra_data['email_confirmation_unserialized_data'][$merge_tag_name];
1113 elseif( !empty( $extra_data['user_id'] ) )
1114 $value = get_user_meta( $extra_data['user_id'], $merge_tag_name, true );
1115
1116 /* value should be a string, but in case it is not */
1117 if( is_array( $value ) )
1118 $value = implode( ' ', $value );
1119
1120 return apply_filters( 'wppb_ec_filter_user_meta', $value, $merge_tag_name, $extra_data );
1121 }
1122 add_filter( 'mustache_variable_ec_user_meta', 'wppb_ec_replace_user_meta', 10, 4 );
1123
1124
1125 add_filter( 'wppb_ec_filter_user_meta', 'wppb_ec_change_user_meta_by_type', 10, 3 );
1126 function wppb_ec_change_user_meta_by_type( $value, $meta_name, $extra_data = '' ){
1127 $fields = apply_filters( 'wppb_form_fields', get_option( 'wppb_manage_fields', 'not_found' ), array( 'user_id' => ( empty( $extra_data['user_id'] ) ) ? '' : $extra_data['user_id'], 'meta' => ( empty( $extra_data['email_confirmation_unserialized_data'] ) ) ? '' : $extra_data['email_confirmation_unserialized_data'], 'context' => 'mustache_variable' ) );
1128 if( !empty( $fields ) ) {
1129 foreach ($fields as $field) {
1130 if ($field['meta-name'] == $meta_name && ($field['field'] == 'Avatar' || $field['field'] == 'Upload' ) ) {
1131 if( is_numeric( $value ) )
1132 $value = wp_get_attachment_url( $value );
1133 }
1134 }
1135 }
1136 return $value;
1137 }
1138
1139 /**
1140 * Function that filters and returns the users user_meta labels in the Email Customizer
1141 *
1142 * @since v.2.0
1143 *
1144 * @param string $value
1145 * @param string $merge_tag_name
1146 * @param string $merge_tag
1147 * @param array $extra_data
1148 *
1149 * @return string
1150 */
1151 function wppb_ec_replace_user_meta_labels( $value, $merge_tag_name, $merge_tag, $extra_data ){
1152 /* we remove _labels from end so we get the meta name */
1153 $merge_tag_name = preg_replace( '/_labels$/', '', $merge_tag_name, 1 );
1154
1155 if ( isset( $extra_data['email_confirmation_unserialized_data'][$merge_tag_name] ) )
1156 $value = $extra_data['email_confirmation_unserialized_data'][$merge_tag_name];
1157 if( !empty( $extra_data['user_id'] ) )
1158 $value = get_user_meta( $extra_data['user_id'], $merge_tag_name, true );
1159
1160 /* get label from value */
1161 /* get manage fields */
1162 $fields = apply_filters( 'wppb_form_fields', get_option( 'wppb_manage_fields', 'not_found' ), array( 'user_id' => ( empty( $extra_data['user_id'] ) ) ? '' : $extra_data['user_id'], 'meta' => ( empty( $extra_data['email_confirmation_unserialized_data'] ) ) ? '' : $extra_data['email_confirmation_unserialized_data'], 'context' => 'mustache_variable' ) );
1163 if( !empty( $fields ) ) {
1164 foreach ($fields as $field) {
1165 if( $field['meta-name'] == $merge_tag_name ){
1166 if( $field['field'] == 'Select (Country)' ){
1167 if( function_exists( 'wppb_country_select_options' ) ) {
1168 $all_countries = wppb_country_select_options('email_customizer');
1169 if( !empty( $all_countries[$value] ) )
1170 return $all_countries[$value];
1171 else
1172 return $value;
1173 }
1174 else{
1175 return $value;
1176 }
1177 }
1178 else if( $field['field'] == 'Select (Currency)' ){
1179 if( function_exists( 'wppb_get_currencies' ) ) {
1180 $all_currencies = wppb_get_currencies('email_customizer');
1181 if( !empty( $all_currencies[$value] ) )
1182 return $all_currencies[$value];
1183 else
1184 return $value;
1185 }
1186 else{
1187 return $value;
1188 }
1189 }
1190 else {
1191 /* get label corresponding to value. the values and labels in the backend settings are comma separated so we assume that as well here ? */
1192 $saved_values = array_map('trim', explode(',', $value));
1193 $field['options'] = array_map('trim', explode(',', $field['options']));
1194 $field['labels'] = array_map('trim', explode(',', $field['labels']));
1195 /* get the position for each value */
1196 $key_array = array();
1197 if (!empty($field['options'])) {
1198 foreach ($field['options'] as $key => $option) {
1199 if (in_array($option, $saved_values))
1200 $key_array[] = $key;
1201 }
1202 }
1203
1204 $show_values = array();
1205 if (!empty($key_array)) {
1206 foreach ($key_array as $key) {
1207 if (!empty($field['labels'][$key]))
1208 $show_values[] = $field['labels'][$key];
1209 else
1210 $show_values[] = $field['options'][$key];
1211 }
1212 }
1213
1214 return implode(',', $show_values);
1215 }
1216 }
1217 }
1218 }
1219 }
1220 add_filter( 'mustache_variable_ec_user_meta_labels', 'wppb_ec_replace_user_meta_labels', 10, 4 );
1221
1222 // function that filters the From email address
1223 function wppb_website_email($sender_email){
1224
1225 $reply_to_email = get_option( 'wppb_emailc_common_settings_from_reply_to_email', 'not_found' );
1226
1227 if ( $reply_to_email != 'not_found' ) {
1228 $reply_to_email = str_replace('{{reply_to}}', get_bloginfo('admin_email'), $reply_to_email );
1229
1230 if( is_email( $reply_to_email ) )
1231 $sender_email = $reply_to_email;
1232 }
1233
1234 return apply_filters( 'wppb_from_website_email', $sender_email );
1235
1236 }
1237
1238 // function that filters the From name
1239 function wppb_website_name($site_name){
1240
1241 $email_from_name = get_option( 'wppb_emailc_common_settings_from_name', 'not_found' );
1242
1243 if ( $email_from_name != 'not_found' ) {
1244 $email_from_name = str_replace('{{site_name}}', get_bloginfo('name'), $email_from_name );
1245 $site_name = $email_from_name;
1246 }
1247
1248 return html_entity_decode( htmlspecialchars_decode( $site_name, ENT_QUOTES ), ENT_QUOTES );
1249 }
1250
1251 // Function that changes email headers only when they are needed.
1252 function wppb_change_email_from_headers(){
1253 add_filter('wp_mail_from_name','wppb_website_name', 20, 1);
1254 add_filter('wp_mail_from','wppb_website_email', 20, 1);
1255 }
1256
1257 add_filter( 'wppb_send_email', 'wppb_disable_emails', 20, 5 );
1258 function wppb_disable_emails( $send_email, $to, $subject, $message, $context ) {
1259 $actions = array(
1260 'email_user_account_info' => 'wppb_user_emailc_default_registration_email_enabled',
1261 'email_user_activate' => 'wppb_user_emailc_registr_w_email_confirm_email_enabled',
1262 'email_user_need_approval' => 'wppb_user_emailc_registration_with_admin_approval_email_enabled',
1263 'email_user_approved' => 'wppb_user_emailc_admin_approval_notif_approved_email_enabled',
1264 'email_user_unapproved' => 'wppb_user_emailc_admin_approval_notif_unapproved_email_enabled',
1265 'email_user_recover' => 'wppb_user_emailc_reset_email_enabled',
1266 'email_user_recover_success' => 'wppb_user_emailc_reset_success_email_enabled',
1267 'email_user_update_email' => 'wppb_user_emailc_change_email_address_request_enabled',
1268 'wppb_epaa_user_email' => 'wppb_user_emailc_epaa_notification_enabled',
1269 'email_admin_new_subscriber' => 'wppb_admin_emailc_default_registration_email_enabled',
1270 'email_admin_approve' => 'wppb_admin_emailc_registration_with_admin_approval_email_enabled',
1271 'email_admin_recover_success' => 'wppb_admin_emailc_user_password_reset_email_enabled',
1272 'wppb_epaa_admin_email' => 'wppb_admin_emailc_epaa_notification_enabled',
1273 );
1274
1275 if ( !empty( $actions[$context] ) )
1276 $option_name = $actions[$context];
1277 else
1278 return $send_email;
1279
1280 $option = get_option( $option_name );
1281
1282 if ( $option == 'off' )
1283 return false;
1284
1285 return $send_email;
1286 }
1287
1288 if ( get_option( 'wppb_user_emailc_change_email_address_enabled' ) == 'off' )
1289 add_filter( 'send_email_change_email', '__return_false' );
1290