MatteoManna / Simple-User-Avatar

WordPress plugin that help users to add or remove his avatar using images from his Media Library.
https://wordpress.org/plugins/simple-user-avatar/
Other
16 stars 5 forks source link

Wordpress multidomain #8

Open Sampozzo opened 1 year ago

Sampozzo commented 1 year ago

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?

MatteoManna commented 1 year ago

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

Sampozzo commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

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

Sampozzo commented 1 year ago

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;