PluginProbe
User Profile Builder – Beautiful User Registration Forms, User Profiles & User Role Editor / 3.9.6
User Profile Builder – Beautiful User Registration Forms, User Profiles & User Role Editor v3.9.6
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 2.0.7 All 340 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 3.9.6, at features/email-customizer/email-customizer.php

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