PluginProbe
User Profile Builder – Beautiful User Registration Forms, User Profiles & User Role Editor / 2.7.1
User Profile Builder – Beautiful User Registration Forms, User Profiles & User Role Editor v2.7.1
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
← All changes | features/functions.php +616 -136 2.0.22.7.1 View file →
@@ -6,9 +6,9 @@
6 6
7 7 // whitelist options, you can add more register_settings changing the second parameter
8 8 function wppb_register_settings() {
9 9 register_setting( 'wppb_option_group', 'wppb_default_settings' );
10 - register_setting( 'wppb_general_settings', 'wppb_general_settings' );
10 + register_setting( 'wppb_general_settings', 'wppb_general_settings', 'wppb_general_settings_sanitize' );
11 11 register_setting( 'wppb_display_admin_settings', 'wppb_display_admin_settings' );
12 12 register_setting( 'wppb_profile_builder_pro_serial', 'wppb_profile_builder_pro_serial' );
13 13 register_setting( 'wppb_profile_builder_hobbyist_serial', 'wppb_profile_builder_hobbyist_serial' );
14 14 register_setting( 'wppb_module_settings', 'wppb_module_settings' );
@@ -16,8 +16,9 @@
16 16 register_setting( 'customRedirectSettings', 'customRedirectSettings' );
17 17 register_setting( 'customUserListingSettings', 'customUserListingSettings' );
18 18 register_setting( 'reCaptchaSettings', 'reCaptchaSettings' );
19 19 register_setting( 'emailCustomizer', 'emailCustomizer' );
20 + register_setting( 'wppb_content_restriction_settings', 'wppb_content_restriction_settings' );
20 21 }
21 22
22 23
23 24
@@ -35,11 +36,17 @@
35 36 function wppb_add_plugin_stylesheet() {
36 37 $wppb_generalSettings = get_option( 'wppb_general_settings' );
37 38
38 39 if ( ( file_exists( WPPB_PLUGIN_DIR . '/assets/css/style-front-end.css' ) ) && ( isset( $wppb_generalSettings['extraFieldsLayout'] ) && ( $wppb_generalSettings['extraFieldsLayout'] == 'default' ) ) ){
39 - wp_register_style( 'wppb_stylesheet', WPPB_PLUGIN_URL . 'assets/css/style-front-end.css' );
40 + wp_register_style( 'wppb_stylesheet', WPPB_PLUGIN_URL . 'assets/css/style-front-end.css', array(), PROFILE_BUILDER_VERSION );
40 41 wp_enqueue_style( 'wppb_stylesheet' );
41 42 }
43 + if( is_rtl() ) {
44 + if ( ( file_exists( WPPB_PLUGIN_DIR . '/assets/css/rtl.css' ) ) && ( isset( $wppb_generalSettings['extraFieldsLayout'] ) && ( $wppb_generalSettings['extraFieldsLayout'] == 'default' ) ) ){
45 + wp_register_style( 'wppb_stylesheet_rtl', WPPB_PLUGIN_URL . 'assets/css/rtl.css', array(), PROFILE_BUILDER_VERSION );
46 + wp_enqueue_style( 'wppb_stylesheet_rtl' );
47 + }
48 + }
42 49 }
43 50
44 51
45 52 function wppb_show_admin_bar($content){
@@ -71,16 +78,22 @@
71 78 if ((isset($_SERVER["HTTPS"])) && ($_SERVER["HTTPS"] == "on"))
72 79 $pageURL .= "s";
73 80
74 81 $pageURL .= "://";
82 +
83 + if( strpos( $_SERVER["HTTP_HOST"], $_SERVER["SERVER_NAME"] ) !== false ){
84 + $pageURL .=$_SERVER["HTTP_HOST"].$_SERVER["REQUEST_URI"];
85 + }
86 + else {
87 + if ($_SERVER["SERVER_PORT"] != "80")
88 + $pageURL .= $_SERVER["SERVER_NAME"] . ":" . $_SERVER["SERVER_PORT"] . $_SERVER["REQUEST_URI"];
89 + else
90 + $pageURL .= $_SERVER["SERVER_NAME"] . $_SERVER["REQUEST_URI"];
91 + }
75 92
76 - if ($_SERVER["SERVER_PORT"] != "80")
77 - $pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
78 -
79 - else
80 - $pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
81 -
82 - return $pageURL;
93 + if ( function_exists('apply_filters') ) $pageURL = apply_filters('wppb_curpageurl', $pageURL);
94 +
95 + return $pageURL;
83 96 }
84 97 }
85 98
86 99
@@ -94,9 +107,11 @@
94 107 require_once( WPPB_PLUGIN_DIR.'/front-end/extra-fields/extra-fields.php' );
95 108
96 109 add_action( 'show_user_profile', 'display_profile_extra_fields_in_admin', 10 );
97 110 add_action( 'edit_user_profile', 'display_profile_extra_fields_in_admin', 10 );
98 - add_action( 'user_profile_update_errors', 'wppb_validate_backend_fields', 10, 3 );
111 + global $pagenow;
112 + if( $pagenow != 'user-new.php' )
113 + add_action( 'user_profile_update_errors', 'wppb_validate_backend_fields', 10, 3 );
99 114 add_action( 'personal_options_update', 'save_profile_extra_fields_in_admin', 10 );
100 115 add_action( 'edit_user_profile_update', 'save_profile_extra_fields_in_admin', 10 );
101 116 }
102 117
@@ -112,8 +127,12 @@
112 127 // include the menu file for the login screen
113 128 include_once( WPPB_PLUGIN_DIR.'/front-end/login.php' );
114 129 add_shortcode( 'wppb-login', 'wppb_front_end_login' );
115 130
131 + // include the menu file for the logout screen
132 + include_once( WPPB_PLUGIN_DIR.'/front-end/logout.php' );
133 + add_shortcode( 'wppb-logout', 'wppb_front_end_logout' );
134 +
116 135 // include the menu file for the register screen
117 136 include_once( WPPB_PLUGIN_DIR.'/front-end/register.php' );
118 137 add_shortcode( 'wppb-register', 'wppb_front_end_register_handler' );
119 138
@@ -129,9 +148,9 @@
129 148 }
130 149
131 150
132 151 /**
133 - * Function that overwites the default wp_mail function and sends out emails
152 + * Function that overwrites the default wp_mail function and sends out emails
134 153 *
135 154 * @since v.2.0
136 155 *
137 156 * @param string $to
@@ -139,31 +158,36 @@
139 158 * @param string $message
140 159 * @param string $message_from
141 160 *
142 161 */
143 -function wppb_mail($to, $subject, $message, $message_from){
144 - $to = apply_filters ( 'wppb_send_email_to', $to );
145 - $send_email = apply_filters ( 'wppb_send_email', true, $to, $subject, $message );
146 -
147 - $message = apply_filters( 'wppb_email_message', $message );
162 +function wppb_mail( $to, $subject, $message, $message_from = null, $context = null, $headers = '' ) {
163 + $to = apply_filters( 'wppb_send_email_to', $to );
164 + $send_email = apply_filters( 'wppb_send_email', true, $to, $subject, $message, $context );
148 165
149 - do_action( 'wppb_before_sending_email', $to, $subject, $message, $send_email );
166 + $message = apply_filters( 'wppb_email_message', $message, $context );
167 +
168 + do_action( 'wppb_before_sending_email', $to, $subject, $message, $send_email, $context );
150 169
151 - if ( $send_email ){
170 + if ( $send_email ) {
152 171 //we add this filter to enable html encoding
153 - add_filter( 'wp_mail_content_type', create_function( '', 'return "text/html"; ' ) );
154 -
155 - $sent = wp_mail( $to , $subject, $message );
172 + add_filter( 'wp_mail_content_type', create_function( '', 'return "text/html"; ' ) );
173 +
174 + $atts = apply_filters( 'wppb_mail', compact( 'to', 'subject', 'message', 'headers' ), $context );
175 +
176 + $sent = wp_mail( $atts['to'] , html_entity_decode( htmlspecialchars_decode( $atts['subject'], ENT_QUOTES ), ENT_QUOTES ), $atts['message'], $atts['headers'] );
177 +
178 + do_action( 'wppb_after_sending_email', $sent, $to, $subject, $message, $send_email, $context );
179 +
180 + return $sent;
156 181 }
157 -
158 - do_action( 'wppb_after_sending_email', $sent, $to, $subject, $message, $send_email );
159 -
160 - return $sent;
182 +
183 + return '';
161 184 }
162 185
163 186 function wppb_activate_account_check(){
164 187 if ( ( isset( $_GET['activation_key'] ) ) && ( trim( $_GET['activation_key'] ) != '' ) ){
165 188 global $post;
189 + $activation_key = sanitize_text_field( $_GET['activation_key'] );
166 190
167 191 $wppb_generalSettings = get_option( 'wppb_general_settings' );
168 192 $activation_landing_page_id = ( ( isset( $wppb_generalSettings['activationLandingPage'] ) && ( trim( $wppb_generalSettings['activationLandingPage'] ) != '' ) ) ? $wppb_generalSettings['activationLandingPage'] : 'not_set' );
169 193
@@ -173,9 +197,9 @@
173 197 add_filter( 'the_content', 'wppb_add_activation_message' );
174 198
175 199 }elseif ( strpos( $post->post_content, '[wppb-register' ) === false ){
176 200 //no activation page was selected, and the sent link pointed to the home url
177 - wp_redirect( apply_filters( 'wppb_activatate_account_redirect_url', WPPB_PLUGIN_URL.'assets/misc/fallback-page.php?activation_key='.urlencode( $_GET['activation_key'] ).'&site_name='.urlencode( get_bloginfo( 'name' ) ).'&site_url='.urlencode( get_bloginfo( 'url' ) ).'&message='.urlencode( $activation_message = wppb_activate_signup( $_GET['activation_key'] ) ), $_GET['activation_key'], $activation_message ) );
201 + wp_redirect( apply_filters( 'wppb_activatate_account_redirect_url', WPPB_PLUGIN_URL.'assets/misc/fallback-page.php?activation_key='.urlencode( $activation_key ).'&site_name='.urlencode( get_bloginfo( 'name' ) ).'&site_url='.urlencode( get_bloginfo( 'url' ) ).'&message='.urlencode( $activation_message = wppb_activate_signup( $activation_key ) ), $activation_key, $activation_message ) );
178 202 exit;
179 203 }
180 204 }
181 205 }
@@ -183,22 +207,22 @@
183 207
184 208
185 209 function wppb_add_activation_message( $content ){
186 210
187 - return wppb_activate_signup( $_GET['activation_key'] ) . $content;
211 + return wppb_activate_signup( sanitize_text_field( $_GET['activation_key'] ) ) . $content;
188 212 }
189 213
190 214
191 215 // Create a new, top-level page
192 216 $args = array(
193 - 'page_title' => __( 'Profile Builder', 'profilebuilder' ),
194 - 'menu_title' => __( 'Profile Builder', 'profilebuilder' ),
217 + 'page_title' => 'Profile Builder',
218 + 'menu_title' => 'Profile Builder',
195 219 'capability' => 'manage_options',
196 220 'menu_slug' => 'profile-builder',
197 221 'page_type' => 'menu_page',
198 222 'position' => '70,69',
199 223 'priority' => 1,
200 - 'icon_url' => WPPB_PLUGIN_URL . 'assets/images/pb_menu_icon.png'
224 + 'icon_url' => WPPB_PLUGIN_URL . 'assets/images/pb-menu-icon.png'
201 225 );
202 226 new WCK_Page_Creator_PB( $args );
203 227
204 228 /**
@@ -220,25 +244,48 @@
220 244 *
221 245 * @return void
222 246 */
223 247 function wppb_print_cpt_script( $hook ){
248 + wp_enqueue_script( 'jquery-ui-dialog' );
249 + wp_enqueue_style( 'wp-jquery-ui-dialog' );
250 +
224 251 if ( $hook == 'profile-builder_page_manage-fields' ){
225 252 wp_enqueue_script( 'wppb-manage-fields-live-change', WPPB_PLUGIN_URL . 'assets/js/jquery-manage-fields-live-change.js', array(), PROFILE_BUILDER_VERSION, true );
226 253 }
227 -
228 - if ( ( $hook == 'profile-builder_page_manage-fields' ) || ( $hook == 'profile-builder_page_profile-builder-basic-info' ) || ( $hook == 'profile-builder_page_profile-builder-modules' ) || ( $hook == 'profile-builder_page_profile-builder-general-settings' ) || ( $hook == 'profile-builder_page_profile-builder-admin-bar-settings' ) || ( $hook == 'profile-builder_page_profile-builder-register' ) || ( $hook == 'profile-builder_page_profile-builder-wppb_userListing' ) || ( $hook == 'profile-builder_page_profile-builder-wppb_customRedirect' ) || ( $hook == 'profile-builder_page_profile-builder-wppb_emailCustomizer' ) || ( $hook == 'profile-builder_page_profile-builder-wppb_emailCustomizerAdmin' ) ){
229 - wp_enqueue_style( 'wppb-back-end-style', WPPB_PLUGIN_URL . 'assets/css/style-back-end.css', false, PROFILE_BUILDER_VERSION );
254 +
255 + if (( $hook == 'profile-builder_page_manage-fields' ) ||
256 + ( $hook == 'profile-builder_page_profile-builder-basic-info' ) ||
257 + ( $hook == 'profile-builder_page_profile-builder-modules' ) ||
258 + ( $hook == 'profile-builder_page_profile-builder-general-settings' ) ||
259 + ( $hook == 'profile-builder_page_profile-builder-admin-bar-settings' ) ||
260 + ( $hook == 'profile-builder_page_profile-builder-register' ) ||
261 + ( $hook == 'profile-builder_page_profile-builder-wppb_userListing' ) ||
262 + ( $hook == 'profile-builder_page_custom-redirects' ) ||
263 + ( $hook == 'profile-builder_page_profile-builder-wppb_emailCustomizer' ) ||
264 + ( $hook == 'profile-builder_page_profile-builder-wppb_emailCustomizerAdmin' ) ||
265 + ( $hook == 'profile-builder_page_profile-builder-add-ons' ) ||
266 + ( $hook == 'profile-builder_page_profile-builder-woocommerce-sync' ) ||
267 + ( $hook == 'profile-builder_page_profile-builder-bbpress') ||
268 + ( $hook == 'admin_page_profile-builder-pms-promo') ) {
269 + wp_enqueue_style( 'wppb-back-end-style', WPPB_PLUGIN_URL . 'assets/css/style-back-end.css', false, PROFILE_BUILDER_VERSION );
230 270 }
231 271
232 272 if ( $hook == 'profile-builder_page_profile-builder-general-settings' )
233 273 wp_enqueue_script( 'wppb-manage-fields-live-change', WPPB_PLUGIN_URL . 'assets/js/jquery-email-confirmation.js', array(), PROFILE_BUILDER_VERSION, true );
234 -
274 +
275 + if( ($hook == 'profile-builder_page_profile-builder-add-ons' ) ||
276 + ($hook == 'admin_page_profile-builder-pms-promo' ) ) {
277 + wp_enqueue_script('wppb-add-ons', WPPB_PLUGIN_URL . 'assets/js/jquery-pb-add-ons.js', array(), PROFILE_BUILDER_VERSION, true);
278 + wp_enqueue_style( 'thickbox' );
279 + wp_enqueue_script( 'thickbox' );
280 + }
281 +
235 282 if ( isset( $_GET['post_type'] ) || isset( $_GET['post'] ) ){
236 283 if ( isset( $_GET['post_type'] ) )
237 - $post_type = $_GET['post_type'];
284 + $post_type = sanitize_text_field( $_GET['post_type'] );
238 285
239 286 elseif ( isset( $_GET['post'] ) )
240 - $post_type = get_post_type( $_GET['post'] );
287 + $post_type = get_post_type( absint( $_GET['post'] ) );
241 288
242 289 if ( ( 'wppb-epf-cpt' == $post_type ) || ( 'wppb-rf-cpt' == $post_type ) || ( 'wppb-ul-cpt' == $post_type ) ){
243 290 wp_enqueue_style( 'wppb-back-end-style', WPPB_PLUGIN_URL . 'assets/css/style-back-end.css', false, PROFILE_BUILDER_VERSION );
244 291 wp_enqueue_script( 'wppb-epf-rf', WPPB_PLUGIN_URL . 'assets/js/jquery-epf-rf.js', array(), PROFILE_BUILDER_VERSION, true );
@@ -244,78 +291,82 @@
244 291 wp_enqueue_script( 'wppb-epf-rf', WPPB_PLUGIN_URL . 'assets/js/jquery-epf-rf.js', array(), PROFILE_BUILDER_VERSION, true );
245 292 }
246 293 }
247 294 if ( file_exists ( WPPB_PLUGIN_DIR.'/update/update-checker.php' ) ) {
248 - wp_enqueue_style( 'wppb-serial-notice-css', WPPB_PLUGIN_URL . 'assets/css/serial-notice.css', false, PROFILE_BUILDER_VERSION );
249 295 wp_enqueue_script( 'wppb-sitewide', WPPB_PLUGIN_URL . 'assets/js/jquery-pb-sitewide.js', array(), PROFILE_BUILDER_VERSION, true );
250 296 }
297 + wp_enqueue_style( 'wppb-serial-notice-css', WPPB_PLUGIN_URL . 'assets/css/serial-notice.css', false, PROFILE_BUILDER_VERSION );
251 298 }
252 299 add_action( 'admin_enqueue_scripts', 'wppb_print_cpt_script' );
253 300
254 301
255 -// Set up the AJAX hooks
256 -function wppb_delete(){
257 - if ( isset( $_POST['_ajax_nonce'] ) ){
258 -
259 - if ( ( isset( $_POST['what'] ) ) && ( $_POST['what'] == 'avatar' ) ){
260 - if ( !wp_verify_nonce( $_POST['_ajax_nonce'], 'user'.base64_decode( $_POST['currentUser'] ).'_nonce_avatar' ) ){
261 - echo __( 'The user-validation has failed - the avatar was not deleted!', 'profilebuilder' );
262 - die();
263 -
264 - }else{
265 - update_user_meta( base64_decode( $_POST['currentUser'] ), base64_decode( $_POST['customFieldName'] ), '');
266 - update_user_meta( base64_decode( $_POST['currentUser'] ), 'resized_avatar_'.base64_decode( $_POST['customFieldID'] ), '' );
267 - echo 'done';
268 - die();
269 - }
270 - }elseif ( ( isset( $_POST['what'] ) ) && ( $_POST['what'] == 'attachment' ) ){
271 - if ( !wp_verify_nonce( $_POST['_ajax_nonce'], 'user'.base64_decode( $_POST['currentUser'] ).'_nonce_upload' ) ){
272 - echo __( 'The user-validation has failed - the attachment was not deleted!', 'profilebuilder' );
273 - die();
274 -
275 - }else{
276 - update_user_meta( base64_decode( $_POST['currentUser'] ), base64_decode( $_POST['customFieldName'] ), '');
277 - echo 'done';
278 - die();
279 - }
280 - }
281 - }
282 -}
283 -add_action( 'wp_ajax_hook_wppb_delete', 'wppb_delete' );
284 -
285 -
286 302 //the function used to overwrite the avatar across the wp installation
287 303 function wppb_changeDefaultAvatar( $avatar, $id_or_email, $size, $default, $alt ){
288 -
289 - global $wpdb;
290 -
291 - /* Get user info. */
304 + /* Get user info. */
292 305 if(is_object($id_or_email)){
293 306 $my_user_id = $id_or_email->user_id;
294 -
307 +
295 308 }elseif(is_numeric($id_or_email)){
296 - $my_user_id = $id_or_email;
297 -
309 + $my_user_id = $id_or_email;
310 +
298 311 }elseif(!is_integer($id_or_email)){
299 312 $user_info = get_user_by( 'email', $id_or_email );
300 313 $my_user_id = ( is_object( $user_info ) ? $user_info->ID : '' );
301 - }else
302 - $my_user_id = $id_or_email;
314 + }else
315 + $my_user_id = $id_or_email;
303 316
304 317 $wppb_manage_fields = get_option( 'wppb_manage_fields', 'not_found' );
305 -
306 318 if ( $wppb_manage_fields != 'not_found' ){
307 319 foreach( $wppb_manage_fields as $value ){
308 320 if ( $value['field'] == 'Avatar'){
309 - $customUserAvatar = get_user_meta( $my_user_id, 'resized_avatar_'.$value['id'], true );
310 -
311 - if (($customUserAvatar != '') || ($customUserAvatar != null)){
312 - $avatar = "<img alt='{$alt}' src='{$customUserAvatar}' class='avatar avatar-{$value['avatar-size']} photo avatar-default' height='{$size}' width='{$size}' />";
321 + $avatar_field = $value;
322 + }
323 + }
324 + }
325 +
326 + /* for multisite if we don't have an avatar try to get it from the main blog */
327 + if( is_multisite() && empty( $avatar_field ) ){
328 + switch_to_blog(1);
329 + $wppb_switched_blog = true;
330 + $wppb_manage_fields = get_option( 'wppb_manage_fields', 'not_found' );
331 + if ( $wppb_manage_fields != 'not_found' ){
332 + foreach( $wppb_manage_fields as $value ){
333 + if ( $value['field'] == 'Avatar'){
334 + $avatar_field = $value;
313 335 }
314 336 }
315 337 }
316 338 }
317 339
340 + if ( !empty( $avatar_field ) ){
341 +
342 + $customUserAvatar = get_user_meta( $my_user_id, Wordpress_Creation_Kit_PB::wck_generate_slug( $avatar_field['meta-name'] ), true );
343 + if( !empty( $customUserAvatar ) ){
344 + if( is_numeric( $customUserAvatar ) ){
345 + $img_attr = wp_get_attachment_image_src( $customUserAvatar, 'wppb-avatar-size-'.$size );
346 + if( $img_attr[3] === false ){
347 + $img_attr = wp_get_attachment_image_src( $customUserAvatar, 'thumbnail' );
348 + $avatar = "<img alt='{$alt}' src='{$img_attr[0]}' class='avatar avatar-{$size} photo avatar-default' height='{$size}' width='{$size}' />";
349 + }
350 + else
351 + $avatar = "<img alt='{$alt}' src='{$img_attr[0]}' class='avatar avatar-{$size} photo avatar-default' height='{$img_attr[2]}' width='{$img_attr[1]}' />";
352 + }
353 + else {
354 + $customUserAvatar = get_user_meta($my_user_id, 'resized_avatar_' . $avatar_field['id'], true);
355 + $customUserAvatarRelativePath = get_user_meta($my_user_id, 'resized_avatar_' . $avatar_field['id'] . '_relative_path', true);
356 +
357 + if ((($customUserAvatar != '') || ($customUserAvatar != null)) && file_exists($customUserAvatarRelativePath)) {
358 + $avatar = "<img alt='{$alt}' src='{$customUserAvatar}' class='avatar avatar-{$size} photo avatar-default' height='{$size}' width='{$size}' />";
359 + }
360 + }
361 + }
362 +
363 + }
364 +
365 + /* if we switched the blog restore it */
366 + if( is_multisite() && !empty( $wppb_switched_blog ) && $wppb_switched_blog )
367 + restore_current_blog();
368 +
318 369 return $avatar;
319 370 }
320 371 add_filter( 'get_avatar', 'wppb_changeDefaultAvatar', 21, 5 );
321 372
@@ -323,69 +374,107 @@
323 374 //the function used to resize the avatar image; the new function uses a user ID as parameter to make pages load faster
324 375 function wppb_resize_avatar( $userID, $userlisting_size = null, $userlisting_crop = null ){
325 376 // include the admin image API
326 377 require_once( ABSPATH . '/wp-admin/includes/image.php' );
327 -
378 +
328 379 // retrieve first a list of all the current custom fields
329 - $wppb_manage_fields = get_option( 'wppb_manage_fields' );
330 -
331 - foreach ( $wppb_manage_fields as $key => $value ){
332 - if ( $value['field'] == 'Avatar' ){
333 -
334 - // retrieve width and height of the image
335 - $width = $height = '';
336 -
337 - //this checks if it only has 1 component
338 - if ( is_numeric( $value['avatar-size'] ) ){
339 - $width = $height = $value['avatar-size'];
380 + $wppb_manage_fields = get_option( 'wppb_manage_fields', 'not_found' );
381 + if ( $wppb_manage_fields != 'not_found' ){
382 + foreach( $wppb_manage_fields as $value ){
383 + if ( $value['field'] == 'Avatar'){
384 + $avatar_field = $value;
385 + }
386 + }
387 + }
340 388
341 - }else{
342 - //this checks if the entered value has 2 components
343 - $sentValue = explode( ',', $value['avatar-size'] );
344 - $width = $sentValue[0];
345 - $height = $sentValue[1];
389 + /* for multisite if we don't have an avatar try to get it from the main blog */
390 + if( is_multisite() && empty( $avatar_field ) ){
391 + switch_to_blog(1);
392 + $wppb_switched_blog = true;
393 + $wppb_manage_fields = get_option( 'wppb_manage_fields', 'not_found' );
394 + if ( $wppb_manage_fields != 'not_found' ){
395 + foreach( $wppb_manage_fields as $value ){
396 + if ( $value['field'] == 'Avatar'){
397 + $avatar_field = $value;
398 + }
346 399 }
347 -
348 - $width = ( !empty( $userlisting_size ) ? $userlisting_size : $width );
349 - $height = ( !empty( $userlisting_size ) ? $userlisting_size : $height );
350 -
400 + }
401 + }
402 +
403 +
404 + if ( !empty( $avatar_field ) ){
405 +
406 + // retrieve width and height of the image
407 + $width = $height = '';
408 +
409 + //this checks if it only has 1 component
410 + if ( is_numeric( $avatar_field['avatar-size'] ) ){
411 + $width = $height = $avatar_field['avatar-size'];
412 +
413 + }else{
414 + //this checks if the entered value has 2 components
415 + $sentValue = explode( ',', $avatar_field['avatar-size'] );
416 + $width = $sentValue[0];
417 + $height = $sentValue[1];
418 + }
419 +
420 + $width = ( !empty( $userlisting_size ) ? $userlisting_size : $width );
421 + $height = ( !empty( $userlisting_size ) ? $userlisting_size : $height );
422 +
423 + if( !strpos( get_user_meta( $userID, 'resized_avatar_'.$avatar_field['id'], true ), $width . 'x' . $height ) ) {
351 424 // retrieve the original image (in original size)
352 - $avatar_directory_path = get_user_meta( $userID, 'avatar_directory_path_'.$value['id'], true );
353 -
354 - $image = wp_get_image_editor( $avatar_directory_path );
425 + $avatar_directory_path = get_user_meta( $userID, 'avatar_directory_path_'.$avatar_field['id'], true );
426 +
427 + $image = wp_get_image_editor( $avatar_directory_path );
355 428 if ( !is_wp_error( $image ) ) {
356 - do_action( 'wppb_before_avatar_resizing', $image, $userID, $value['meta-name'], $value['avatar-size'] );
357 -
429 + do_action( 'wppb_before_avatar_resizing', $image, $userID, Wordpress_Creation_Kit_PB::wck_generate_slug( $avatar_field['meta-name'] ), $avatar_field['avatar-size'] );
430 +
358 431 $crop = apply_filters( 'wppb_avatar_crop_resize', ( !empty( $userlisting_crop ) ? $userlisting_crop : false ) );
359 -
432 +
360 433 $resize = $image->resize( $width, $height, $crop );
361 -
434 +
362 435 if ($resize !== FALSE) {
363 436 do_action( 'wppb_avatar_resizing', $image, $resize );
364 -
437 +
365 438 $fileType = apply_filters( 'wppb_resized_file_extension', 'png' );
366 -
439 +
367 440 $wp_upload_array = wp_upload_dir(); // Array of key => value pairs
368 -
441 +
369 442 //create file(name); both with directory and url
370 443 $fileName_dir = $image->generate_filename( NULL, $wp_upload_array['basedir'].'/profile_builder/avatars/', $fileType );
371 -
444 +
372 445 if ( PHP_OS == "WIN32" || PHP_OS == "WINNT" )
373 446 $fileName_dir = str_replace( '\\', '/', $fileName_dir );
374 -
447 +
375 448 $fileName_url = str_replace( str_replace( '\\', '/', $wp_upload_array['basedir'] ), $wp_upload_array['baseurl'], $fileName_dir );
376 449
377 450 //save the newly created (resized) avatar on the disc
378 - $image->save( $fileName_dir );
379 -
380 - update_user_meta( $userID, 'resized_avatar_'.$value['id'], $fileName_url );
381 - update_user_meta( $userID, 'resized_avatar_'.$value['id'].'_relative_path', $fileName_dir );
382 -
383 - do_action( 'wppb_after_avatar_resizing', $image, $fileName_dir, $fileName_url );
451 + $saved_image = $image->save( $fileName_dir );
452 +
453 + if ( !is_wp_error( $saved_image ) ) {
454 + /* the image save sometimes doesn't save with the desired extension so we need to see with what extension it saved it with and
455 + if it differs replace the extension in the path and url that we save as meta */
456 + $validate_saved_image = wp_check_filetype_and_ext( $saved_image['path'], $saved_image['path'] );
457 + $ext = substr( $fileName_dir,strrpos( $fileName_dir, '.', -1 ), strlen($fileName_dir) );
458 + if( !empty( $validate_saved_image['ext'] ) && $validate_saved_image['ext'] != $ext ){
459 + $fileName_url = str_replace( $ext, '.'.$validate_saved_image['ext'], $fileName_url );
460 + $fileName_dir = str_replace( $ext, '.'.$validate_saved_image['ext'], $fileName_dir );
461 + }
462 +
463 + update_user_meta( $userID, 'resized_avatar_'.$avatar_field['id'], $fileName_url );
464 + update_user_meta( $userID, 'resized_avatar_'.$avatar_field['id'].'_relative_path', $fileName_dir );
465 +
466 + do_action( 'wppb_after_avatar_resizing', $image, $fileName_dir, $fileName_url );
467 + }
384 468 }
385 469 }
386 470 }
387 471 }
472 +
473 + /* if we switched the blog restore it */
474 + if( is_multisite() && !empty( $wppb_switched_blog ) && $wppb_switched_blog )
475 + restore_current_blog();
476 +
388 477 }
389 478
390 479
391 480 if ( is_admin() ){
@@ -398,19 +487,16 @@
398 487 $delete = $wpdb->delete( $wpdb->signups, array( 'user_login' => $userLogin ) );
399 488 else
400 489 $delete = $wpdb->delete( $wpdb->prefix.'signups', array( 'user_login' => $userLogin ) );
401 490 }
402 -
403 - if ( is_multisite() )
404 - add_action( 'wpmu_delete_user', 'wppb_delete_user_from_signups_table' );
405 -
406 - else{
407 - $wppb_generalSettings = get_option( 'wppb_general_settings' );
408 -
409 - if ( $wppb_generalSettings['emailConfirmation'] == 'yes' )
410 - add_action( 'delete_user', 'wppb_delete_user_from_signups_table' );
411 - }
412 491
492 + $wppb_generalSettings = get_option( 'wppb_general_settings' );
493 + if ( !empty( $wppb_generalSettings['emailConfirmation'] ) && ( $wppb_generalSettings['emailConfirmation'] == 'yes' ) ) {
494 + if( is_multisite() )
495 + add_action( 'wpmu_delete_user', 'wppb_delete_user_from_signups_table' );
496 + else
497 + add_action('delete_user', 'wppb_delete_user_from_signups_table');
498 + }
413 499 }
414 500
415 501
416 502
@@ -439,9 +525,9 @@
439 525 //function to output the password strength checker on frontend forms
440 526 function wppb_password_strength_checker_html(){
441 527 $wppb_generalSettings = get_option( 'wppb_general_settings' );
442 528 if( !empty( $wppb_generalSettings['minimum_password_strength'] ) ){
443 - $password_strength = '<span id="pass-strength-result">'.__('Strength indicator', 'profilebuilder' ).'</span>
529 + $password_strength = '<span id="pass-strength-result">'.__('Strength indicator', 'profile-builder' ).'</span>
444 530 <input type="hidden" value="" name="wppb_password_strength" id="wppb_password_strength"/>';
445 531 return $password_strength;
446 532 }
447 533 return '';
@@ -463,11 +549,12 @@
463 549 //function to check password strength
464 550 function wppb_check_password_strength(){
465 551 $wppb_generalSettings = get_option( 'wppb_general_settings' );
466 552 if( isset( $_POST['wppb_password_strength'] ) && !empty( $wppb_generalSettings['minimum_password_strength'] ) ){
553 + $wppb_password_strength = sanitize_text_field( $_POST['wppb_password_strength'] );
467 554 $password_strength_array = array( 'short' => 0, 'bad' => 1, 'good' => 2, 'strong' => 3 );
468 - $password_strength_text = array( 'short' => __( 'Very Week', 'profilebuilder' ), 'bad' => __( 'Week', 'profilebuilder' ), 'good' => __( 'Medium', 'profilebuilder' ), 'strong' => __( 'Strong', 'profilebuilder' ) );
469 - if( $password_strength_array[$_POST['wppb_password_strength']] < $password_strength_array[$wppb_generalSettings['minimum_password_strength']] ){
555 + $password_strength_text = array( 'short' => __( 'Very Weak', 'profile-builder' ), 'bad' => __( 'Weak', 'profile-builder' ), 'good' => __( 'Medium', 'profile-builder' ), 'strong' => __( 'Strong', 'profile-builder' ) );
556 + if( $password_strength_array[$wppb_password_strength] < $password_strength_array[$wppb_generalSettings['minimum_password_strength']] ){
470 557 return $password_strength_text[$wppb_generalSettings['minimum_password_strength']];
471 558 }
472 559 else
473 560 return false;
@@ -478,13 +565,27 @@
478 565 /* function to output password length requirements text */
479 566 function wppb_password_length_text(){
480 567 $wppb_generalSettings = get_option( 'wppb_general_settings' );
481 568 if( !empty( $wppb_generalSettings['minimum_password_length'] ) ){
482 - return __( 'Minimum length of '. $wppb_generalSettings['minimum_password_length'] .' characters', 'profilebuilder' );
569 + return sprintf(__('Minimum length of %d characters.', 'profile-builder'), $wppb_generalSettings['minimum_password_length']);
483 570 }
484 571 return '';
485 572 }
486 573
574 +/* function to output password strength requirements text */
575 +function wppb_password_strength_description() {
576 + $wppb_generalSettings = get_option( 'wppb_general_settings' );
577 +
578 + if( ! empty( $wppb_generalSettings['minimum_password_strength'] ) ) {
579 + $password_strength_text = array( 'short' => __( 'Very Weak', 'profile-builder' ), 'bad' => __( 'Weak', 'profile-builder' ), 'good' => __( 'Medium', 'profile-builder' ), 'strong' => __( 'Strong', 'profile-builder' ) );
580 + $password_strength_description = '<br>'. sprintf( __( 'The password must have a minimum strength of %s.', 'profile-builder' ), $password_strength_text[$wppb_generalSettings['minimum_password_strength']] );
581 +
582 + return $password_strength_description;
583 + } else {
584 + return '';
585 + }
586 +}
587 +
487 588 /**
488 589 * Include password strength check scripts on frontend where we have shortoces present
489 590 */
490 591 add_action( 'wp_footer', 'wppb_enqueue_password_strength_check' );
@@ -552,14 +653,393 @@
552 653 /**
553 654 * Create functions for repeating error messages in front-end forms
554 655 */
555 656 function wppb_required_field_error($field_title='') {
556 - $required_error = __(apply_filters('wppb_required_error' , 'This field is required' , $field_title),'profilebuilder');
657 + $required_error = apply_filters('wppb_required_error' , __('This field is required','profile-builder') , $field_title);
557 658
558 659 return $required_error;
559 660
560 661 }
561 662
663 +/**
664 + * Function that returns a certain field (from manage_fields) by a given id or meta_name
665 + */
666 +function wppb_get_field_by_id_or_meta( $id_or_meta ){
667 +
668 + $id = 0;
669 + $meta = '';
670 +
671 + if ( is_numeric($id_or_meta) )
672 + $id = $id_or_meta;
673 + else
674 + $meta = $id_or_meta;
675 +
676 + $fields = get_option('wppb_manage_fields', 'not_found');
677 +
678 + if ($fields != 'not_found') {
679 +
680 + foreach ($fields as $key => $field) {
681 + if ( (!empty($id)) && ($field['id'] == $id) )
682 + return $field;
683 + if ( (!empty($meta)) && ($field['meta-name'] == $meta) )
684 + return $field;
685 + }
686 +
687 + }
688 +
689 + return '';
690 +}
691 +
692 +
693 +/* Function for displaying reCAPTCHA error on Login and Recover Password forms */
694 +function wppb_recaptcha_field_error($field_title='') {
695 + $recaptcha_error = apply_filters('wppb_recaptcha_error' , __('Please enter a (valid) reCAPTCHA value','profile-builder') , $field_title);
696 +
697 + return $recaptcha_error;
698 +
699 +}
700 +/* Function for displaying phone field error */
701 +function wppb_phone_field_error( $field_title = '' ) {
702 + $phone_error = apply_filters( 'wppb_phone_error' , __( 'Incorrect phone number', 'profile-builder' ) , $field_title );
703 +
704 + return $phone_error;
705 +}
706 +
562 707 /* Create a wrapper function for get_query_var */
563 708 function wppb_get_query_var( $varname ){
564 709 return apply_filters( 'wppb_get_query_var_'.$varname, get_query_var( $varname ) );
565 710 }
711 +
712 +/* Filter the "Save Changes" button text, to make it translatable */
713 +function wppb_change_save_changes_button($value){
714 + $value = __('Save Changes','profile-builder');
715 + return $value;
716 +}
717 +add_filter( 'wck_save_changes_button', 'wppb_change_save_changes_button', 10, 2);
718 +
719 +/* Filter the "Cancel" button text, to make it translatable */
720 +function wppb_change_cancel_button($value){
721 + $value = __('Cancel','profile-builder');
722 + return $value;
723 +}
724 +add_filter( 'wck_cancel_button', 'wppb_change_cancel_button', 10, 2);
725 +
726 +/* ilter the "Delete" button text, to make it translatable */
727 +function wppb_change_delete_button($value){
728 + $value = __('Delete','profile-builder');
729 + return $value;
730 +}
731 +add_filter( 'wck_delete_button', 'wppb_change_delete_button', 10, 2);
732 +
733 +/*Filter the "Edit" button text, to make it translatable*/
734 +function wppb_change_edit_button($value){
735 + $value = __('Edit','profile-builder');
736 + return $value;
737 +}
738 +add_filter( 'wck_edit_button', 'wppb_change_edit_button', 10, 2);
739 +
740 +/*Filter the User Listing, Register Forms and Edit Profile forms metabox header content, to make it translatable*/
741 +function wppb_change_metabox_content_header(){
742 + return '<thead><tr><th class="wck-number">#</th><th class="wck-content">'. __( 'Content', 'profile-builder' ) .'</th><th class="wck-edit">'. __( 'Edit', 'profile-builder' ) .'</th><th class="wck-delete">'. __( 'Delete', 'profile-builder' ) .'</th></tr></thead>';
743 +}
744 +add_filter('wck_metabox_content_header_wppb_ul_page_settings', 'wppb_change_metabox_content_header', 1);
745 +add_filter('wck_metabox_content_header_wppb_rf_page_settings', 'wppb_change_metabox_content_header', 1);
746 +add_filter('wck_metabox_content_header_wppb_epf_page_settings', 'wppb_change_metabox_content_header', 1);
747 +
748 +
749 +/* Add a notice if people are not able to register via Profile Builder; Membership -> "Anyone can register" checkbox is not checked under WordPress admin UI -> Settings -> General tab */
750 +if ( (get_option('users_can_register') == false) && (!class_exists('PMS_Add_General_Notices')) ) {
751 + if( is_multisite() ) {
752 + new WPPB_Add_General_Notices('wppb_anyone_can_register',
753 + sprintf(__('To allow users to register for your website via Profile Builder, you first must enable user registration. Go to %1$sNetwork Settings%2$s, and under Registration Settings make sure to check “User accounts may be registered”. %3$sDismiss%4$s', 'profile-builder'), "<a href='" . network_admin_url('settings.php') . "'>", "</a>", "<a href='" . esc_url( add_query_arg('wppb_anyone_can_register_dismiss_notification', '0') ) . "'>", "</a>"),
754 + 'update-nag');
755 + }else{
756 + new WPPB_Add_General_Notices('wppb_anyone_can_register',
757 + sprintf(__('To allow users to register for your website via Profile Builder, you first must enable user registration. Go to %1$sSettings -> General%2$s tab, and under Membership make sure to check “Anyone can register”. %3$sDismiss%4$s', 'profile-builder'), "<a href='" . admin_url('options-general.php') . "'>", "</a>", "<a href='" . esc_url( add_query_arg('wppb_anyone_can_register_dismiss_notification', '0') ) . "'>", "</a>"),
758 + 'update-nag');
759 + }
760 +}
761 +
762 +/*Filter default WordPress notices ("Post published. Post updated."), add post type name for User Listing, Registration Forms and Edit Profile Forms*/
763 +function wppb_change_default_post_updated_messages($messages){
764 + global $post;
765 + $post_type = get_post_type($post->ID);
766 + $object = get_post_type_object($post_type);
767 +
768 + if ( ($post_type == 'wppb-rf-cpt')||($post_type == 'wppb-epf-cpt')||($post_type == 'wppb-ul-cpt') ){
769 + $messages['post'][1] = $object->labels->name . ' updated.';
770 + $messages['post'][6] = $object->labels->name . ' published.';
771 + }
772 + return $messages;
773 +}
774 +add_filter('post_updated_messages','wppb_change_default_post_updated_messages', 2);
775 +
776 +
777 +/* for meta-names with spaces in them PHP converts the space to underline in the $_POST */
778 +function wppb_handle_meta_name( $meta_name ){
779 + $meta_name = str_replace( ' ', '_', $meta_name );
780 + $meta_name = str_replace( '.', '_', $meta_name );
781 + return $meta_name;
782 +}
783 +
784 +
785 +// change User Registered date and time according to timezone selected in WordPress settings
786 +function wppb_get_date_by_timezone() {
787 + $wppb_wp_timezone = get_option( 'timezone_string' );
788 +
789 + if( ! empty( $wppb_wp_timezone ) ) {
790 + date_default_timezone_set( $wppb_wp_timezone );
791 + $wppb_get_date = date( "Y-m-d G:i:s" );
792 + } else {
793 + $wppb_wp_gmt_offset = get_option( 'gmt_offset' );
794 + $wppb_gmt_offset = $wppb_wp_gmt_offset * 60 * 60;
795 + $wppb_get_date = gmdate( "Y-m-d G:i:s", time() + $wppb_gmt_offset );
796 + }
797 +
798 + return $wppb_get_date;
799 +}
800 +
801 +/**
802 + * Add HTML tag 'required' to fields
803 + *
804 + * Add HTML tag 'required' for each field if the field is required. For browsers that don't support this HTML tag, we will still have the fallback.
805 + * Field type 'Checkbox' is explicitly excluded because there is no HTML support to check if at least one option is selected.
806 + * Other fields excluded are Avatar, Upload, Heading, ReCaptcha, WYSIWYG, Map.
807 + *
808 + * @since
809 + *
810 + * @param string $extra_attributes Extra attributes attached to the field HTML tag.
811 + * @param array $field Field description.
812 + * @return string $extra_attributes
813 + */
814 +function wppb_add_html_tag_required_to_fields( $extra_attributes, $field, $form_location ) {
815 + if ( $field['field'] != "Checkbox" && isset( $field['required'] ) && $field['required'] == 'Yes' ){
816 + if( !( ( $field['field'] == "Default - Password" || $field['field'] == "Default - Repeat Password" ) && $form_location == 'edit_profile' ) )
817 + $extra_attributes .= ' required ';
818 + }
819 + return $extra_attributes;
820 +}
821 +add_filter( 'wppb_extra_attribute', 'wppb_add_html_tag_required_to_fields', 10, 3 );
822 +
823 +/**
824 + * Add HTML tag 'required' to WooCommerce fields
825 + *
826 + * Add HTML tag 'required' for each WooCommerce field if the field is required. For browsers that don't support this HTML tag, we will still have the fallback.
827 + * Does not work on 'State / County' field, if it becomes required later depending on the Country Value
828 + *
829 + * @since
830 + *
831 + * @param string $extra_attributes Extra attributes attached to the field HTML tag.
832 + * @param array $field Field description.
833 + * @return string $extra_attributes
834 + */
835 +function wppb_add_html_tag_required_to_woo_fields( $extra_attributes, $field ) {
836 + if ( isset( $field['required'] ) && $field['required'] == 'Yes' ){
837 + $extra_attributes .= ' required ';
838 + }
839 + return $extra_attributes;
840 +}
841 +add_filter( 'wppb_woo_extra_attribute', 'wppb_add_html_tag_required_to_woo_fields', 10, 2 );
842 +
843 +
844 +/**
845 + * Add jQuery script to remove required attribute for hidden fields
846 + *
847 + * If a field is hidden dynamically via conditional fields or WooSync 'Ship to a different address' checkbox, then the required field needs to be removed.
848 + * If a field is made visible again, add the required field back again.
849 + *
850 + * @since
851 + *
852 + * @param string $extra_attributes Extra attributes attached to the field HTML tag.
853 + * @param array $field Field description.
854 + * @return string $extra_attributes
855 + */
856 +function wppb_manage_required_attribute() {
857 + global $wppb_shortcode_on_front;
858 + if ($wppb_shortcode_on_front) {
859 + ?>
860 + <script type="text/javascript">
861 + jQuery(document).on( "wppbAddRequiredAttributeEvent", wppbAddRequired );
862 + function wppbAddRequired(event) {
863 + var element = wppbEventTargetRequiredElement( event.target );
864 + if( jQuery( element ).attr( "wppb_cf_temprequired" ) ){
865 + jQuery( element ).removeAttr( "wppb_cf_temprequired" );
866 + jQuery( element ).attr( "required", "required" );
867 + }
868 + }
869 +
870 + jQuery(document).on( "wppbRemoveRequiredAttributeEvent", wppbRemoveRequired );
871 + function wppbRemoveRequired(event) {
872 + var element = wppbEventTargetRequiredElement( event.target );
873 + if ( jQuery( element ).attr( "required" ) ) {
874 + jQuery( element ).removeAttr( "required" );
875 + jQuery( element ).attr( "wppb_cf_temprequired", "wppb_cf_temprequired" );
876 + }
877 + }
878 +
879 + jQuery(document).on( "wppbToggleRequiredAttributeEvent", wppbToggleRequired );
880 + function wppbToggleRequired(event) {
881 + if ( jQuery( event.target ).attr( "required" ) ) {
882 + jQuery( event.target ).removeAttr( "required" );
883 + jQuery( event.target ).attr( "wppb_cf_temprequired", "wppb_cf_temprequired" );
884 + }else if( jQuery( event.target ).attr( "wppb_cf_temprequired" ) ){
885 + jQuery( event.target ).removeAttr( "wppb_cf_temprequired" );
886 + jQuery( event.target ).attr( "required", "required" );
887 + }
888 + }
889 +
890 + function wppbEventTargetRequiredElement( htmlElement ){
891 + if ( htmlElement.nodeName == "OPTION" ){
892 + // <option> is the target element, so we need to get the parent <select>, in order to apply the required attribute
893 + return htmlElement.parentElement;
894 + }else{
895 + return htmlElement;
896 + }
897 + }
898 +
899 + </script>
900 + <?php
901 + }
902 +}
903 +add_action( 'wp_footer', 'wppb_manage_required_attribute' );
904 +
905 +function wpbb_specify_blog_details_on_signup_email( $message, $user_email, $user, $activation_key, $registration_page_url, $meta, $from_name, $context ){
906 + $meta = unserialize($meta);
907 +
908 + if ( is_multisite() && isset( $meta['wppb_create_new_site_checkbox'] ) && $meta['wppb_create_new_site_checkbox'] == 'yes' ) {
909 + $blog_details = wpmu_validate_blog_signup( $meta['wppb_blog_url'], $meta['wppb_blog_title'] );
910 +
911 + if ( empty($blog_details['errors']->errors['blogname']) && empty($blog_details['errors']->errors['blog_title'])) {
912 + $blog_path = $blog_details['domain'] . $blog_details['path'];
913 + $message .= __( '<br><br>Also, you will be able to visit your site at ', 'profile-builder' ) . '<a href="' . $blog_path . '">' . $blog_path . '</a>.';
914 + }
915 + }
916 + return $message;
917 +}
918 +add_filter( 'wppb_signup_user_notification_email_content', 'wpbb_specify_blog_details_on_signup_email', 5, 8 );
919 +
920 +function wpbb_specify_blog_details_on_registration_email( $user_message_content, $email, $password, $user_message_subject, $context ){
921 +
922 + if ( is_multisite() ) {
923 + $user = get_user_by( 'email', $email );
924 + $blog_path = wppb_get_blog_url_of_user_id( $user->ID );
925 + if ( ! empty ( $blog_path ) ) {
926 + $user_message_content .= __( '<br><br>You can visit your site at ', 'profile-builder' ) . '<a href="' . $blog_path . '">' . $blog_path . '</a>.';
927 + }
928 + }
929 + return $user_message_content;
930 +
931 +}
932 +add_filter( 'wppb_register_user_email_message_without_admin_approval', 'wpbb_specify_blog_details_on_registration_email', 5, 5 );
933 +add_filter( 'wppb_register_user_email_message_with_admin_approval', 'wpbb_specify_blog_details_on_registration_email', 5, 5 );
934 +
935 +
936 +function wppb_get_blog_url_of_user_id( $user_id, $ignore_privacy = true ){
937 + $blog_id = get_user_meta( $user_id, 'primary_blog', true );
938 + if ( is_multisite() && !empty( $blog_id ) ){
939 + $blog_details = get_blog_details( $blog_id );
940 + if ( $ignore_privacy || $blog_details->public ) {
941 + return $blog_details->domain . $blog_details->path;
942 + }
943 + }
944 + return '';
945 +}
946 +
947 +function wppb_can_users_signup_blog(){
948 + if ( ! is_multisite() )
949 + return false;
950 + global $wpdb;
951 + $current_site = get_current_site();
952 + $sitemeta_options_query = $wpdb->prepare( "SELECT meta_value FROM {$wpdb->sitemeta} WHERE meta_key = 'registration' AND site_id = %d", $current_site->id );
953 + $network_options_meta = $wpdb->get_results( $sitemeta_options_query );
954 +
955 + if ( $network_options_meta[0]->meta_value == 'all' ){
956 + return true;
957 + }
958 + return false;
959 +}
960 +
961 +/**
962 + * Function that handle redirect URL
963 + *
964 + * @param string $redirect_priority - it can be normal or top priority
965 + * @param string $redirect_type - type of the redirect
966 + * @param null|string $redirect_url - redirect URL if already set
967 + * @param null|string|object $user - username, user email or user data
968 + * @param null|string $user_role - user role
969 + *
970 + * @return null|string $redirect_url
971 + */
972 +function wppb_get_redirect_url( $redirect_priority = 'normal', $redirect_type, $redirect_url = NULL, $user = NULL, $user_role = NULL ) {
973 + if( PROFILE_BUILDER == 'Profile Builder Pro' ) {
974 + $wppb_module_settings = get_option( 'wppb_module_settings' );
975 +
976 + if( isset( $wppb_module_settings['wppb_customRedirect'] ) && $wppb_module_settings['wppb_customRedirect'] == 'show' && $redirect_priority != 'top' && function_exists( 'wppb_custom_redirect_url' ) ) {
977 + $redirect_url = wppb_custom_redirect_url( $redirect_type, $redirect_url, $user, $user_role );
978 + }
979 + }
980 +
981 + if( ! empty( $redirect_url ) ) {
982 + $redirect_url = ( wppb_check_missing_http( $redirect_url ) ? 'http://'. $redirect_url : $redirect_url );
983 + }
984 +
985 + return $redirect_url;
986 +}
987 +
988 +/**
989 + * Function that builds the redirect
990 + *
991 + * @param string $redirect_url - redirect URL
992 + * @param int $redirect_delay - redirect delay in seconds
993 + * @param null|string $redirect_type - the type of the redirect
994 + * @param null|array $form_args - form args if set
995 + *
996 + * @return string $redirect_message
997 + */
998 +function wppb_build_redirect( $redirect_url, $redirect_delay, $redirect_type = NULL, $form_args = NULL ) {
999 + if( isset( $redirect_type ) ) {
1000 + $redirect_url = apply_filters( 'wppb_'. $redirect_type .'_redirect', $redirect_url );
1001 + }
1002 +
1003 + $redirect_message = '';
1004 +
1005 + if( ! empty( $redirect_url ) ) {
1006 + $redirect_url = ( wppb_check_missing_http( $redirect_url ) ? 'http://'. $redirect_url : $redirect_url );
1007 +
1008 + if( $redirect_delay == 0 ) {
1009 + $redirect_message = '<meta http-equiv="Refresh" content="'. $redirect_delay .';url='. $redirect_url .'" />';
1010 + } else {
1011 + $redirect_url_href = apply_filters( 'wppb_redirect_url', '<a href="'. $redirect_url .'">'. __( 'here', 'profile-builder' ) .'</a>', $redirect_url, $redirect_type, $form_args );
1012 + $redirect_message = apply_filters( 'wppb_redirect_message_before_returning', '<p class="redirect_message">'. sprintf( wp_slash( __( 'You will soon be redirected automatically. If you see this page for more than %1$d seconds, please click %2$s.%3$s', 'profile-builder' ) ), $redirect_delay, $redirect_url_href, '<meta http-equiv="Refresh" content="'. $redirect_delay .';url='. $redirect_url .'" />' ) .'</p>', $redirect_url, $redirect_delay, $redirect_url_href, $redirect_type, $form_args );
1013 + }
1014 + }
1015 +
1016 + return $redirect_message;
1017 +}
1018 +
1019 +/**
1020 + * Function that strips the script tags from an input
1021 + * @param $string
1022 + * @return mixed
1023 + */
1024 +function wppb_sanitize_value( $string ){
1025 + return preg_replace( '/<script\b[^>]*>(.*?)<\/script>/is', '', $string );
1026 +}
1027 +
1028 +/**
1029 + * Function that receives a user role and returns it's label.
1030 + * Returns the original role if not found.
1031 + *
1032 + * @since v.2.7.1
1033 + *
1034 + * @param string $role
1035 + *
1036 + * @return string
1037 + */
1038 +function wppb_get_role_name($role){
1039 + global $wp_roles;
1040 +
1041 + if ( array_key_exists( $role, $wp_roles->role_names ) )
1042 + return $wp_roles->role_names[$role];
1043 +
1044 + return '';
1045 +}