Skip to content

Add get_visible_actor_types() actor-visibility accessor#3525

Open
pfefferle wants to merge 1 commit into
trunkfrom
update/actor-visibility-accessor
Open

Add get_visible_actor_types() actor-visibility accessor#3525
pfefferle wants to merge 1 commit into
trunkfrom
update/actor-visibility-accessor

Conversation

@pfefferle

Copy link
Copy Markdown
Member

Part of the Actors v2 refactor (CMF-556), step 1.

Proposed changes:

  • Introduce Activitypub\get_visible_actor_types() — a single accessor that answers "which actor types does this site expose?", returning the subset of user/blog that is not disabled. It folds the activitypub_actor_mode option and the legacy override constants (ACTIVITYPUB_SINGLE_USER_MODE, ACTIVITYPUB_DISABLE_BLOG_USER, ACTIVITYPUB_DISABLE_USER) into a plain list, computed via the existing is_user_type_disabled() so all current filters keep firing.
  • Add an activitypub_visible_actor_types filter over the result.
  • Refactor 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:

  • Have you written new tests for your changes, if applicable?

Tests cover the mode→types mapping across all three actor modes, parity with is_user_type_disabled() (including the legacy activitypub_is_user_type_disabled filter), the new activitypub_visible_actor_types filter, and is_single_user() directly across all modes.

Testing instructions:

  • npm run env-test -- --filter=Test_Functions_User — all green.
  • No user-facing change: an existing site behaves identically. The accessor is internal plumbing for the Actors v2 work.

Changelog entry

No changelog needed — internal refactor with no user-facing change (Skip Changelog).

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).
Copilot AI review requested due to automatic review settings July 7, 2026 15:10
@pfefferle pfefferle added Skip Changelog Disables the "Changelog Updated" action for PRs where changelog entries are not necessary. Code Quality labels Jul 7, 2026
@pfefferle pfefferle self-assigned this Jul 7, 2026
@pfefferle pfefferle requested a review from a team July 7, 2026 15:10

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 the activitypub_visible_actor_types filter.
  • Refactor Activitypub\is_single_user() to derive its result from get_visible_actor_types().
  • Add PHPUnit tests covering mode→types mapping, parity with is_user_type_disabled() (incl. legacy filter), the new filter, and is_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' );
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Code Quality Skip Changelog Disables the "Changelog Updated" action for PRs where changelog entries are not necessary. [Tests] Includes Tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants