fix(oauth): actually use the third-party avatar and seed it only once
The OAuth flow wrote the provider avatar to `jio_oauth_avatar`, but nothing ever read it — every user who signed up through GitHub/QQ saw a Gravatar hash or the default avatar instead of their own picture. The reference seeds its `custom_avatar` from the OAuth profile and its resolver reads it back, so both halves were missing here. jio_get_custom_avatar_url() now falls back to the stored OAuth avatar when no uploaded one exists, which puts the chain at uploaded → third-party → external service → default. The theme already swaps WordPress's get_avatar_data, so one change covers every avatar surface. Writes go through a single seed_avatar() guard: it no-ops when an uploaded avatar or an existing OAuth avatar is present, matching the reference's `if ($args['avatar'] && !$custom_avatar)`. Previously both the bind path and the login refresh overwrote the meta unconditionally, which would have wiped a user's own picture on their next social login. Because the OAuth avatar now shows through once the upload is gone, both "restore default" flows (the REST endpoint and the admin profile box) delete it too; the admin checkbox also appears when only an OAuth avatar is set, since $avatar_url is now non-empty in that case. Baidu serves avatars from tb.himg.baidu.com, which 403s — rewritten to himg.bdimg.com the way the reference does. On top of that the URL is upgraded to https when the site runs over SSL, because the reference's scheme-relative form still yields a plain http:// when copied verbatim, and browsers block it as mixed content. WeChatShare was reading `custom_avatar` — a reference-theme key this codebase never writes — so its author branch always fell through to get_avatar_url(); it now uses the shared resolver like every other surface. Verification: drove the resolver through five states with a stub (none / OAuth only / both / upload only / Baidu legacy host) and confirmed the expected URL each time. Added oauth-avatar-contract.test.cjs to pin the resolution order, the seed guard, and the reset cleanup. 868 widget and navigation tests pass; the PSR-4 path audit reports 0 errors.
This commit is contained in:
1 parent
7d78a33a9d
commit
6f29e3d865
6 files changed
+137
-16
No files matched your search
@@ -27,6 +27,8 @@ trait UserControllerProfileMediaOperations {
|
||||
|
||||
$attachment_id = (int) get_user_meta($user_id, 'jio_avatar_attachment_id', true);
|
||||
delete_user_meta($user_id, 'jio_avatar_attachment_id');
|
||||
// 第三方头像会在上传头像被清除后重新顶上来,恢复默认时必须一并丢弃。
|
||||
delete_user_meta($user_id, 'jio_oauth_avatar');
|
||||
$this->delete_owned_profile_attachment($attachment_id, $user_id);
|
||||
do_action('jio_user_avatar_changed', $user_id, 0, '');
|
||||
|
||||
|
||||
Reference in new issue
Block a user