Simple-User-Avatar icon indicating copy to clipboard operation
Simple-User-Avatar copied to clipboard

Wordpress multidomain

Open Sampozzo opened this issue 3 years ago • 5 comments

Hello, just testing on a wordpress multisite over multiple domains. If i change my avatar on sub1.domain.com, my avatar of the same account on sub2.domain.com and on domain.com (the main website) will break.

Any help?

Sampozzo avatar Jan 10 '23 16:01 Sampozzo

Uh @Sampozzo, thank you for your message. Good question.

The problem is that my plugin retrieve avatar from the local Media Library, so I have to think about how to fix it.

Matteo

MatteoManna avatar Jan 11 '23 19:01 MatteoManna

Thank you @MatteoManna , the best for me is to have one single avatar over the whole network and not one avatar for every subdomain like it seems working other plugin i'm checking. I hope you will find a solution.

Sampozzo avatar Jan 11 '23 22:01 Sampozzo

Hello @MatteoManna i found a very simple solution that works for me, don't know it can be added to the official plugin.

The default blog have ID = 1

just add:

switch_to_blog(1);

before the

$attachment_id = get_user_meta( $user_id, SUA_USER_META_KEY, true );

at line 74

Sampozzo avatar Jan 24 '23 21:01 Sampozzo

sorry, after more testing, it doesn't work on upload in subdomains, but i think this is the direction

Sampozzo avatar Jan 24 '23 21:01 Sampozzo

ok sorry again for my continue posting, this works for me, i hope to help:

add this:

$user_blog = get_user_meta( $user_id, 'primary_blog', true);
switch_to_blog( $user_blog);

at line 75, just after this:

$attachment_id = get_user_meta( $user_id, SUA_USER_META_KEY, true );

Switch again to current blog before returning avatar:

restore_current_blog();
return $avatar;

Sampozzo avatar Jan 24 '23 23:01 Sampozzo

Hi @Sampozzo, thank you for code review, please send me a Pull Request.

I will review your code and then, if it's okay, I will release it.

MatteoManna avatar Nov 14 '24 08:11 MatteoManna