commit
b8ee030d78
1 changed files with 14 additions and 1 deletions
|
@ -19,6 +19,7 @@ use function Activitypub\get_remote_metadata_by_actor;
|
|||
*/
|
||||
class Followers {
|
||||
const TAXONOMY = 'activitypub-followers';
|
||||
const CACHE_KEY_INBOXES = 'follower_inboxes_%s';
|
||||
|
||||
/**
|
||||
* Register WordPress hooks/actions and register Taxonomy
|
||||
|
@ -225,6 +226,7 @@ class Followers {
|
|||
if ( is_wp_error( $result ) ) {
|
||||
return $result;
|
||||
} else {
|
||||
wp_cache_delete( sprintf( self::CACHE_KEY_INBOXES, $user_id ), 'activitypub' );
|
||||
return $follower;
|
||||
}
|
||||
}
|
||||
|
@ -238,6 +240,7 @@ class Followers {
|
|||
* @return bool|WP_Error True on success, false or WP_Error on failure.
|
||||
*/
|
||||
public static function remove_follower( $user_id, $actor ) {
|
||||
wp_cache_delete( sprintf( self::CACHE_KEY_INBOXES, $user_id ), 'activitypub' );
|
||||
return wp_remove_object_terms( $user_id, $actor, self::TAXONOMY );
|
||||
}
|
||||
|
||||
|
@ -376,6 +379,13 @@ class Followers {
|
|||
* @return array The list of Inboxes
|
||||
*/
|
||||
public static function get_inboxes( $user_id ) {
|
||||
$cache_key = sprintf( self::CACHE_KEY_INBOXES, $user_id );
|
||||
$inboxes = wp_cache_get( $cache_key, 'activitypub' );
|
||||
|
||||
if ( $inboxes ) {
|
||||
return $inboxes;
|
||||
}
|
||||
|
||||
// get all Followers of a ID of the WordPress User
|
||||
$terms = new WP_Term_Query(
|
||||
array(
|
||||
|
@ -409,7 +419,10 @@ class Followers {
|
|||
)
|
||||
);
|
||||
|
||||
return array_filter( $results );
|
||||
$inboxes = array_filter( $results );
|
||||
wp_cache_set( $cache_key, $inboxes, 'activitypub' );
|
||||
|
||||
return $inboxes;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in a new issue