-
Notifications
You must be signed in to change notification settings - Fork 83
Refactor avatar handling to use remote actor meta #2373
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 2 commits
Commits
Show all changes
32 commits
Select commit
Hold shift + click to select a range
d727234
Refactor avatar handling to use remote actor meta
pfefferle 27a3bf1
Remove avatar_url meta from comment creation
pfefferle 2d4a06d
Update includes/collection/class-remote-actors.php
pfefferle 1326fcc
Improve avatar URL handling and add migration tests
pfefferle 2c18173
Refactor avatar URL handling in Remote_Actors
pfefferle 9a72a3b
Optimize comment meta query in migration class
pfefferle a887f63
Merge branch 'trunk' into improve-avatar-handling
pfefferle 8063d28
Add optimized remote actor queries and avatar tests
pfefferle 67f4b6f
Merge branch 'trunk' into improve-avatar-handling
pfefferle c918461
Refactor remote actor deletion to use actor ID
pfefferle 7d8fb8e
Merge branch 'trunk' into improve-avatar-handling
pfefferle 712c3a4
Add changelog
matticbot a562838
Merge branch 'trunk' into improve-avatar-handling
pfefferle bf10eb0
Update includes/collection/class-remote-actors.php
pfefferle 6491890
Add return type to delete_remote_actor docblock
pfefferle 4aab7a1
Merge branch 'trunk' into improve-avatar-handling
pfefferle 524b91f
Update includes/collection/class-remote-actors.php
pfefferle bcdd915
Update includes/collection/class-remote-actors.php
pfefferle ebf3c62
Update includes/collection/class-remote-actors.php
pfefferle b33c8b4
Update tests/phpunit/tests/includes/class-test-migration.php
pfefferle baf34f7
Remove WP_Post type check for remote actor
pfefferle 396df8f
Refactor comment creation in migration test
pfefferle 7c7b4b2
Remove cleanup code from migration tests
pfefferle 9c23bb1
Optimize avatar migration query and update meta check
pfefferle 1979e8e
Update includes/class-migration.php
pfefferle b769c32
Merge branch 'trunk' into improve-avatar-handling
pfefferle 1f75317
Update avatar URL storage logic in Remote_Actors
pfefferle 299c898
Merge branch 'trunk' into improve-avatar-handling
pfefferle 5ff43e1
Rename Avatar class to Avatars and update references
pfefferle a472a99
Set default avatar URL when icon is missing
pfefferle 34753a6
Merge branch 'trunk' into improve-avatar-handling
pfefferle ce06914
Update test for get_avatar_url default behavior
pfefferle File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,82 @@ | ||
| <?php | ||
| /** | ||
| * Avatar class file. | ||
| * | ||
| * @package Activitypub | ||
| */ | ||
|
|
||
| namespace Activitypub; | ||
|
|
||
| use Activitypub\Collection\Remote_Actors; | ||
|
|
||
| /** | ||
| * ActivityPub Avatar class. | ||
| */ | ||
| class Avatar { | ||
| /** | ||
| * Initialize the class, registering WordPress hooks. | ||
| */ | ||
| public static function init() { | ||
| \add_filter( 'pre_get_avatar_data', array( self::class, 'pre_get_avatar_data' ), 11, 2 ); | ||
| } | ||
|
|
||
| /** | ||
| * Replaces the default avatar. | ||
| * | ||
| * @param array $args Arguments passed to get_avatar_data(), after processing. | ||
| * @param int|string|object $id_or_email A user ID, email address, or comment object. | ||
| * | ||
| * @return array $args | ||
| */ | ||
| public static function pre_get_avatar_data( $args, $id_or_email ) { | ||
| if ( | ||
| ! $id_or_email instanceof \WP_Comment || | ||
| ! isset( $id_or_email->comment_type ) || | ||
| $id_or_email->user_id | ||
| ) { | ||
| return $args; | ||
| } | ||
|
|
||
| /** | ||
| * Filter allowed comment types for avatars. | ||
| * | ||
| * @param array $allowed_comment_types Array of allowed comment types. | ||
| */ | ||
| $allowed_comment_types = \apply_filters( 'get_avatar_comment_types', array( 'comment' ) ); | ||
| if ( ! \in_array( $id_or_email->comment_type ?: 'comment', $allowed_comment_types, true ) ) { // phpcs:ignore Universal.Operators.DisallowShortTernary | ||
| return $args; | ||
| } | ||
|
|
||
| $avatar = null; | ||
|
|
||
| // First, try to get avatar from remote actor. | ||
| $remote_actor_id = \get_comment_meta( $id_or_email->comment_ID, '_activitypub_remote_actor_id', true ); | ||
| if ( $remote_actor_id ) { | ||
| $avatar = Remote_Actors::get_avatar_url( $remote_actor_id ); | ||
| } | ||
|
|
||
| // Fall back to avatar_url comment meta for backward compatibility. | ||
| if ( ! $avatar ) { | ||
| $avatar = \get_comment_meta( $id_or_email->comment_ID, 'avatar_url', true ); | ||
| } | ||
|
|
||
| if ( $avatar ) { | ||
| if ( empty( $args['class'] ) ) { | ||
| $args['class'] = array(); | ||
| } elseif ( \is_string( $args['class'] ) ) { | ||
| $args['class'] = \explode( ' ', $args['class'] ); | ||
| } | ||
|
|
||
| /** This filter is documented in wp-includes/link-template.php */ | ||
| $args['url'] = \apply_filters( 'get_avatar_url', $avatar, $id_or_email, $args ); | ||
| $args['class'][] = 'avatar'; | ||
| $args['class'][] = 'avatar-activitypub'; | ||
| $args['class'][] = 'avatar-' . (int) $args['size']; | ||
| $args['class'][] = 'photo'; | ||
| $args['class'][] = 'u-photo'; | ||
| $args['class'] = \array_unique( $args['class'] ); | ||
| } | ||
|
|
||
| return $args; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.