Skip to content

Commit 1735b49

Browse files
author
Md. Alimuzzaman Alim
committed
Update buddypress.php
Fix for broken banner image. #417
1 parent ea07fd2 commit 1735b49

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

lib/classes/compatibility/buddypress.php

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,10 @@ public function avatar_uploaded($item_id, $type, $r){
6969
public function bp_core_fetch_avatar($image_html){
7070
try {
7171
preg_match("/src=(?:'|\")(.*)(?:'|\")/", $image_html, $image_url);
72-
$gs_image_url = $this->bp_core_fetch_avatar_url($image_url[1]);
73-
$image_html = str_replace($image_url[1], $gs_image_url, $image_html);
72+
if(!empty($image_url[1])){
73+
$gs_image_url = $this->bp_core_fetch_avatar_url($image_url[1]);
74+
$image_html = str_replace($image_url[1], $gs_image_url, $image_html);
75+
}
7476
} catch (\Throwable $th) {
7577
//throw $th;
7678
}
@@ -91,7 +93,7 @@ public function bp_core_fetch_avatar_url($url){
9193
$root_dir = ud_get_stateless_media()->get( 'sm.root_dir' );
9294
$root_dir = trim( $root_dir, '/ ' ); // Remove any forward slash and empty space.
9395
// Making sure that we only modify url for uploads dir.
94-
if(strpos($name, "$root_dir/http") !== 0){
96+
if(strpos($name, "$root_dir/http") !== 0 && $root_dir !== $name){
9597
$full_avatar_path = $wp_uploads_dir['basedir'] . '/' . $name;
9698
do_action( 'sm:sync::syncFile', $full_avatar, $full_avatar_path, true, array('stateless' => false));
9799
$url = ud_get_stateless_media()->get_gs_host() . '/' . $name;
@@ -154,11 +156,16 @@ public function bp_attachments_pre_get_attachment($return, $r){
154156

155157
$url = bp_attachments_get_attachment('url', $r);
156158
$name = apply_filters( 'wp_stateless_file_name', $url);
159+
160+
$root_dir = ud_get_stateless_media()->get( 'sm.root_dir' );
161+
$root_dir = trim( $root_dir, '/ ' ); // Remove any forward slash and empty space.
157162

158-
$full_path = bp_attachments_get_attachment(false, $r);
159-
do_action( 'sm:sync::syncFile', $name, $full_path, true, array('stateless' => false));
163+
if($root_dir . "/" != $name){
164+
$full_path = bp_attachments_get_attachment(false, $r);
165+
do_action( 'sm:sync::syncFile', $name, $full_path, true, array('stateless' => false));
166+
$return = ud_get_stateless_media()->get_gs_host() . '/' . $name;
167+
}
160168

161-
$return = ud_get_stateless_media()->get_gs_host() . '/' . $name;
162169
}
163170
} catch (\Throwable $th) {
164171
//throw $th;

0 commit comments

Comments
 (0)