Add get_visible_actor_types() actor-visibility accessor#3525
Open
pfefferle wants to merge 1 commit into
Open
Conversation
Introduce a single seam for "which actor types does this site expose": get_visible_actor_types() folds the actor-mode option and the legacy override constants into a plain list (subset of user/blog) via the existing is_user_type_disabled(), behind a new activitypub_visible_actor_types filter. Refactor is_single_user() to read through the accessor. Pure refactor: no behavior change on existing filters. Part of the Actors v2 refactor (CMF-556).
There was a problem hiding this comment.
Pull request overview
Introduces a single accessor for determining which ActivityPub actor types are exposed by the site (as part of the Actors v2 refactor), and updates is_single_user() to use this new seam, with PHPUnit coverage for mode mapping and filters.
Changes:
- Add
Activitypub\get_visible_actor_types()and theactivitypub_visible_actor_typesfilter. - Refactor
Activitypub\is_single_user()to derive its result fromget_visible_actor_types(). - Add PHPUnit tests covering mode→types mapping, parity with
is_user_type_disabled()(incl. legacy filter), the new filter, andis_single_user().
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| includes/functions-user.php | Adds get_visible_actor_types() and refactors is_single_user() to use it. |
| tests/phpunit/tests/includes/class-test-functions-user.php | Adds tests for the new accessor, filter behavior, parity with legacy behavior, and is_single_user(). |
Comment on lines
+236
to
+253
| function get_visible_actor_types() { | ||
| $types = array(); | ||
|
|
||
| foreach ( array( 'user', 'blog' ) as $type ) { | ||
| if ( ! is_user_type_disabled( $type ) ) { | ||
| $types[] = $type; | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Filters the actor types that are visible on this site. | ||
| * | ||
| * @since unreleased | ||
| * | ||
| * @param string[] $types Visible actor types, subset of array( 'user', 'blog' ). | ||
| */ | ||
| return \apply_filters( 'activitypub_visible_actor_types', $types ); | ||
| } |
Comment on lines
+226
to
+247
| public function test_get_visible_actor_types_parity( $mode ) { | ||
| \update_option( 'activitypub_actor_mode', $mode ); | ||
|
|
||
| foreach ( array( 'user', 'blog' ) as $type ) { | ||
| $this->assertSame( | ||
| ! \Activitypub\is_user_type_disabled( $type ), | ||
| \in_array( $type, \Activitypub\get_visible_actor_types(), true ), | ||
| "Accessor and is_user_type_disabled() must agree on '{$type}' in mode '{$mode}'." | ||
| ); | ||
| } | ||
|
|
||
| // The legacy per-type filter is reflected by the accessor. | ||
| $disable_blog = function ( $disabled, $type ) { | ||
| return 'blog' === $type ? true : $disabled; | ||
| }; | ||
| \add_filter( 'activitypub_is_user_type_disabled', $disable_blog, 10, 2 ); | ||
|
|
||
| $this->assertNotContains( 'blog', \Activitypub\get_visible_actor_types(), 'A type disabled via the legacy filter must not be visible.' ); | ||
|
|
||
| \remove_filter( 'activitypub_is_user_type_disabled', $disable_blog ); | ||
| \delete_option( 'activitypub_actor_mode' ); | ||
| } |
Comment on lines
+285
to
299
| public function test_get_visible_actor_types_filter() { | ||
| \update_option( 'activitypub_actor_mode', ACTIVITYPUB_ACTOR_MODE ); | ||
|
|
||
| $add_blog = function ( $types ) { | ||
| $types[] = 'blog'; | ||
| return $types; | ||
| }; | ||
| \add_filter( 'activitypub_visible_actor_types', $add_blog ); | ||
|
|
||
| $this->assertSame( array( 'user', 'blog' ), \Activitypub\get_visible_actor_types() ); | ||
|
|
||
| \remove_filter( 'activitypub_visible_actor_types', $add_blog ); | ||
| \delete_option( 'activitypub_actor_mode' ); | ||
| } | ||
| } |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Part of the Actors v2 refactor (CMF-556), step 1.
Proposed changes:
Activitypub\get_visible_actor_types()— a single accessor that answers "which actor types does this site expose?", returning the subset ofuser/blogthat is not disabled. It folds theactivitypub_actor_modeoption and the legacy override constants (ACTIVITYPUB_SINGLE_USER_MODE,ACTIVITYPUB_DISABLE_BLOG_USER,ACTIVITYPUB_DISABLE_USER) into a plain list, computed via the existingis_user_type_disabled()so all current filters keep firing.activitypub_visible_actor_typesfilter over the result.is_single_user()to read through the accessor (array( 'blog' ) === get_visible_actor_types()), giving the new seam a first caller and revealing intent.This is a pure, behavior-preserving refactor. The mode option is read directly in ~two dozen places today; this establishes the one seam that later steps of the project (blog actor always-on, replacing the mode option with visible-actor-types) build on, instead of touching every call site at once.
Other information:
Tests cover the mode→types mapping across all three actor modes, parity with
is_user_type_disabled()(including the legacyactivitypub_is_user_type_disabledfilter), the newactivitypub_visible_actor_typesfilter, andis_single_user()directly across all modes.Testing instructions:
npm run env-test -- --filter=Test_Functions_User— all green.Changelog entry
No changelog needed — internal refactor with no user-facing change (Skip Changelog).