Make WordPress Core

Ticket #39065: 39065.diff

File 39065.diff, 3.1 KB (added by flixos90, 8 years ago)
  • src/wp-includes/link-template.php

     
    34723472        $user_id = $user_id ? (int) $user_id : get_current_user_id();
    34733473
    34743474        $blogs = get_blogs_of_user( $user_id );
    3475         if ( ! is_super_admin() && empty($blogs) ) {
     3475        if ( is_multisite() && ! user_can( $user_id, 'manage_network' ) && empty($blogs) ) {
    34763476                $url = user_admin_url( $path, $scheme );
    34773477        } elseif ( ! is_multisite() ) {
    34783478                $url = admin_url( $path, $scheme );
    34793479        } else {
    34803480                $current_blog = get_current_blog_id();
    3481                 if ( $current_blog  && ( is_super_admin( $user_id ) || in_array( $current_blog, array_keys( $blogs ) ) ) ) {
     3481                if ( $current_blog  && ( user_can( $user_id, 'manage_network' ) || in_array( $current_blog, array_keys( $blogs ) ) ) ) {
    34823482                        $url = admin_url( $path, $scheme );
    34833483                } else {
    34843484                        $active = get_active_blog_for_user( $user_id );
  • tests/phpunit/tests/link/getDashboardUrl.php

     
     1<?php
     2
     3/**
     4 * @group link
     5 */
     6class Tests_Link_GetDashboardUrl extends WP_UnitTestCase {
     7
     8        /**
     9         * @ticket 39065
     10         */
     11        public function test_get_dashboard_url_for_current_site_user() {
     12                $user_id = self::factory()->user->create();
     13
     14                $this->assertEquals( admin_url(), get_dashboard_url( $user_id ) );
     15        }
     16
     17        /**
     18         * @ticket 39065
     19         */
     20        public function test_get_dashboard_url_for_user_with_no_sites() {
     21                $user_id = self::factory()->user->create();
     22
     23                add_filter( 'get_blogs_of_user', '__return_empty_array' );
     24
     25                $expected = is_multisite() ? user_admin_url() : admin_url();
     26
     27                $this->assertEquals( $expected, get_dashboard_url( $user_id ) );
     28        }
     29
     30        /**
     31         * @ticket 39065
     32         */
     33        public function test_get_dashboard_url_for_network_administrator_with_no_sites() {
     34                if ( ! is_multisite() ) {
     35                        $this->markTestSkipped( 'Test only runs in multisite.' );
     36                }
     37
     38                $user_id = self::factory()->user->create( array( 'role' => 'administrator' ) );
     39                grant_super_admin( $user_id );
     40
     41                add_filter( 'get_blogs_of_user', '__return_empty_array' );
     42
     43                $this->assertEquals( admin_url(), get_dashboard_url( $user_id ) );
     44        }
     45
     46        /**
     47         * @ticket 39065
     48         */
     49        public function test_get_dashboard_url_for_administrator_of_different_site() {
     50                if ( ! is_multisite() ) {
     51                        $this->markTestSkipped( 'Test only runs in multisite.' );
     52                }
     53
     54                $user_id = self::factory()->user->create( array( 'role' => 'administrator' ) );
     55                remove_user_from_blog( $user_id, get_current_blog_id() );
     56
     57                $site_id = self::factory()->blog->create( array( 'user_id' => $user_id ) );
     58
     59                $this->assertEquals( get_admin_url( $site_id ), get_dashboard_url( $user_id ) );
     60        }
     61}