Skip to content

Commit

Permalink
Merge pull request #106 from humanmade/show-all-authors
Browse files Browse the repository at this point in the history
Show all users in post author column.
  • Loading branch information
roborourke authored Aug 18, 2022
2 parents b9f2439 + c271235 commit ad162b1
Show file tree
Hide file tree
Showing 3 changed files with 101 additions and 0 deletions.
2 changes: 2 additions & 0 deletions inc/namespace.php
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,8 @@ function validate_authors( $authors, WP_REST_Request $request, string $param, st

/** @var WP_User[] */
$users = get_users( [
// Check all sites.
'blog_id' => 0,
'include' => $authors,
'orderby' => 'include',
] );
Expand Down
4 changes: 4 additions & 0 deletions inc/template.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ function get_authors( WP_Post $post ) : array {

/** @var WP_User[] */
$users = get_users( [
// Check all sites.
'blog_id' => 0,
'include' => $author_ids,
'orderby' => 'include',
] );
Expand Down Expand Up @@ -155,6 +157,8 @@ function set_authors( WP_Post $post, array $authors ) : array {

/** @var WP_User[] */
$users = get_users( [
// Check all sites.
'blog_id' => 0,
'include' => $authors,
'orderby' => 'include',
] );
Expand Down
95 changes: 95 additions & 0 deletions tests/phpunit/test-multisite.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
<?php
/**
* Multisite tests for the plugin.
*
* @package authorship
*/

declare( strict_types=1 );

namespace Authorship\Tests;

use const Authorship\POSTS_PARAM;

/**
* @group ms-required
*/
class TestMultisite extends TestCase {
/**
* Super admin.
*
* @var \WP_User
*/
protected static $super_admin;

/**
* Sub site.
*
* @var \WP_Site
*/
protected static $sub_site;

/**
* Set up class test fixtures.
*
* @param \WP_UnitTest_Factory $factory Test factory.
*/
public static function wpSetUpBeforeClass( \WP_UnitTest_Factory $factory ) {
parent::wpSetUpBeforeClass( $factory );

// Create a super admin user.
self::$super_admin = $factory->user->create_and_get( [
'role' => 'administrator',
'display_name' => 'Super Admin',
'user_email' => '[email protected]',
] );

grant_super_admin( self::$super_admin->ID );

// Create a subsite.
self::$sub_site = $factory->blog->create_and_get( [
'domain' => 'example.org',
'path' => '/subsite',
'title' => 'Authorship Sub Site',
'user_id' => self::$users['admin']->ID,
] );
}

public function testSuperAdminWithNoRoleOnSite() {
// Change site.
switch_to_blog( self::$sub_site->blog_id );

// Confirm no role on current site.
$super_admin = get_user_by( 'ID', self::$super_admin->ID );
$this->assertEmpty( $super_admin->roles );

$factory = self::factory()->post;

// Attributed to Super Admin, owned by Admin.
$post = $factory->create_and_get( [
'post_author' => self::$users['admin']->ID,
POSTS_PARAM => [
self::$super_admin->ID,
],
] );

// Check super admin ID is stored.
$author_ids = \Authorship\get_author_ids( $post );
$this->assertSame( [ self::$super_admin->ID ], $author_ids );

$author_url = get_author_posts_url( self::$super_admin->ID );
$this->assertTrue( strpos( $author_url, '/subsite/' ) !== false );
$this->go_to( $author_url );

/** @var \WP_Query */
global $wp_query, $authordata;

$this->assertQueryTrue( 'is_author', 'is_archive' );
$this->assertTrue( is_author( self::$super_admin->ID ) );
$this->assertSame( [ $post->ID ], wp_list_pluck( $wp_query->posts, 'ID' ) );
$this->assertSame( self::$super_admin->ID, $authordata->ID );

restore_current_blog();
}

}

0 comments on commit ad162b1

Please sign in to comment.