Skip to content

Commit ad162b1

Browse files
authored
Merge pull request #106 from humanmade/show-all-authors
Show all users in post author column.
2 parents b9f2439 + c271235 commit ad162b1

File tree

3 files changed

+101
-0
lines changed

3 files changed

+101
-0
lines changed

inc/namespace.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -428,6 +428,8 @@ function validate_authors( $authors, WP_REST_Request $request, string $param, st
428428

429429
/** @var WP_User[] */
430430
$users = get_users( [
431+
// Check all sites.
432+
'blog_id' => 0,
431433
'include' => $authors,
432434
'orderby' => 'include',
433435
] );

inc/template.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ function get_authors( WP_Post $post ) : array {
5353

5454
/** @var WP_User[] */
5555
$users = get_users( [
56+
// Check all sites.
57+
'blog_id' => 0,
5658
'include' => $author_ids,
5759
'orderby' => 'include',
5860
] );
@@ -155,6 +157,8 @@ function set_authors( WP_Post $post, array $authors ) : array {
155157

156158
/** @var WP_User[] */
157159
$users = get_users( [
160+
// Check all sites.
161+
'blog_id' => 0,
158162
'include' => $authors,
159163
'orderby' => 'include',
160164
] );

tests/phpunit/test-multisite.php

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
<?php
2+
/**
3+
* Multisite tests for the plugin.
4+
*
5+
* @package authorship
6+
*/
7+
8+
declare( strict_types=1 );
9+
10+
namespace Authorship\Tests;
11+
12+
use const Authorship\POSTS_PARAM;
13+
14+
/**
15+
* @group ms-required
16+
*/
17+
class TestMultisite extends TestCase {
18+
/**
19+
* Super admin.
20+
*
21+
* @var \WP_User
22+
*/
23+
protected static $super_admin;
24+
25+
/**
26+
* Sub site.
27+
*
28+
* @var \WP_Site
29+
*/
30+
protected static $sub_site;
31+
32+
/**
33+
* Set up class test fixtures.
34+
*
35+
* @param \WP_UnitTest_Factory $factory Test factory.
36+
*/
37+
public static function wpSetUpBeforeClass( \WP_UnitTest_Factory $factory ) {
38+
parent::wpSetUpBeforeClass( $factory );
39+
40+
// Create a super admin user.
41+
self::$super_admin = $factory->user->create_and_get( [
42+
'role' => 'administrator',
43+
'display_name' => 'Super Admin',
44+
'user_email' => 'super-admin.role@example.org',
45+
] );
46+
47+
grant_super_admin( self::$super_admin->ID );
48+
49+
// Create a subsite.
50+
self::$sub_site = $factory->blog->create_and_get( [
51+
'domain' => 'example.org',
52+
'path' => '/subsite',
53+
'title' => 'Authorship Sub Site',
54+
'user_id' => self::$users['admin']->ID,
55+
] );
56+
}
57+
58+
public function testSuperAdminWithNoRoleOnSite() {
59+
// Change site.
60+
switch_to_blog( self::$sub_site->blog_id );
61+
62+
// Confirm no role on current site.
63+
$super_admin = get_user_by( 'ID', self::$super_admin->ID );
64+
$this->assertEmpty( $super_admin->roles );
65+
66+
$factory = self::factory()->post;
67+
68+
// Attributed to Super Admin, owned by Admin.
69+
$post = $factory->create_and_get( [
70+
'post_author' => self::$users['admin']->ID,
71+
POSTS_PARAM => [
72+
self::$super_admin->ID,
73+
],
74+
] );
75+
76+
// Check super admin ID is stored.
77+
$author_ids = \Authorship\get_author_ids( $post );
78+
$this->assertSame( [ self::$super_admin->ID ], $author_ids );
79+
80+
$author_url = get_author_posts_url( self::$super_admin->ID );
81+
$this->assertTrue( strpos( $author_url, '/subsite/' ) !== false );
82+
$this->go_to( $author_url );
83+
84+
/** @var \WP_Query */
85+
global $wp_query, $authordata;
86+
87+
$this->assertQueryTrue( 'is_author', 'is_archive' );
88+
$this->assertTrue( is_author( self::$super_admin->ID ) );
89+
$this->assertSame( [ $post->ID ], wp_list_pluck( $wp_query->posts, 'ID' ) );
90+
$this->assertSame( self::$super_admin->ID, $authordata->ID );
91+
92+
restore_current_blog();
93+
}
94+
95+
}

0 commit comments

Comments
 (0)