Make WordPress Core

Ticket #39065: 39065.2.diff

File 39065.2.diff, 3.5 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        static $user_id = false;
     8
     9        public static function wpSetUpBeforeClass( $factory ) {
     10                self::$user_id = $factory->user->create( array( 'role' => 'administrator' ) );
     11        }
     12
     13        public static function wpTearDownAfterClass() {
     14                wpmu_delete_user( self::$user_id );
     15
     16                global $wp_rewrite;
     17                $wp_rewrite->init();
     18        }
     19
     20        /**
     21         * @ticket 39065
     22         */
     23        public function test_get_dashboard_url_for_current_site_user() {
     24                $this->assertEquals( admin_url(), get_dashboard_url( self::$user_id ) );
     25        }
     26
     27        /**
     28         * @ticket 39065
     29         */
     30        public function test_get_dashboard_url_for_user_with_no_sites() {
     31                add_filter( 'get_blogs_of_user', '__return_empty_array' );
     32
     33                $expected = is_multisite() ? user_admin_url() : admin_url();
     34
     35                $this->assertEquals( $expected, get_dashboard_url( self::$user_id ) );
     36        }
     37
     38        /**
     39         * @ticket 39065
     40         */
     41        public function test_get_dashboard_url_for_network_administrator_with_no_sites() {
     42                if ( ! is_multisite() ) {
     43                        $this->markTestSkipped( 'Test only runs in multisite.' );
     44                }
     45
     46                grant_super_admin( self::$user_id );
     47
     48                add_filter( 'get_blogs_of_user', '__return_empty_array' );
     49
     50                $expected = admin_url();
     51                $result = get_dashboard_url( self::$user_id );
     52
     53                revoke_super_admin( self::$user_id );
     54
     55                $this->assertEquals( $expected, $result );
     56        }
     57
     58        /**
     59         * @ticket 39065
     60         */
     61        public function test_get_dashboard_url_for_administrator_of_different_site() {
     62                if ( ! is_multisite() ) {
     63                        $this->markTestSkipped( 'Test only runs in multisite.' );
     64                }
     65
     66                $site_id = self::factory()->blog->create( array( 'user_id' => self::$user_id ) );
     67
     68                remove_user_from_blog( self::$user_id, get_current_blog_id() );
     69
     70                $expected = get_admin_url( $site_id );
     71                $result = get_dashboard_url( self::$user_id );
     72
     73                remove_user_from_blog( self::$user_id, $site_id );
     74                add_user_to_blog( get_current_blog_id(), self::$user_id, 'administrator');
     75
     76                wpmu_delete_blog( $site_id, true );
     77
     78                $this->assertEquals( $expected, $result );
     79        }
     80}