Skip to content

Commit 4c09cb8

Browse files
authored
Refactor collection classes to use unified query methods (#2340)
1 parent b686a99 commit 4c09cb8

32 files changed

+446
-190
lines changed

build/follow-me/render.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@
108108

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

114114
ob_start();

build/followers/render.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
}
4747

4848
$_per_page = absint( $attributes['per_page'] );
49-
$follower_data = Followers::get_followers_with_count( $user_id, $_per_page );
49+
$follower_data = Followers::query( $user_id, $_per_page );
5050

5151
// Prepare Followers data for the Interactivity API context.
5252
$followers = array_map(

includes/class-migration.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ public static function migrate_from_0_17() {
284284

285285
if ( $followers ) {
286286
foreach ( $followers as $actor ) {
287-
Followers::add_follower( $user_id, $actor );
287+
Followers::add( $user_id, $actor );
288288
}
289289
}
290290
}
@@ -378,14 +378,14 @@ private static function migrate_to_4_0_0() {
378378
);
379379

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

383383
if ( $followers ) {
384384
\update_user_option( $user->ID, 'activitypub_use_permalink_as_id', '1' );
385385
}
386386
}
387387

388-
$followers = Followers::get_followers( Actors::BLOG_USER_ID );
388+
$followers = Followers::get_many( Actors::BLOG_USER_ID );
389389

390390
if ( $followers ) {
391391
\update_option( 'activitypub_use_permalink_as_id_for_blog', '1' );

includes/class-moderation.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ public static function activity_is_blocked_for_user( $activity, $user_id ) {
112112
public static function add_user_block( $user_id, $type, $value ) {
113113
switch ( $type ) {
114114
case self::TYPE_ACTOR:
115-
return Blocked_Actors::add_block( $user_id, $value );
115+
return Blocked_Actors::add( $user_id, $value );
116116

117117
case self::TYPE_DOMAIN:
118118
case self::TYPE_KEYWORD:
@@ -148,7 +148,7 @@ public static function add_user_block( $user_id, $type, $value ) {
148148
public static function remove_user_block( $user_id, $type, $value ) {
149149
switch ( $type ) {
150150
case self::TYPE_ACTOR:
151-
return Blocked_Actors::remove_block( $user_id, $value );
151+
return Blocked_Actors::remove( $user_id, $value );
152152

153153
case self::TYPE_DOMAIN:
154154
case self::TYPE_KEYWORD:
@@ -182,7 +182,7 @@ public static function remove_user_block( $user_id, $type, $value ) {
182182
*/
183183
public static function get_user_blocks( $user_id ) {
184184
return array(
185-
'actors' => \wp_list_pluck( Blocked_Actors::get_blocked_actors( $user_id ), 'guid' ),
185+
'actors' => \wp_list_pluck( Blocked_Actors::get_many( $user_id ), 'guid' ),
186186
'domains' => \get_user_meta( $user_id, self::USER_META_KEYS[ self::TYPE_DOMAIN ], true ) ?: array(), // phpcs:ignore Universal.Operators.DisallowShortTernary.Found
187187
'keywords' => \get_user_meta( $user_id, self::USER_META_KEYS[ self::TYPE_KEYWORD ], true ) ?: array(), // phpcs:ignore Universal.Operators.DisallowShortTernary.Found
188188
);
@@ -266,7 +266,7 @@ public static function remove_site_block( $type, $value ) {
266266
*/
267267
public static function get_site_blocks() {
268268
return array(
269-
'actors' => \wp_list_pluck( Blocked_Actors::get_blocked_actors( Actors::BLOG_USER_ID ), 'guid' ),
269+
'actors' => \wp_list_pluck( Blocked_Actors::get_many( Actors::BLOG_USER_ID ), 'guid' ),
270270
'domains' => \get_option( self::OPTION_KEYS[ self::TYPE_DOMAIN ], array() ),
271271
'keywords' => \get_option( self::OPTION_KEYS[ self::TYPE_KEYWORD ], array() ),
272272
);

includes/collection/class-blocked-actors.php

Lines changed: 76 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class Blocked_Actors {
2121
* @param string $value The actor URI to block.
2222
* @return bool True on success, false on failure.
2323
*/
24-
public static function add_block( $user_id, $value ) {
24+
public static function add( $user_id, $value ) {
2525
// Find or create actor post.
2626
$actor_post = Remote_Actors::fetch_by_uri( $value );
2727
if ( \is_wp_error( $actor_post ) ) {
@@ -55,7 +55,7 @@ public static function add_block( $user_id, $value ) {
5555
* @param string|int $value The actor URI or post ID to unblock.
5656
* @return bool True on success, false on failure.
5757
*/
58-
public static function remove_block( $user_id, $value ) {
58+
public static function remove( $user_id, $value ) {
5959
// Handle both post ID and URI formats.
6060
if ( \is_numeric( $value ) ) {
6161
$post_id = (int) $value;
@@ -84,7 +84,7 @@ public static function remove_block( $user_id, $value ) {
8484
}
8585

8686
/**
87-
* Get the blocked actors of a given user, along with a total count for pagination purposes.
87+
* Query blocked actors of a given user, with pagination info.
8888
*
8989
* @param int|null $user_id The ID of the WordPress User.
9090
* @param int $number Maximum number of results to return.
@@ -98,7 +98,7 @@ public static function remove_block( $user_id, $value ) {
9898
* @type int $total Total number of blocked actors.
9999
* }
100100
*/
101-
public static function get_blocked_actors_with_count( $user_id, $number = -1, $page = null, $args = array() ) {
101+
public static function query( $user_id, $number = -1, $page = null, $args = array() ) {
102102
$defaults = array(
103103
'post_type' => Remote_Actors::POST_TYPE,
104104
'posts_per_page' => $number,
@@ -122,9 +122,78 @@ public static function get_blocked_actors_with_count( $user_id, $number = -1, $p
122122
return \compact( 'blocked_actors', 'total' );
123123
}
124124

125+
/**
126+
* Get many blocked actors.
127+
*
128+
* @param int|null $user_id The ID of the WordPress User.
129+
* @param int $number Maximum number of results to return.
130+
* @param int $page Page number.
131+
* @param array $args The WP_Query arguments.
132+
*
133+
* @return \WP_Post[] List of blocked Actors.
134+
*/
135+
public static function get_many( $user_id, $number = -1, $page = null, $args = array() ) {
136+
return self::query( $user_id, $number, $page, $args )['blocked_actors'];
137+
}
138+
139+
/**
140+
* Add an actor block for a user.
141+
*
142+
* @deprecated unreleased Use {@see Blocked_Actors::add()}.
143+
*
144+
* @param int $user_id The user ID.
145+
* @param string $value The actor URI to block.
146+
* @return bool True on success, false on failure.
147+
*/
148+
public static function add_block( $user_id, $value ) {
149+
\_deprecated_function( __METHOD__, 'unreleased', 'Activitypub\Collection\Blocked_Actors::add' );
150+
151+
return self::add( $user_id, $value );
152+
}
153+
154+
/**
155+
* Remove an actor block for a user.
156+
*
157+
* @deprecated unreleased Use {@see Blocked_Actors::remove()}.
158+
*
159+
* @param int $user_id The user ID.
160+
* @param string|int $value The actor URI or post ID to unblock.
161+
* @return bool True on success, false on failure.
162+
*/
163+
public static function remove_block( $user_id, $value ) {
164+
\_deprecated_function( __METHOD__, 'unreleased', 'Activitypub\Collection\Blocked_Actors::remove' );
165+
166+
return self::remove( $user_id, $value );
167+
}
168+
169+
/**
170+
* Get the blocked actors of a given user, along with a total count for pagination purposes.
171+
*
172+
* @deprecated unreleased Use {@see Blocked_Actors::query()}.
173+
*
174+
* @param int|null $user_id The ID of the WordPress User.
175+
* @param int $number Maximum number of results to return.
176+
* @param int $page Page number.
177+
* @param array $args The WP_Query arguments.
178+
*
179+
* @return array {
180+
* Data about the blocked actors.
181+
*
182+
* @type \WP_Post[] $blocked_actors List of blocked Actor WP_Post objects.
183+
* @type int $total Total number of blocked actors.
184+
* }
185+
*/
186+
public static function get_blocked_actors_with_count( $user_id, $number = -1, $page = null, $args = array() ) {
187+
\_deprecated_function( __METHOD__, 'unreleased', 'Activitypub\Collection\Blocked_Actors::query' );
188+
189+
return self::query( $user_id, $number, $page, $args );
190+
}
191+
125192
/**
126193
* Get the blocked actors of a given user.
127194
*
195+
* @deprecated unreleased Use {@see Blocked_Actors::get_many()}.
196+
*
128197
* @param int|null $user_id The ID of the WordPress User.
129198
* @param int $number Maximum number of results to return.
130199
* @param int $page Page number.
@@ -133,6 +202,8 @@ public static function get_blocked_actors_with_count( $user_id, $number = -1, $p
133202
* @return \WP_Post[] List of blocked Actors.
134203
*/
135204
public static function get_blocked_actors( $user_id, $number = -1, $page = null, $args = array() ) {
136-
return self::get_blocked_actors_with_count( $user_id, $number, $page, $args )['blocked_actors'];
205+
\_deprecated_function( __METHOD__, 'unreleased', 'Activitypub\Collection\Blocked_Actors::get_many' );
206+
207+
return self::get_many( $user_id, $number, $page, $args );
137208
}
138209
}

0 commit comments

Comments
 (0)