Skip to content
Merged
2 changes: 1 addition & 1 deletion build/follow-me/render.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@

$stats = array(
'posts' => $user_id ? count_user_posts( $user_id, 'post', true ) : (int) wp_count_posts()->publish,
'followers' => Followers::count_followers( $user_id ),
'followers' => Followers::count( $user_id ),
);

ob_start();
Expand Down
2 changes: 1 addition & 1 deletion build/followers/render.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
}

$_per_page = absint( $attributes['per_page'] );
$follower_data = Followers::get_followers_with_count( $user_id, $_per_page );
$follower_data = Followers::query( $user_id, $_per_page );

// Prepare Followers data for the Interactivity API context.
$followers = array_map(
Expand Down
6 changes: 3 additions & 3 deletions includes/class-migration.php
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ public static function migrate_from_0_17() {

if ( $followers ) {
foreach ( $followers as $actor ) {
Followers::add_follower( $user_id, $actor );
Followers::add( $user_id, $actor );
}
}
}
Expand Down Expand Up @@ -378,14 +378,14 @@ private static function migrate_to_4_0_0() {
);

foreach ( $users as $user ) {
$followers = Followers::get_followers( $user->ID );
$followers = Followers::get_many( $user->ID );

if ( $followers ) {
\update_user_option( $user->ID, 'activitypub_use_permalink_as_id', '1' );
}
}

$followers = Followers::get_followers( Actors::BLOG_USER_ID );
$followers = Followers::get_many( Actors::BLOG_USER_ID );

if ( $followers ) {
\update_option( 'activitypub_use_permalink_as_id_for_blog', '1' );
Expand Down
8 changes: 4 additions & 4 deletions includes/class-moderation.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ public static function activity_is_blocked_for_user( $activity, $user_id ) {
public static function add_user_block( $user_id, $type, $value ) {
switch ( $type ) {
case self::TYPE_ACTOR:
return Blocked_Actors::add_block( $user_id, $value );
return Blocked_Actors::add( $user_id, $value );

case self::TYPE_DOMAIN:
case self::TYPE_KEYWORD:
Expand Down Expand Up @@ -148,7 +148,7 @@ public static function add_user_block( $user_id, $type, $value ) {
public static function remove_user_block( $user_id, $type, $value ) {
switch ( $type ) {
case self::TYPE_ACTOR:
return Blocked_Actors::remove_block( $user_id, $value );
return Blocked_Actors::remove( $user_id, $value );

case self::TYPE_DOMAIN:
case self::TYPE_KEYWORD:
Expand Down Expand Up @@ -182,7 +182,7 @@ public static function remove_user_block( $user_id, $type, $value ) {
*/
public static function get_user_blocks( $user_id ) {
return array(
'actors' => \wp_list_pluck( Blocked_Actors::get_blocked_actors( $user_id ), 'guid' ),
'actors' => \wp_list_pluck( Blocked_Actors::get_many( $user_id ), 'guid' ),
'domains' => \get_user_meta( $user_id, self::USER_META_KEYS[ self::TYPE_DOMAIN ], true ) ?: array(), // phpcs:ignore Universal.Operators.DisallowShortTernary.Found
'keywords' => \get_user_meta( $user_id, self::USER_META_KEYS[ self::TYPE_KEYWORD ], true ) ?: array(), // phpcs:ignore Universal.Operators.DisallowShortTernary.Found
);
Expand Down Expand Up @@ -266,7 +266,7 @@ public static function remove_site_block( $type, $value ) {
*/
public static function get_site_blocks() {
return array(
'actors' => \wp_list_pluck( Blocked_Actors::get_blocked_actors( Actors::BLOG_USER_ID ), 'guid' ),
'actors' => \wp_list_pluck( Blocked_Actors::get_many( Actors::BLOG_USER_ID ), 'guid' ),
'domains' => \get_option( self::OPTION_KEYS[ self::TYPE_DOMAIN ], array() ),
'keywords' => \get_option( self::OPTION_KEYS[ self::TYPE_KEYWORD ], array() ),
);
Expand Down
77 changes: 72 additions & 5 deletions includes/collection/class-blocked-actors.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class Blocked_Actors {
* @param string $value The actor URI to block.
* @return bool True on success, false on failure.
*/
public static function add_block( $user_id, $value ) {
public static function add( $user_id, $value ) {
// Find or create actor post.
$actor_post = Remote_Actors::fetch_by_uri( $value );
if ( \is_wp_error( $actor_post ) ) {
Expand Down Expand Up @@ -55,7 +55,7 @@ public static function add_block( $user_id, $value ) {
* @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 ) {
public static function remove( $user_id, $value ) {
// Handle both post ID and URI formats.
if ( \is_numeric( $value ) ) {
$post_id = (int) $value;
Expand Down Expand Up @@ -84,7 +84,7 @@ public static function remove_block( $user_id, $value ) {
}

/**
* Get the blocked actors of a given user, along with a total count for pagination purposes.
* Query blocked actors of a given user, with pagination info.
*
* @param int|null $user_id The ID of the WordPress User.
* @param int $number Maximum number of results to return.
Expand All @@ -98,7 +98,7 @@ public static function remove_block( $user_id, $value ) {
* @type int $total Total number of blocked actors.
* }
*/
public static function get_blocked_actors_with_count( $user_id, $number = -1, $page = null, $args = array() ) {
public static function query( $user_id, $number = -1, $page = null, $args = array() ) {
$defaults = array(
'post_type' => Remote_Actors::POST_TYPE,
'posts_per_page' => $number,
Expand All @@ -122,9 +122,75 @@ public static function get_blocked_actors_with_count( $user_id, $number = -1, $p
return \compact( 'blocked_actors', 'total' );
}

/**
* Get many blocked actors.
*
* @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_many( $user_id, $number = -1, $page = null, $args = array() ) {
return self::query( $user_id, $number, $page, $args )['blocked_actors'];
}

/**
* Add an actor block for a user.
*
* @deprecated unreleased Use {@see Blocked_Actors::add()}
*
* @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 ) {
_deprecated_function( __METHOD__, 'unreleased', 'Activitypub\Collection\Blocked_Actors::add' );
return self::add( $user_id, $value );
}

/**
* Remove an actor block for a user.
*
* @deprecated unreleased Use {@see Blocked_Actors::remove()}
*
* @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 ) {
_deprecated_function( __METHOD__, 'unreleased', 'Activitypub\Collection\Blocked_Actors::remove' );
return self::remove( $user_id, $value );
}

/**
* Get the blocked actors of a given user, along with a total count for pagination purposes.
*
* @deprecated unreleased Use {@see Blocked_Actors::query()}
*
* @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() ) {
_deprecated_function( __METHOD__, 'unreleased', 'Activitypub\Collection\Blocked_Actors::query' );
return self::query( $user_id, $number, $page, $args );
}

/**
* Get the blocked actors of a given user.
*
* @deprecated unreleased Use {@see Blocked_Actors::get_many()}
*
* @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.
Expand All @@ -133,6 +199,7 @@ public static function get_blocked_actors_with_count( $user_id, $number = -1, $p
* @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'];
_deprecated_function( __METHOD__, 'unreleased', 'Activitypub\Collection\Blocked_Actors::get_many' );
return self::get_many( $user_id, $number, $page, $args );
}
}
103 changes: 93 additions & 10 deletions includes/collection/class-followers.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class Followers {
*
* @return int|\WP_Error The Follower ID or an WP_Error.
*/
public static function add_follower( $user_id, $actor ) {
public static function add( $user_id, $actor ) {
$meta = get_remote_metadata_by_actor( $actor );

if ( Tombstone::exists( $meta ) ) {
Expand All @@ -66,6 +66,21 @@ public static function add_follower( $user_id, $actor ) {
return $post_id;
}

/**
* Add new Follower.
*
* @deprecated unreleased Use {@see Followers::add()}
*
* @param int $user_id The ID of the WordPress User.
* @param string $actor The Actor URL.
*
* @return int|\WP_Error The Follower ID or an WP_Error.
*/
public static function add_follower( $user_id, $actor ) {
_deprecated_function( __METHOD__, 'unreleased', 'Activitypub\Collection\Followers::add' );
return self::add( $user_id, $actor );
}

/**
* Remove a Follower.
*
Expand Down Expand Up @@ -109,7 +124,7 @@ public static function remove( $post_or_id, $user_id ) {
public static function remove_follower( $user_id, $actor ) {
_deprecated_function( __METHOD__, '7.1.0', 'Activitypub\Collection\Followers::remove' );

$remote_actor = self::get_follower( $user_id, $actor );
$remote_actor = self::get_by_uri( $user_id, $actor );

if ( \is_wp_error( $remote_actor ) ) {
return false;
Expand All @@ -119,14 +134,14 @@ public static function remove_follower( $user_id, $actor ) {
}

/**
* Get a Follower.
* Get a Follower by URI.
*
* @param int $user_id The ID of the WordPress User.
* @param string $actor The Actor URL.
*
* @return \WP_Post|\WP_Error The Follower object or WP_Error on failure.
*/
public static function get_follower( $user_id, $actor ) {
public static function get_by_uri( $user_id, $actor ) {
global $wpdb;

// phpcs:ignore WordPress.DB.DirectDatabaseQuery
Expand All @@ -153,6 +168,21 @@ public static function get_follower( $user_id, $actor ) {
return \get_post( $id );
}

/**
* Get a Follower.
*
* @deprecated unreleased Use {@see Followers::get_by_uri()}
*
* @param int $user_id The ID of the WordPress User.
* @param string $actor The Actor URL.
*
* @return \WP_Post|\WP_Error The Follower object or WP_Error on failure.
*/
public static function get_follower( $user_id, $actor ) {
_deprecated_function( __METHOD__, 'unreleased', 'Activitypub\Collection\Followers::get_by_uri' );
return self::get_by_uri( $user_id, $actor );
}

/**
* Get a Follower by Actor independent of the User.
*
Expand All @@ -169,7 +199,7 @@ public static function get_follower_by_actor( $actor ) {
}

/**
* Get the Followers of a given user.
* Get many followers.
*
* @param int|null $user_id The ID of the WordPress User.
* @param int $number Maximum number of results to return.
Expand All @@ -178,15 +208,34 @@ public static function get_follower_by_actor( $actor ) {
*
* @return \WP_Post[] List of `Follower` objects.
*/
public static function get_followers( $user_id, $number = -1, $page = null, $args = array() ) {
$data = self::get_followers_with_count( $user_id, $number, $page, $args );
public static function get_many( $user_id, $number = -1, $page = null, $args = array() ) {
$data = self::query( $user_id, $number, $page, $args );

return $data['followers'];
}

/**
* Get the Followers of a given user.
*
* @deprecated unreleased Use {@see Followers::get_many()}
*
* @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 `Follower` objects.
*/
public static function get_followers( $user_id, $number = -1, $page = null, $args = array() ) {
_deprecated_function( __METHOD__, 'unreleased', 'Activitypub\Collection\Followers::get_many' );
return self::get_many( $user_id, $number, $page, $args );
}

/**
* Get the Followers of a given user, along with a total count for pagination purposes.
*
* @deprecated unreleased Use {@see Followers::query()}
*
* @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.
Expand All @@ -200,6 +249,26 @@ public static function get_followers( $user_id, $number = -1, $page = null, $arg
* }
*/
public static function get_followers_with_count( $user_id, $number = -1, $page = null, $args = array() ) {
_deprecated_function( __METHOD__, 'unreleased', 'Activitypub\Collection\Followers::query' );
return self::query( $user_id, $number, $page, $args );
}

/**
* Query followers with pagination info.
*
* @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 followers.
*
* @type \WP_Post[] $followers List of `Follower` objects.
* @type int $total Total number of followers.
* }
*/
public static function query( $user_id, $number = -1, $page = null, $args = array() ) {
$defaults = array(
'post_type' => Remote_Actors::POST_TYPE,
'posts_per_page' => $number,
Expand Down Expand Up @@ -230,14 +299,28 @@ public static function get_followers_with_count( $user_id, $number = -1, $page =
}

/**
* Count the total number of followers
* Count the total number of followers.
*
* @param int $user_id The ID of the WordPress User.
*
* @return int The number of Followers
*/
public static function count( $user_id ) {
return self::query( $user_id, 1 )['total'];
}

/**
* Count the total number of followers.
*
* @deprecated unreleased Use {@see Followers::count()}
*
* @param int $user_id The ID of the WordPress User.
*
* @return int The number of Followers
*/
public static function count_followers( $user_id ) {
return self::get_followers_with_count( $user_id, 1 )['total'];
_deprecated_function( __METHOD__, 'unreleased', 'Activitypub\Collection\Followers::count' );
return self::count( $user_id );
}

/**
Expand Down Expand Up @@ -377,7 +460,7 @@ public static function get_all_followers() {
),
),
);
return self::get_followers( null, null, null, $args );
return self::get_many( null, null, null, $args );
}

/**
Expand Down
Loading
Loading