-
Notifications
You must be signed in to change notification settings - Fork 83
Add actor blocking functionality with list table interface #2027
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 all commits
Commits
Show all changes
44 commits
Select commit
Hold shift + click to select a range
d1348fd
Add comprehensive ActivityPub moderation system
obenland d640adf
Add comprehensive PHPUnit tests for Moderation API
obenland 202047e
Apply PHPCBF code formatting fixes
obenland 2892d71
Improve moderation JavaScript UX and fix terminology
obenland cc9cf01
Add code coverage annotations and refactor blocking logic
obenland db625c1
Add changelog entry for blocking and moderation system
obenland 72f919e
Fix AJAX nonce verification order for better security
obenland 3c8d6f0
Consolidate moderation admin functionality and fix AJAX parameter con…
obenland ecaacac
Add moderation meta and settings for ActivityPub
obenland 2084082
Align variable assignments in ajax_moderation_settings
obenland c4b48e6
Fix test_add_user_block_valid_types by mocking remote actor response
obenland b4f9c68
Remove explicit cap check
obenland 42bb423
Backslashit
obenland 52b0423
Remove actor block functionality from moderation settings
obenland 11dd52a
Merge branch 'trunk' into add/block-lists
obenland d225429
Moderation: Refine UI with singular class names and table-only handling
obenland 1d94cf3
Use namespaced functions and improve moderation labels
obenland 15679ca
Refactor moderation to remove actor-level blocking
obenland 4976174
Add actor blocking functionality with list table interface
obenland 9495d26
Merge branch 'trunk' into feature/new-actor-blocks
obenland 087d22c
Fix merge stuff
obenland f403d4b
Backslashit
obenland 84602eb
Merge branch 'trunk' into feature/new-actor-blocks
obenland 8e93ef1
Add periods to admin method docblocks and fix translation call
obenland 9c46998
Add hooks for user and site block/unblock actions
obenland a608f5e
Remove blocked actors from following list on block
obenland 8f2cd8c
Add changelog
matticbot 7320518
Refactor actor blocking and icon handling
obenland c48e16a
Update label for profile input for accessibility
obenland 2a8c607
Clean post cache after block/unblock actions
obenland c0a66eb
Refactor actor blocking logic in Blocked_Actors table
obenland d990f45
Refactor unfollow to use actor ID instead of post
obenland 3b10797
Merge branch 'trunk' into feature/new-actor-blocks
obenland fcfc8fe
Merge branch 'trunk' into feature/new-actor-blocks
pfefferle b909d5e
Update templates/blocked-actors-list.php
obenland 48d3211
Align Following input label with Block input
obenland 3c43505
Resolve non-URL actors via Webfinger before blocking
obenland 625e23f
Refactor blocked actors into dedicated collection class
obenland df08a79
Move actor blocking management to Blocked_Actors collection
obenland b074be0
Fix PHP coding standards violations
obenland d2736af
Replace magic strings with TYPE constants in moderation system
obenland fa63f80
Merge branch 'trunk' into feature/new-actor-blocks
obenland b1c49ef
Followers: First pass at blocking accounts (#1935)
obenland 6d0db54
Preserve original profile in follow error redirects
obenland 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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| Significance: minor | ||
| Type: added | ||
|
|
||
| Add actor blocking functionality with list table interface for managing blocked users and site-wide blocks |
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,4 @@ | ||
| Significance: minor | ||
| Type: added | ||
|
|
||
| Follower lists now include the option to block individual accounts. |
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
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,138 @@ | ||
| <?php | ||
| /** | ||
| * Blocked Actors collection file. | ||
| * | ||
| * @package Activitypub | ||
| */ | ||
|
|
||
| namespace Activitypub\Collection; | ||
|
|
||
| use Activitypub\Moderation; | ||
|
|
||
| /** | ||
| * ActivityPub Blocked Actors Collection. | ||
| */ | ||
| class Blocked_Actors { | ||
|
|
||
| /** | ||
| * Add an actor block for a user. | ||
| * | ||
| * @param int $user_id The user ID. | ||
| * @param string $value The actor URI to block. | ||
| * @return bool True on success, false on failure. | ||
| */ | ||
| public static function add_block( $user_id, $value ) { | ||
| // Find or create actor post. | ||
| $actor_post = Actors::fetch_remote_by_uri( $value ); | ||
| if ( \is_wp_error( $actor_post ) ) { | ||
| return false; | ||
| } | ||
|
|
||
| $blocked = \get_post_meta( $actor_post->ID, Moderation::BLOCKED_ACTORS_META_KEY, false ); | ||
| if ( ! \in_array( (string) $user_id, $blocked, true ) ) { | ||
| /** | ||
| * Fired when an actor is blocked. | ||
| * | ||
| * @param string $value The blocked actor URI. | ||
| * @param string $type The block type (actor, domain, keyword). | ||
| * @param int $user_id The user ID. | ||
| */ | ||
| \do_action( 'activitypub_add_user_block', $value, Moderation::TYPE_ACTOR, $user_id ); | ||
|
|
||
| $result = (bool) \add_post_meta( $actor_post->ID, Moderation::BLOCKED_ACTORS_META_KEY, (string) $user_id ); | ||
| \clean_post_cache( $actor_post->ID ); | ||
|
|
||
| return $result; | ||
| } | ||
|
|
||
| return true; // Already blocked. | ||
| } | ||
|
|
||
| /** | ||
| * Remove an actor block for a user. | ||
| * | ||
| * @param int $user_id The user ID. | ||
| * @param string|int $value The actor URI or post ID to unblock. | ||
| * @return bool True on success, false on failure. | ||
| */ | ||
| public static function remove_block( $user_id, $value ) { | ||
| // Handle both post ID and URI formats. | ||
| if ( \is_numeric( $value ) ) { | ||
| $post_id = (int) $value; | ||
| } else { | ||
| // Otherwise, find the actor post by actor ID. | ||
| $actor_post = Actors::fetch_remote_by_uri( $value ); | ||
| if ( \is_wp_error( $actor_post ) ) { | ||
| return false; | ||
| } | ||
| $post_id = $actor_post->ID; | ||
| } | ||
|
|
||
| /** | ||
| * Fired when an actor is unblocked. | ||
| * | ||
| * @param string $value The unblocked actor URI. | ||
| * @param string $type The block type (actor, domain, keyword). | ||
| * @param int $user_id The user ID. | ||
| */ | ||
| \do_action( 'activitypub_remove_user_block', $value, Moderation::TYPE_ACTOR, $user_id ); | ||
|
|
||
| $result = \delete_post_meta( $post_id, Moderation::BLOCKED_ACTORS_META_KEY, $user_id ); | ||
| \clean_post_cache( $post_id ); | ||
|
|
||
| return $result; | ||
| } | ||
|
|
||
| /** | ||
| * Get the blocked actors of a given user, along with a total count for pagination purposes. | ||
| * | ||
| * @param int|null $user_id The ID of the WordPress User. | ||
| * @param int $number Maximum number of results to return. | ||
| * @param int $page Page number. | ||
| * @param array $args The WP_Query arguments. | ||
| * | ||
| * @return array { | ||
| * Data about the blocked actors. | ||
| * | ||
| * @type \WP_Post[] $blocked_actors List of blocked Actor WP_Post objects. | ||
| * @type int $total Total number of blocked actors. | ||
| * } | ||
| */ | ||
| public static function get_blocked_actors_with_count( $user_id, $number = -1, $page = null, $args = array() ) { | ||
| $defaults = array( | ||
| 'post_type' => Actors::POST_TYPE, | ||
| 'posts_per_page' => $number, | ||
| 'paged' => $page, | ||
| 'orderby' => 'ID', | ||
| 'order' => 'DESC', | ||
| // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_query | ||
| 'meta_query' => array( | ||
obenland marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| array( | ||
| 'key' => Moderation::BLOCKED_ACTORS_META_KEY, | ||
| 'value' => $user_id, | ||
| ), | ||
| ), | ||
| ); | ||
|
|
||
| $args = \wp_parse_args( $args, $defaults ); | ||
| $query = new \WP_Query( $args ); | ||
| $total = $query->found_posts; | ||
| $blocked_actors = \array_filter( $query->posts ); | ||
|
|
||
| return \compact( 'blocked_actors', 'total' ); | ||
| } | ||
|
|
||
| /** | ||
| * Get the blocked actors of a given user. | ||
| * | ||
| * @param int|null $user_id The ID of the WordPress User. | ||
| * @param int $number Maximum number of results to return. | ||
| * @param int $page Page number. | ||
| * @param array $args The WP_Query arguments. | ||
| * | ||
| * @return \WP_Post[] List of blocked Actors. | ||
| */ | ||
| public static function get_blocked_actors( $user_id, $number = -1, $page = null, $args = array() ) { | ||
| return self::get_blocked_actors_with_count( $user_id, $number, $page, $args )['blocked_actors']; | ||
| } | ||
| } | ||
Oops, something went wrong.
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.