Multisite: Replace is_super_admin()
with manage_network
in get_dashboard_url()
.
Unit tests for `get_dashboard_url()` have been added. Props iaaxpage. Fixes #39065. See #37616. git-svn-id: https://develop.svn.wordpress.org/trunk@39589 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
539b85406d
commit
b4317ea053
@ -3472,13 +3472,13 @@ function get_dashboard_url( $user_id = 0, $path = '', $scheme = 'admin' ) {
|
||||
$user_id = $user_id ? (int) $user_id : get_current_user_id();
|
||||
|
||||
$blogs = get_blogs_of_user( $user_id );
|
||||
if ( ! is_super_admin() && empty($blogs) ) {
|
||||
if ( is_multisite() && ! user_can( $user_id, 'manage_network' ) && empty($blogs) ) {
|
||||
$url = user_admin_url( $path, $scheme );
|
||||
} elseif ( ! is_multisite() ) {
|
||||
$url = admin_url( $path, $scheme );
|
||||
} else {
|
||||
$current_blog = get_current_blog_id();
|
||||
if ( $current_blog && ( is_super_admin( $user_id ) || in_array( $current_blog, array_keys( $blogs ) ) ) ) {
|
||||
if ( $current_blog && ( user_can( $user_id, 'manage_network' ) || in_array( $current_blog, array_keys( $blogs ) ) ) ) {
|
||||
$url = admin_url( $path, $scheme );
|
||||
} else {
|
||||
$active = get_active_blog_for_user( $user_id );
|
||||
|
77
tests/phpunit/tests/link/getDashboardUrl.php
Normal file
77
tests/phpunit/tests/link/getDashboardUrl.php
Normal file
@ -0,0 +1,77 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @group link
|
||||
*/
|
||||
class Tests_Link_GetDashboardUrl extends WP_UnitTestCase {
|
||||
static $user_id = false;
|
||||
|
||||
public static function wpSetUpBeforeClass( $factory ) {
|
||||
self::$user_id = $factory->user->create( array( 'role' => 'administrator' ) );
|
||||
}
|
||||
|
||||
public static function wpTearDownAfterClass() {
|
||||
wpmu_delete_user( self::$user_id );
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 39065
|
||||
*/
|
||||
public function test_get_dashboard_url_for_current_site_user() {
|
||||
$this->assertEquals( admin_url(), get_dashboard_url( self::$user_id ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 39065
|
||||
*/
|
||||
public function test_get_dashboard_url_for_user_with_no_sites() {
|
||||
add_filter( 'get_blogs_of_user', '__return_empty_array' );
|
||||
|
||||
$expected = is_multisite() ? user_admin_url() : admin_url();
|
||||
|
||||
$this->assertEquals( $expected, get_dashboard_url( self::$user_id ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 39065
|
||||
*/
|
||||
public function test_get_dashboard_url_for_network_administrator_with_no_sites() {
|
||||
if ( ! is_multisite() ) {
|
||||
$this->markTestSkipped( 'Test only runs in multisite.' );
|
||||
}
|
||||
|
||||
grant_super_admin( self::$user_id );
|
||||
|
||||
add_filter( 'get_blogs_of_user', '__return_empty_array' );
|
||||
|
||||
$expected = admin_url();
|
||||
$result = get_dashboard_url( self::$user_id );
|
||||
|
||||
revoke_super_admin( self::$user_id );
|
||||
|
||||
$this->assertEquals( $expected, $result );
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 39065
|
||||
*/
|
||||
public function test_get_dashboard_url_for_administrator_of_different_site() {
|
||||
if ( ! is_multisite() ) {
|
||||
$this->markTestSkipped( 'Test only runs in multisite.' );
|
||||
}
|
||||
|
||||
$site_id = self::factory()->blog->create( array( 'user_id' => self::$user_id ) );
|
||||
|
||||
remove_user_from_blog( self::$user_id, get_current_blog_id() );
|
||||
|
||||
$expected = get_admin_url( $site_id );
|
||||
$result = get_dashboard_url( self::$user_id );
|
||||
|
||||
remove_user_from_blog( self::$user_id, $site_id );
|
||||
add_user_to_blog( get_current_blog_id(), self::$user_id, 'administrator');
|
||||
|
||||
wpmu_delete_blog( $site_id, true );
|
||||
|
||||
$this->assertEquals( $expected, $result );
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user