get_follower requires user_id check
This commit is contained in:
parent
d1f6973d9b
commit
4a4a06de37
2 changed files with 36 additions and 4 deletions
|
@ -183,12 +183,27 @@ class Followers {
|
||||||
*
|
*
|
||||||
* @param string $actor The Actor URL
|
* @param string $actor The Actor URL
|
||||||
*
|
*
|
||||||
* @return \Activitypub\Model\Follower The Follower object
|
* @return \Activitypub\Model\Follower The Follower object
|
||||||
*/
|
*/
|
||||||
public static function get_follower( $actor ) {
|
public static function get_follower( $user_id, $actor ) {
|
||||||
$term = get_term_by( 'name', $actor, self::TAXONOMY );
|
$terms = new WP_Term_Query(
|
||||||
|
array(
|
||||||
|
'name' => $actor,
|
||||||
|
'taxonomy' => self::TAXONOMY,
|
||||||
|
'hide_empty' => false,
|
||||||
|
'object_ids' => $user_id,
|
||||||
|
'number' => 1,
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
return new Follower( $term->name );
|
$term = $terms->get_terms();
|
||||||
|
|
||||||
|
if ( is_array( $term ) && ! empty( $term ) ) {
|
||||||
|
$term = reset( $term );
|
||||||
|
return new Follower( $term->name );
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -50,6 +50,23 @@ class Test_Db_Activitypub_Followers extends WP_UnitTestCase {
|
||||||
$this->assertContains( $follower, $db_followers );
|
$this->assertContains( $follower, $db_followers );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function test_get_follower() {
|
||||||
|
$followers = array( 'https://example.com/author/jon' );
|
||||||
|
|
||||||
|
$pre_http_request = new MockAction();
|
||||||
|
add_filter( 'pre_http_request', array( $pre_http_request, 'filter' ), 10, 3 );
|
||||||
|
|
||||||
|
foreach ( $followers as $follower ) {
|
||||||
|
\Activitypub\Collection\Followers::add_follower( 1, $follower );
|
||||||
|
}
|
||||||
|
|
||||||
|
$follower = \Activitypub\Collection\Followers::get_follower( 1, 'https://example.com/author/jon' );
|
||||||
|
$this->assertEquals( 'https://example.com/author/jon', $follower->get_actor() );
|
||||||
|
|
||||||
|
$follower = \Activitypub\Collection\Followers::get_follower( 1, 'http://sally.example.org' );
|
||||||
|
$this->assertNull( $follower );
|
||||||
|
}
|
||||||
|
|
||||||
public static function http_request_host_is_external( $in, $host ) {
|
public static function http_request_host_is_external( $in, $host ) {
|
||||||
if ( in_array( $host, array( 'example.com', 'example.org' ), true ) ) {
|
if ( in_array( $host, array( 'example.com', 'example.org' ), true ) ) {
|
||||||
return true;
|
return true;
|
||||||
|
|
Loading…
Reference in a new issue