diff --git a/assets/js/um-scripts.js b/assets/js/um-scripts.js
index 665643c0..91913505 100644
--- a/assets/js/um-scripts.js
+++ b/assets/js/um-scripts.js
@@ -1,3 +1,7 @@
+/*jQuery('body').on('error', '.um-avatar', function() {
+ if( jQuery(this).data('load-error') != undefined ) return;
+ jQuery(this).data('load-error', '1').attr('src', jQuery(this).data('default'));
+});*/
jQuery(document).ready(function() {
jQuery(document).on('click', '.um-dropdown a', function(e){
diff --git a/includes/core/class-permalinks.php b/includes/core/class-permalinks.php
index c852c3ee..56e27224 100644
--- a/includes/core/class-permalinks.php
+++ b/includes/core/class-permalinks.php
@@ -136,22 +136,15 @@ if ( ! class_exists( 'um\core\Permalinks' ) ) {
$um_port_forwarding_url = UM()->options()->get( 'um_port_forwarding_url' );
$um_port_forwarding_url = ! empty( $um_port_forwarding_url ) ? $um_port_forwarding_url : '';
+ $page_url = '';
if ( is_multisite() ) {
-
- $page_url = '';
$blog_id = get_current_blog_id();
$siteurl = get_site_url( $blog_id );
$network_permalink_structure = UM()->options()->get( 'network_permalink_structure' );
if( $network_permalink_structure == "sub-directory" ){
- if ( is_ssl() ) {
- $page_url = 'https';
- } else {
- $page_url = 'http';
- }
- $page_url .= "://";
-
+ $page_url .= "//";
$page_url .= $_SERVER[ $server_name_method ];
}else{
$page_url .= $siteurl;
@@ -159,7 +152,6 @@ if ( ! class_exists( 'um\core\Permalinks' ) ) {
if ( $um_port_forwarding_url == 1 && isset( $_SERVER["SERVER_PORT"] ) ) {
$page_url .= ":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
-
} else {
$page_url .= $_SERVER["REQUEST_URI"];
}
@@ -168,13 +160,7 @@ if ( ! class_exists( 'um\core\Permalinks' ) ) {
if ( !isset( $_SERVER['SERVER_NAME'] ) )
return '';
-
- if ( is_ssl() ) {
- $page_url = 'https';
- } else {
- $page_url = 'http';
- }
- $page_url .= "://";
+ $page_url .= "//";
if ( $um_port_forwarding_url == 1 && isset( $_SERVER["SERVER_PORT"] ) ) {
$page_url .= $_SERVER[ $server_name_method ].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
@@ -210,7 +196,7 @@ if ( ! class_exists( 'um\core\Permalinks' ) ) {
* }
* ?>
*/
- return apply_filters( 'um_get_current_page_url', $page_url );
+ return apply_filters( 'um_get_current_page_url', set_url_scheme( $page_url ) );
}
diff --git a/includes/core/class-rest-api.php b/includes/core/class-rest-api.php
index bd42c056..8a75f37e 100644
--- a/includes/core/class-rest-api.php
+++ b/includes/core/class-rest-api.php
@@ -524,9 +524,9 @@ if ( ! class_exists( 'um\core\REST_API' ) ) {
$val->first_name = um_user('first_name');
$val->last_name = um_user('last_name');
$val->account_status = um_user('account_status');
- $val->profile_pic_original = $this->getsrc( um_user('profile_photo', 'original') );
- $val->profile_pic_normal = $this->getsrc( um_user('profile_photo', 200) );
- $val->profile_pic_small = $this->getsrc( um_user('profile_photo', 40) );
+ $val->profile_pic_original = um_get_user_avatar_url('', 'original');
+ $val->profile_pic_normal = um_get_user_avatar_url('', 200);
+ $val->profile_pic_small = um_get_user_avatar_url('', 40);
$val->cover_photo = $this->getsrc( um_user('cover_photo', 1000) );
/**
@@ -667,9 +667,9 @@ if ( ! class_exists( 'um\core\REST_API' ) ) {
break;
case 'profile_pic':
- $response['profile_pic_original'] = $this->getsrc( um_user('profile_photo', 'original') );
- $response['profile_pic_normal'] = $this->getsrc( um_user('profile_photo', 200) );
- $response['profile_pic_small'] = $this->getsrc( um_user('profile_photo', 40) );
+ $response['profile_pic_original'] = um_get_user_avatar_url('', 'original');
+ $response['profile_pic_normal'] = um_get_user_avatar_url('', 200);
+ $response['profile_pic_small'] = um_get_user_avatar_url('', 40);
break;
case 'status':
@@ -699,9 +699,9 @@ if ( ! class_exists( 'um\core\REST_API' ) ) {
$val->first_name = um_user('first_name');
$val->last_name = um_user('last_name');
$val->account_status = um_user('account_status');
- $val->profile_pic_original = $this->getsrc( um_user('profile_photo', 'original') );
- $val->profile_pic_normal = $this->getsrc( um_user('profile_photo', 200) );
- $val->profile_pic_small = $this->getsrc( um_user('profile_photo', 40) );
+ $val->profile_pic_original = um_get_user_avatar_url('', 'original');
+ $val->profile_pic_normal = um_get_user_avatar_url('', 200);
+ $val->profile_pic_small = um_get_user_avatar_url('', 40);
$val->cover_photo = $this->getsrc( um_user('cover_photo', 1000) );
/**
diff --git a/includes/core/um-actions-profile.php b/includes/core/um-actions-profile.php
index 072e8901..803a3e88 100644
--- a/includes/core/um-actions-profile.php
+++ b/includes/core/um-actions-profile.php
@@ -518,11 +518,7 @@ function um_profile_dynamic_meta_desc() {
$user_id = um_user( 'ID' );
$url = um_user_profile_url();
- if (um_profile( 'profile_photo' )) {
- $avatar = um_user_uploads_uri() . um_profile( 'profile_photo' );
- } else {
- $avatar = um_get_default_avatar_uri();
- }
+ $avatar = um_get_user_avatar_url( $user_id, 'original' );
um_reset_user(); ?>
diff --git a/includes/core/um-filters-avatars.php b/includes/core/um-filters-avatars.php
index 715e8aec..12aec65c 100644
--- a/includes/core/um-filters-avatars.php
+++ b/includes/core/um-filters-avatars.php
@@ -27,7 +27,6 @@ add_filter( 'avatar_defaults', 'um_avatar_defaults', 99999 );
* @return string returns avatar in image html elements
*/
function um_get_avatar( $avatar = '', $id_or_email='', $size = '96', $avatar_class = '', $default = '', $alt = '' ) {
-
if ( is_numeric($id_or_email) )
$user_id = (int) $id_or_email;
elseif ( is_string( $id_or_email ) && ( $user = get_user_by( 'email', $id_or_email ) ) )
@@ -41,64 +40,6 @@ function um_get_avatar( $avatar = '', $id_or_email='', $size = '96', $avatar_cla
$avatar = um_user('profile_photo', $size);
- /**
- * UM hook
- *
- * @type filter
- * @title um_avatar_image_alternate_text
- * @description Change avatar image alt
- * @input_vars
- * [{"var":"$avatar_alt","type":"string","desc":"Image alternate text. Display name by default"}]
- * @change_log
- * ["Since: 2.0"]
- * @usage
- *
- * @example
- *
- */
- $image_alt = apply_filters( "um_avatar_image_alternate_text", um_user("display_name") );
-
- if ( ! $avatar && UM()->options()->get( 'use_gravatars' ) ) {
-
- $default = get_option( 'avatar_default', 'mystery' );
- if ( $default == 'gravatar_default' ) {
- $default = '';
- }
-
- $rating = get_option('avatar_rating');
- if ( !empty( $rating ) ) {
- $rating = "&r={$rating}";
- }
-
- if ( UM()->options()->get('use_gravatars') && ! um_user('synced_profile_photo') && ! $has_profile_photo ){
- $avatar_url = um_get_domain_protocol().'gravatar.com/avatar/'.um_user('synced_gravatar_hashed_id');
- $avatar_url = add_query_arg('s',400, $avatar_url);
- $gravatar_type = UM()->options()->get( 'use_um_gravatar_default_builtin_image' );
-
- if ( $gravatar_type == 'default' ) {
- if ( UM()->options()->get( 'use_um_gravatar_default_image' ) ) {
- $avatar_url = add_query_arg('d', um_get_default_avatar_uri(), $avatar_url );
- }
- } else {
- $avatar_url = add_query_arg('d', $gravatar_type, $avatar_url );
- }
-
- }
-
- $avatar = '
';
-
- }else if( empty( $avatar ) ){
- $default_avatar_uri = um_get_default_avatar_uri();
-
- $avatar = '
';
- }
-
return $avatar;
}
add_filter( 'get_avatar', 'um_get_avatar', 99999, 5 );
\ No newline at end of file
diff --git a/includes/um-short-functions.php b/includes/um-short-functions.php
index 12011f7b..d15afc67 100644
--- a/includes/um-short-functions.php
+++ b/includes/um-short-functions.php
@@ -442,7 +442,7 @@ function um_js_redirect( $url ) {
if (headers_sent() || empty( $url )) {
//for blank redirects
if ('' == $url) {
- $url = ( is_ssl() ? 'https://' : 'http://' ) . $_SERVER["HTTP_HOST"] . $_SERVER["REQUEST_URI"];
+ $url = set_url_scheme( '//' . $_SERVER["HTTP_HOST"] . $_SERVER["REQUEST_URI"] );
}
$funtext = "echo \"\";";
@@ -1594,9 +1594,7 @@ function um_youtube_id_from_url( $url ) {
* @return string
*/
function um_user_uploads_uri() {
- if (is_ssl()) {
- UM()->files()->upload_baseurl = str_replace( "http://", "https://", UM()->files()->upload_baseurl );
- }
+ UM()->files()->upload_baseurl = set_url_scheme( UM()->files()->upload_baseurl );
$uri = UM()->files()->upload_baseurl . um_user( 'ID' ) . '/';
@@ -1706,33 +1704,23 @@ function um_get_avatar_uri( $image, $attrs ) {
*/
$cache_time = apply_filters( 'um_filter_avatar_cache_time', current_time( 'timestamp' ), um_user( 'ID' ) );
- if (!empty( $cache_time )) {
- $cache_time = "?{$cache_time}";
- }
-
- if (file_exists( UM()->files()->upload_basedir . um_user( 'ID' ) . "/profile_photo-{$attrs}{$ext}" )) {
-
- $uri = um_user_uploads_uri() . "profile_photo-{$attrs}{$ext}{$cache_time}";
-
+ if( $attrs == 'original' && file_exists( um_user_uploads_dir() . "profile_photo{$ext}" ) ) {
+ $uri = um_user_uploads_uri() . "profile_photo{$ext}";
+ } else if (file_exists( um_user_uploads_dir() . "profile_photo-{$attrs}{$ext}" )) {
+ $uri = um_user_uploads_uri() . "profile_photo-{$attrs}{$ext}";
} else {
-
$sizes = UM()->options()->get( 'photo_thumb_sizes' );
if (is_array( $sizes )) $find = um_closest_num( $sizes, $attrs );
- if (file_exists( UM()->files()->upload_basedir . um_user( 'ID' ) . "/profile_photo-{$find}{$ext}" )) {
-
- $uri = um_user_uploads_uri() . "profile_photo-{$find}{$ext}{$cache_time}";
-
- } else if (file_exists( UM()->files()->upload_basedir . um_user( 'ID' ) . "/profile_photo{$ext}" )) {
-
- $uri = um_user_uploads_uri() . "profile_photo{$ext}{$cache_time}";
-
- }
-
- if ($attrs == 'original') {
- $uri = um_user_uploads_uri() . "profile_photo{$ext}{$cache_time}";
+ if (file_exists( um_user_uploads_dir() . "profile_photo-{$find}{$ext}" )) {
+ $uri = um_user_uploads_uri() . "profile_photo-{$find}{$ext}";
+ } else if (file_exists( um_user_uploads_dir() . "profile_photo{$ext}" )) {
+ $uri = um_user_uploads_uri() . "profile_photo{$ext}";
}
+ }
+ if ( !empty( $cache_time ) ) {
+ $uri .= "?{$cache_time}";
}
return $uri;
@@ -1749,35 +1737,128 @@ function um_get_default_avatar_uri() {
$uri = !empty( $uri['url'] ) ? $uri['url'] : '';
if ( ! $uri ) {
$uri = um_url . 'assets/img/default_avatar.jpg';
- } else {
-
- //http <-> https compatibility default avatar option of SSL was changed
- $url_array = parse_url( $uri );
-
- if (is_ssl() && $url_array['scheme'] == 'http') {
- $uri = str_replace( 'http://', 'https://', $uri );
- } else if (!is_ssl() && $url_array['scheme'] == 'https') {
- $uri = str_replace( 'https://', 'http://', $uri );
- }
}
- return $uri;
+ return set_url_scheme( $uri );
}
/**
* get user avatar url
*
+ * @param $user_id
+ * @param $size
+ *
* @return bool|string
*/
-function um_get_user_avatar_url() {
- if (um_profile( 'profile_photo' )) {
- $avatar_uri = um_get_avatar_uri( um_profile( 'profile_photo' ), 32 );
- } else {
- $avatar_uri = um_get_default_avatar_uri();
- }
+function um_get_user_avatar_data( $user_id = '', $size = '96' ) {
+ if( empty( $user_id ) ) {
+ $user_id = um_user( 'ID' );
+ } else {
+ um_fetch_user( $user_id );
+ }
- return $avatar_uri;
+ $data = array(
+ 'user_id' => $user_id,
+ 'default' => um_get_default_avatar_uri(),
+ 'class' => 'gravatar avatar avatar-' . $size . ' um-avatar',
+ 'size' => $size
+ );
+
+ if ( $profile_photo = um_profile( 'profile_photo' ) ) {
+ $data['url'] = um_get_avatar_uri( $profile_photo, $size );
+ $data['type'] = 'upload';
+ $data['class'] .= ' um-avatar-uploaded';
+ } else if( $synced_profile_photo = um_user( 'synced_profile_photo' ) ) {
+ $data['url'] = $synced_profile_photo;
+ $data['type'] = 'sync';
+ $data['class'] .= ' um-avatar-default';
+ } else if( UM()->options()->get( 'use_gravatars' ) ) {
+ $avatar_hash_id = get_user_meta( $user_id, 'synced_gravatar_hashed_id', true );
+ $data['url'] = set_url_scheme( '//gravatar.com/avatar/' . $avatar_hash_id );
+ $data['url'] = add_query_arg( 's', 400, $data['url'] );
+ $rating = get_option('avatar_rating');
+ if ( !empty( $rating ) ) {
+ $data['url'] = add_query_arg( 'r', $rating, $data['url'] );
+ }
+ $gravatar_type = UM()->options()->get( 'use_um_gravatar_default_builtin_image' );
+ if ( $gravatar_type == 'default' ) {
+ if ( UM()->options()->get( 'use_um_gravatar_default_image' ) ) {
+ $data['url'] = add_query_arg( 'd', $data['default'], $data['url'] );
+ }
+ } else {
+ $default = get_option( 'avatar_default', 'mystery' );
+ if ( $default == 'gravatar_default' ) {
+ $default = '';
+ }
+ $data['url'] = add_query_arg( 'd', $default, $data['url'] );
+ }
+ $data['type'] = 'gravatar';
+ $data['class'] .= ' um-avatar-gravatar';
+ } else {
+ $data['url'] = $data['default'];
+ $data['type'] = 'default';
+ $data['class'] .= ' um-avatar-default';
+ }
+
+ /**
+ * UM hook
+ *
+ * @type filter
+ * @title um_user_avatar_url_filter
+ * @description Change user avatar URL
+ * @input_vars
+ * [{"var":"$avatar_uri","type":"string","desc":"Avatar URL"},
+ * {"var":"$user_id","type":"int","desc":"User ID"}]
+ * @change_log
+ * ["Since: 2.0"]
+ * @usage add_filter( 'um_user_avatar_url_filter', 'function_name', 10, 2 );
+ * @example
+ *
+ */
+ $data['url'] = apply_filters( 'um_user_avatar_url_filter', $data['url'], $user_id, $data );
+ /**
+ * UM hook
+ *
+ * @type filter
+ * @title um_avatar_image_alternate_text
+ * @description Change user display name on um_user function profile photo
+ * @input_vars
+ * [{"var":"$display_name","type":"string","desc":"User Display Name"}]
+ * @change_log
+ * ["Since: 2.0"]
+ * @usage add_filter( 'um_avatar_image_alternate_text', 'function_name', 10, 1 );
+ * @example
+ *
+ */
+ $data['alt'] = apply_filters( "um_avatar_image_alternate_text", um_user( "display_name" ), $data );
+
+ return $data;
+}
+
+/**
+ * get user avatar url
+ *
+ * @param $user_id
+ * @param $size
+ *
+ * @return bool|string
+ */
+function um_get_user_avatar_url( $user_id = '', $size = '96' ) {
+ $data = um_get_user_avatar_data( $user_id, $size );
+ return $data['url'];
}
@@ -2066,88 +2147,15 @@ function um_user( $data, $attrs = null ) {
break;
case 'profile_photo':
+ $data = um_get_user_avatar_data( um_user( 'ID' ), $attrs );
- $has_profile_photo = false;
- $photo_type = 'um-avatar-default';
-
- /**
- * UM hook
- *
- * @type filter
- * @title um_avatar_image_alternate_text
- * @description Change user display name on um_user function profile photo
- * @input_vars
- * [{"var":"$display_name","type":"string","desc":"User Display Name"}]
- * @change_log
- * ["Since: 2.0"]
- * @usage add_filter( 'um_avatar_image_alternate_text', 'function_name', 10, 1 );
- * @example
- *
- */
- $image_alt = apply_filters( "um_avatar_image_alternate_text", um_user( "display_name" ) );
-
- if (um_profile( 'profile_photo' )) {
- $avatar_uri = um_get_avatar_uri( um_profile( 'profile_photo' ), $attrs );
- $has_profile_photo = true;
- $photo_type = 'um-avatar-uploaded';
- } else if (um_user( 'synced_profile_photo' )) {
- $avatar_uri = um_user( 'synced_profile_photo' );
- } else {
- $avatar_uri = um_get_default_avatar_uri();
- }
-
- /**
- * UM hook
- *
- * @type filter
- * @title um_user_avatar_url_filter
- * @description Change user avatar URL
- * @input_vars
- * [{"var":"$avatar_uri","type":"string","desc":"Avatar URL"},
- * {"var":"$user_id","type":"int","desc":"User ID"}]
- * @change_log
- * ["Since: 2.0"]
- * @usage add_filter( 'um_user_avatar_url_filter', 'function_name', 10, 2 );
- * @example
- *
- */
- $avatar_uri = apply_filters( 'um_user_avatar_url_filter', $avatar_uri, um_user( 'ID' ) );
-
-
- if (!$avatar_uri)
- return '';
-
- if ( UM()->options()->get( 'use_gravatars' ) && !um_user( 'synced_profile_photo' ) && !$has_profile_photo) {
- $avatar_hash_id = get_user_meta( um_user( 'ID' ), 'synced_gravatar_hashed_id', true );
- $avatar_uri = um_get_domain_protocol() . 'gravatar.com/avatar/' . $avatar_hash_id;
- $avatar_uri = add_query_arg( 's', 400, $avatar_uri );
- $gravatar_type = UM()->options()->get( 'use_um_gravatar_default_builtin_image' );
- $photo_type = 'um-avatar-gravatar';
- if ( $gravatar_type == 'default' ) {
- if ( UM()->options()->get( 'use_um_gravatar_default_image' ) ) {
- $avatar_uri = add_query_arg( 'd', um_get_default_avatar_uri(), $avatar_uri );
- }
- } else {
- $avatar_uri = add_query_arg( 'd', $gravatar_type, $avatar_uri );
- }
-
- }
-
- $default_avatar = um_get_default_avatar_uri();
-
- return '
';
+ return '
'; //don't move attribute before src
break;