diff --git a/admin/assets/js/um-admin-scripts.js b/admin/assets/js/um-admin-scripts.js index c8c964ca..b367aaae 100644 --- a/admin/assets/js/um-admin-scripts.js +++ b/admin/assets/js/um-admin-scripts.js @@ -85,10 +85,12 @@ jQuery(document).ready(function() { Tooltips **/ - jQuery('.um-admin-tipsy-n,#redux-share a').tipsy({gravity: 'n', opacity: 1, live: 'a.live' }); - jQuery('.um-admin-tipsy-w').tipsy({gravity: 'w', opacity: 1, live: 'a.live' }); - jQuery('.um-admin-tipsy-e').tipsy({gravity: 'e', opacity: 1, live: 'a.live' }); - jQuery('.um-admin-tipsy-s').tipsy({gravity: 's', opacity: 1, live: 'a.live' }); + if( typeof tipsy !== 'undefined' ){ + jQuery('.um-admin-tipsy-n,#redux-share a').tipsy({gravity: 'n', opacity: 1, live: 'a.live' }); + jQuery('.um-admin-tipsy-w').tipsy({gravity: 'w', opacity: 1, live: 'a.live' }); + jQuery('.um-admin-tipsy-e').tipsy({gravity: 'e', opacity: 1, live: 'a.live' }); + jQuery('.um-admin-tipsy-s').tipsy({gravity: 's', opacity: 1, live: 'a.live' }); + } /** Conditional fields diff --git a/admin/templates/form/profile_customize.php b/admin/templates/form/profile_customize.php index d7d7bb05..162b074d 100644 --- a/admin/templates/form/profile_customize.php +++ b/admin/templates/form/profile_customize.php @@ -139,7 +139,15 @@
- + ++ + + ui_on_off('_um_profile_photo_required'); ?> + + +
+diff --git a/core/lib/upload/um-image-upload.php b/core/lib/upload/um-image-upload.php index 26e33ab9..d87f270d 100644 --- a/core/lib/upload/um-image-upload.php +++ b/core/lib/upload/um-image-upload.php @@ -33,7 +33,7 @@ if(isset($_FILES[$id]['name'])) { } else { $file = "stream_photo_".md5($file)."_".uniqid().".".$ext; - $ret[] = $ultimatemember->files->new_image_upload_temp( $temp, $file, um_get_option('image_compression') ); + $ret[ ] = $ultimatemember->files->new_image_upload_temp( $temp, $file, um_get_option('image_compression') ); } diff --git a/core/um-actions-form.php b/core/um-actions-form.php index 429a3934..e1f47115 100644 --- a/core/um-actions-form.php +++ b/core/um-actions-form.php @@ -152,6 +152,10 @@ $form_id = $args['form_id']; $mode = $args['mode']; $fields = unserialize( $args['custom_fields'] ); + + if ( get_post_meta( $form_id, '_um_profile_photo_required', true ) && empty( $args['profile_photo'] ) ) { + $ultimatemember->form->add_error('profile_photo', sprintf(__('%s is required.','ultimatemember'), 'Profile Photo' ) ); + } if( isset( $fields ) && ! empty( $fields ) ){ foreach( $fields as $key => $array ) { @@ -162,6 +166,10 @@ $ultimatemember->form->add_error($key, sprintf(__('%s is required.','ultimatemember'), $array['title'] ) ); } + if ( isset( $array['type'] ) && $array['type'] == 'user_tags' && isset( $array['required'] ) && $array['required'] == 1 && !isset( $args[$key] ) ) { + $ultimatemember->form->add_error($key, sprintf(__('%s is required.','ultimatemember'), $array['title'] ) ); + } + if ( isset( $array['type'] ) && $array['type'] == 'radio' && isset( $array['required'] ) && $array['required'] == 1 && !isset( $args[$key] ) && !in_array($key, array('role_radio','role_select') ) ) { $ultimatemember->form->add_error($key, sprintf(__('%s is required.','ultimatemember'), $array['title'] ) ); } @@ -350,7 +358,9 @@ if ( $args[$key] == '' && in_array( $key, array('user_email') ) ) { $ultimatemember->form->add_error($key, __('You must provide your email','ultimatemember') ); - } else if ( $mode == 'register' && email_exists( $args[$key] ) ) { + } else if ( in_array( $mode, array('register') ) && email_exists( $args[$key] ) ) { + $ultimatemember->form->add_error($key, __('This email is already linked to an existing account','ultimatemember') ); + } else if ( in_array( $mode, array('profile') ) && email_exists( $args[$key] ) != $args['user_id'] ) { $ultimatemember->form->add_error($key, __('This email is already linked to an existing account','ultimatemember') ); } else if ( !is_email( $args[$key] ) ) { $ultimatemember->form->add_error($key, __('This is not a valid email','ultimatemember') ); @@ -364,6 +374,17 @@ $ultimatemember->form->add_error($key, __('This is not a valid email','ultimatemember') ); } else if ( $args[$key] != '' && email_exists( $args[$key] ) ) { $ultimatemember->form->add_error($key, __('This email is already linked to an existing account','ultimatemember') ); + } else if ( $args[$key] != '' ) { + + $users = get_users('meta_value='.$args[ $key ]); + + foreach ( $users as $user ) { + if( $user->ID != $args['user_id'] ){ + $ultimatemember->form->add_error($key, __('This email is already linked to an existing account','ultimatemember') ); + } + } + + } } diff --git a/core/um-actions-profile.php b/core/um-actions-profile.php index 2bd72d21..1366d4af 100644 --- a/core/um-actions-profile.php +++ b/core/um-actions-profile.php @@ -406,6 +406,12 @@ + + fields->is_error( 'profile_photo' ) ) { + echo $ultimatemember->fields->field_error( $ultimatemember->fields->show_error('profile_photo'), 'force_show' ); + } + ?> diff --git a/core/um-builtin.php b/core/um-builtin.php index e4a46ab7..acf1d143 100644 --- a/core/um-builtin.php +++ b/core/um-builtin.php @@ -649,6 +649,16 @@ class UM_Builtin { 'label' => __('E-mail Address','ultimatemember'), 'required' => 0, 'public' => 1, + 'validate' => 'unique_email', + ), + + 'secondary_user_email' => array( + 'title' => __('Secondary E-mail Address','ultimatemember'), + 'metakey' => 'secondary_user_email', + 'type' => 'text', + 'label' => __('Secondary E-mail Address','ultimatemember'), + 'required' => 0, + 'public' => 1, 'editable' => 1, 'validate' => 'unique_email', ), diff --git a/core/um-fields.php b/core/um-fields.php index e1bca1af..e3e9663a 100644 --- a/core/um-fields.php +++ b/core/um-fields.php @@ -909,7 +909,13 @@ class UM_Fields { if ( !um_can_edit_field( $data ) ) return; // fields that need to be disabled in edit mode (profile) - if ( in_array( $key, array('user_email','username','user_login','user_password') ) && $this->editing == true && $this->set_mode == 'profile' ) { + $arr_restricted_fields = array('user_email','username','user_login','user_password'); + + if( um_get_option('editable_primary_email_in_profile') == 1 ){ + unset( $arr_restricted_fields[0] ); // remove user_email + } + + if ( in_array( $key, $arr_restricted_fields ) && $this->editing == true && $this->set_mode == 'profile' ) { return; } diff --git a/core/um-files.php b/core/um-files.php index 99f82616..92e5320e 100644 --- a/core/um-files.php +++ b/core/um-files.php @@ -211,16 +211,28 @@ class UM_Files { $new_w = um_get_option('image_max_width'); $new_h = round( $new_w / $ratio, 2 ); - $image_p = imagecreatetruecolor( $new_w, $new_h ); - imagecopyresampled( $image_p, $image, 0, 0, 0, 0, $new_w, $new_h, $w, $h ); - $image_p = $this->fix_image_orientation( $image_p, $source ); + if ( $info['mime'] == 'image/jpeg' || $info['mime'] == 'image/gif' ){ + + $image_p = imagecreatetruecolor( $new_w, $new_h ); + imagecopyresampled( $image_p, $image, 0, 0, 0, 0, $new_w, $new_h, $w, $h ); + $image_p = $this->fix_image_orientation( $image_p, $source ); + }else if( $info['mime'] == 'image/png' ){ + + $srcImage = $image; + $targetImage = imagecreatetruecolor( $new_w, $new_h ); + imagealphablending( $targetImage, false ); + imagesavealpha( $targetImage, true ); + imagecopyresampled( $targetImage, $srcImage, 0, 0, 0, 0, $new_w, $new_h, $w, $h ); + + } + if ( $info['mime'] == 'image/jpeg' ){ $has_copied = imagejpeg( $image_p, $destination, $quality ); }else if ( $info['mime'] == 'image/gif' ){ $has_copied = imagegif( $image_p, $destination ); }else if ( $info['mime'] == 'image/png' ){ - $has_copied = imagepng( $image_p, $destination, $quality ); + $has_copied = imagepng( $targetImage, $destination, 0 ,PNG_ALL_FILTERS); } $info['um_has_max_width'] = 'custom'; @@ -230,18 +242,20 @@ class UM_Files { $image = $this->fix_image_orientation( $image, $source ); - if ( $info['mime'] == 'image/jpeg' ){ $has_copied = imagejpeg( $image, $destination, $quality ); }else if ( $info['mime'] == 'image/gif' ){ $has_copied = imagegif( $image, $destination ); }else if ( $info['mime'] == 'image/png' ){ - $has_copied = imagepng( $image, $destination ); + $has_copied = imagepng( $image , $destination , 0 ,PNG_ALL_FILTERS); } + $info['um_has_max_width'] = 'default'; $info['um_has_copied'] = $has_copied ? 'yes':'no'; } + + return $info; } @@ -265,7 +279,7 @@ class UM_Files { $info = $this->create_and_copy_image( $source, $unique_dir['dir'] . $destination, $quality ); - $url = $unique_dir['url'] . $destination; + $url = $unique_dir['url'] . $destination ; return $url; @@ -469,27 +483,28 @@ class UM_Files { $info = @getimagesize( $file ); if ( $info['mime'] == 'image/gif' ){ - + $img_r = imagecreatefromgif( $file ); - - } else if ( $info['mime'] == 'image/png' ){ - - $img_r = imagecreatefrompng( $file ); - - }else{ - $img_r = imagecreatefromjpeg( $file ); - } - - $dst_r = imagecreatetruecolor( $targ_x2, $targ_y2 ); - - imagecopy( $dst_r, $img_r, 0, 0, $targ_x1, $targ_y1, $targ_x2, $targ_y2 ); - - if ( $info['mime'] == 'image/gif' ){ + $dst_r = imagecreatetruecolor( $targ_x2, $targ_y2 ); + imagecopy( $dst_r, $img_r, 0, 0, $targ_x1, $targ_y1, $targ_x2, $targ_y2 ); imagegif( $dst_r, $this->path_only( $file ) . basename( $file ) ); + } else if ( $info['mime'] == 'image/png' ){ - imagepng( $dst_r, $this->path_only( $file ) . basename( $file ), 9, PNG_NO_FILTER ); + + $srcImage = imagecreatefrompng( $file ); + $targetImage = imagecreatetruecolor( $targ_x2, $targ_y2 ); + imagealphablending( $targetImage, false ); + imagesavealpha( $targetImage, true ); + imagecopyresampled( $targetImage, $srcImage, 0, 0, 0, 0, $targ_x1, $targ_y1, $targ_x2, $targ_y2 ); + imagepng( $srcImage, $this->path_only( $file ) . basename( $file ) ); + }else{ + + $img_r = imagecreatefromjpeg( $file ); + $dst_r = imagecreatetruecolor( $targ_x2, $targ_y2 ); + imagecopy( $dst_r, $img_r, 0, 0, $targ_x1, $targ_y1, $targ_x2, $targ_y2 ); imagejpeg( $dst_r, $this->path_only( $file ) . basename( $file ), 100 ); + } $split = explode('/ultimatemember/temp/', $file ); @@ -564,21 +579,32 @@ class UM_Files { if ( $info['mime'] == 'image/jpeg' ){ $thumb_s = imagecreatefromjpeg( $source ); + $thumb = imagecreatetruecolor( $size, $size ); + imagecopyresampled( $thumb, $thumb_s, 0, 0, 0, 0, $size, $size, $w, $h ); + }else if ( $info['mime'] == 'image/gif' ){ $thumb_s = imagecreatefromgif( $source ); - }else if ( $info['mime'] == 'image/png' ){ - $thumb_s = imagecreatefrompng( $source ); + $thumb = imagecreatetruecolor( $size, $size ); + imagecopyresampled( $thumb, $thumb_s, 0, 0, 0, 0, $size, $size, $w, $h ); + } - $thumb = imagecreatetruecolor( $size, $size ); - imagecopyresampled( $thumb, $thumb_s, 0, 0, 0, 0, $size, $size, $w, $h ); - + if ( $info['mime'] == 'image/jpeg' ){ imagejpeg( $thumb, $this->upload_basedir . $user_id . '/' . $name . '-' . $size . $ext, 100); }else if ( $info['mime'] == 'image/png' ){ - imagepng( $thumb, $this->upload_basedir . $user_id . '/' . $name . '-' . $size . $ext, 9,PNG_NO_FILTER); + + $srcImage = imagecreatefrompng( $source ); + $targetImage = imagecreatetruecolor( $size, $size ); + imagealphablending( $targetImage, false ); + imagesavealpha( $targetImage, true ); + imagecopyresampled( $targetImage, $srcImage, 0, 0, 0, 0, $size, $size, $w, $h ); + imagepng( $srcImage, $this->upload_basedir . $user_id . '/' . $name . '-' . $size . $ext, 0 ,PNG_ALL_FILTERS); + }else if ( $info['mime'] == 'image/gif' ){ + imagegif( $thumb, $this->upload_basedir . $user_id . '/' . $name . '-' . $size . $ext); + } } @@ -606,20 +632,27 @@ class UM_Files { if ( $size < $w ) { if ( $info['mime'] == 'image/jpeg' ){ + $thumb = imagecreatetruecolor( $size, $height ); + imagecopyresampled( $thumb, $thumb_s, 0, 0, 0, 0, $size, $height, $w, $h ); $thumb_s = imagecreatefromjpeg( $source ); }else if ( $info['mime'] == 'image/gif' ){ + $thumb = imagecreatetruecolor( $size, $height ); + imagecopyresampled( $thumb, $thumb_s, 0, 0, 0, 0, $size, $height, $w, $h ); $thumb_s = imagecreatefromgif( $source ); - }else if ( $info['mime'] == 'image/png' ){ - $thumb_s = imagecreatefrompng( $source ); } - $thumb = imagecreatetruecolor( $size, $height ); - imagecopyresampled( $thumb, $thumb_s, 0, 0, 0, 0, $size, $height, $w, $h ); if ( $info['mime'] == 'image/jpeg' ){ imagejpeg( $thumb, $this->upload_basedir . $user_id . '/' . $name . '-' . $size . $ext, 100); }else if ( $info['mime'] == 'image/png' ){ - imagepng( $thumb, $this->upload_basedir . $user_id . '/' . $name . '-' . $size . $ext, 9,PNG_NO_FILTER); + + $srcImage = imagecreatefrompng( $source ); + $targetImage = imagecreatetruecolor( $size, $height ); + imagealphablending( $targetImage, false ); + imagesavealpha( $targetImage, true ); + imagecopyresampled( $targetImage, $srcImage, 0, 0, 0, 0, $size, $height, $w, $h ); + + imagepng($srcImage, $this->upload_basedir . $user_id . '/' . $name . '-' . $size . $ext, 0 ,PNG_ALL_FILTERS); }else if ( $info['mime'] == 'image/gif' ){ imagegif( $thumb, $this->upload_basedir . $user_id . '/' . $name . '-' . $size . $ext); } diff --git a/core/um-short-functions.php b/core/um-short-functions.php index cf4848c3..a402fbd0 100644 --- a/core/um-short-functions.php +++ b/core/um-short-functions.php @@ -1481,16 +1481,27 @@ function um_fetch_user( $user_id ) { * @param mixed $value * @return integer */ - function um_is_meta_value_exists( $key, $value ){ + function um_is_meta_value_exists( $key, $value, $return_user_id = false ){ global $wpdb; - $count = $wpdb->get_var( $wpdb->prepare( - "SELECT COUNT(*) as count FROM {$wpdb->usermeta} WHERE meta_key = %s AND meta_value = %s ", - $key, - $value - ) ); + if( ! $return_user_id ){ + $count = $wpdb->get_var( $wpdb->prepare( + "SELECT COUNT(*) as count FROM {$wpdb->usermeta} WHERE meta_key = %s AND meta_value = %s ", + $key, + $value + ) ); + + return $count; + } + + $user_id = $wpdb->get_var( $wpdb->prepare( + "SELECT user_id FROM {$wpdb->usermeta} WHERE meta_key = %s AND meta_value = %s ", + $key, + $value + ) ); + + return $user_id; - return $count; } /** diff --git a/core/um-shortcodes.php b/core/um-shortcodes.php index 2d16b30c..d5735e82 100644 --- a/core/um-shortcodes.php +++ b/core/um-shortcodes.php @@ -416,33 +416,37 @@ class UM_Shortcodes { $paths[] = glob(get_stylesheet_directory() . '/ultimate-member/templates/' . '*.php'); } - foreach ($paths as $k => $files) { + if( isset( $paths ) && ! empty( $paths ) ){ + + foreach ($paths as $k => $files) { - foreach ($files as $file) { + foreach ($files as $file) { - $clean_filename = $this->get_template_name($file); + $clean_filename = $this->get_template_name($file); - if (0 === strpos($clean_filename, $excluded)) { + if (0 === strpos($clean_filename, $excluded)) { - $source = file_get_contents($file); - $tokens = token_get_all($source); - $comment = array( - T_COMMENT, // All comments since PHP5 - T_DOC_COMMENT, // PHPDoc comments - ); - foreach ($tokens as $token) { - if (in_array($token[0], $comment) && strstr($token[1], '/* Template:') && $clean_filename != $excluded) { - $txt = $token[1]; - $txt = str_replace('/* Template: ', '', $txt); - $txt = str_replace(' */', '', $txt); - $array[$clean_filename] = $txt; + $source = file_get_contents($file); + $tokens = token_get_all($source); + $comment = array( + T_COMMENT, // All comments since PHP5 + T_DOC_COMMENT, // PHPDoc comments + ); + foreach ($tokens as $token) { + if (in_array($token[0], $comment) && strstr($token[1], '/* Template:') && $clean_filename != $excluded) { + $txt = $token[1]; + $txt = str_replace('/* Template: ', '', $txt); + $txt = str_replace(' */', '', $txt); + $array[$clean_filename] = $txt; + } } + } } } - + } return $array; diff --git a/um-config.php b/um-config.php index 8e7169be..5e09c729 100644 --- a/um-config.php +++ b/um-config.php @@ -202,6 +202,16 @@ $this->sections[] = array( 'off' => __('Off','ultimatemember'), ), + array( + 'id' => 'editable_primary_email_in_profile', + 'type' => 'switch', + 'title' => __( 'Editable primary email field in profile view','ultimatemember' ), + 'default' => 0, + 'desc' => __('Allow users to edit their primary emails in profile view ( when email address field is added only )','ultimatemember'), + 'on' => __('On','ultimatemember'), + 'off' => __('Off','ultimatemember'), + ), + ) );