Fix cover image size handling and add fallback for invalid sizes

Improved logic to handle cases where the cover image size array is invalid or empty by adding a fallback default size. For mobile devices, the second size is used if available, or the first size is used as a fallback. This ensures proper cover size selection and prevents potential errors.
This commit is contained in:
Mykyta Synelnikov
2025-09-06 14:42:15 +03:00
parent 4cfda2922b
commit 5c67164cc2
2 changed files with 14 additions and 2 deletions
@@ -1104,8 +1104,14 @@ if ( ! class_exists( 'um\core\Member_Directory_Meta' ) ) {
$pagination_data = $this->calculate_pagination( $directory_data, $total_users );
$sizes = UM()->options()->get( 'cover_thumb_sizes' );
// Ensure we have valid sizes array and handle case when only one size is defined
if ( ! is_array( $sizes ) || empty( $sizes ) ) {
$sizes = array( 300 ); // fallback to default
}
$this->cover_size = wp_is_mobile() ? $sizes[1] : end( $sizes );
// For mobile, use second size if available, otherwise use first size
$available_mobile = isset( $sizes[1] ) ? $sizes[1] : $sizes[0];
$this->cover_size = wp_is_mobile() ? $available_mobile : end( $sizes );
$avatar_size = UM()->options()->get( 'profile_photosize' );
$this->avatar_size = str_replace( 'px', '', $avatar_size );
+7 -1
View File
@@ -2951,8 +2951,14 @@ if ( ! class_exists( 'um\core\Member_Directory' ) ) {
$user_ids = apply_filters( 'um_prepare_user_results_array', $user_ids, $this->query_args );
$sizes = UM()->options()->get( 'cover_thumb_sizes' );
// Ensure we have valid sizes array and handle case when only one size is defined
if ( ! is_array( $sizes ) || empty( $sizes ) ) {
$sizes = array( 300 ); // fallback to default
}
$this->cover_size = wp_is_mobile() ? $sizes[1] : end( $sizes );
// For mobile, use second size if available, otherwise use first size
$available_mobile = isset( $sizes[1] ) ? $sizes[1] : $sizes[0];
$this->cover_size = wp_is_mobile() ? $available_mobile : end( $sizes );
$this->cover_size = apply_filters( 'um_member_directory_cover_image_size', $this->cover_size, $directory_data );