Make WordPress Core

Opened 13 years ago

Closed 10 years ago

#20082 closed defect (bug) (invalid)

Admin bar links to wrong site in multisite (subdomain) network

Reported by: niklasbr's profile niklasbr Owned by:
Milestone: Priority: normal
Severity: normal Version:
Component: Toolbar Keywords:
Focuses: multisite Cc:

Description (last modified by dd32)

The code

	foreach ( $actions as $link => $action ) {
		list( $title, $id ) = $action;

		$wp_admin_bar->add_menu( array(
			'parent'    => 'new-content',
			'id'        => $id,
			'title'     => $title,
			'href'      => admin_url( $link )
		) );
	}

generates the wrong URL, whenever I visit a site that has the URL subsite.subsite.example.com but generates the correct URL if the URL is of the pattern subsite.example.com. On subsite.subsite.example.com the admin bar will generate links to subsite.example.com.

Attachments (1)

Skärmavbild 2012-02-20 kl. 10.39.48.png (66.5 KB) - added by niklasbr 13 years ago.
Wrong URL generated

Download all attachments as: .zip

Change History (13)

@niklasbr
13 years ago

Wrong URL generated

#1 follow-up: @solarissmoke
13 years ago

  • Keywords reporter-feedback added

Which link is wrong? The one highlighted in blue has the form a.b.domain.tld which looks correct?

#2 @dd32
13 years ago

  • Description modified (diff)

#3 in reply to: ↑ 1 @niklasbr
13 years ago

  • Keywords reporter-feedback removed

Replying to solarissmoke:

Which link is wrong? The one highlighted in blue has the form a.b.domain.tld which looks correct?

The admin-bar.js script is being loaded from the correct url (which is also the URL being visited) but the links in the admin bar goes to a different site (the blue highlight).

#4 @jeremyfelt
11 years ago

  • Component changed from Administration to Permalinks
  • Focuses multisite added

#5 @jeremyfelt
11 years ago

  • Milestone Awaiting Review deleted
  • Resolution set to worksforme
  • Severity changed from major to normal
  • Status changed from new to closed

I'm not able to reproduce the reported issue in either WordPress 3.3.1 or 3.9. When I switch between subsites on a subdomain network, the URLs in the wp-admin-bar-new-content area all generate correctly. From the screenshot provided, it appears that something else may be adding another link to media-new.php and that is being generated incorrectly.

I'm going to close this out as worksforme. Please feel free to reopen with an example of how to reproduce.

#6 @niklasbr
11 years ago

  • Resolution worksforme deleted
  • Status changed from closed to reopened

#7 @SergeyBiryukov
11 years ago

  • Milestone set to Awaiting Review

#8 @SergeyBiryukov
11 years ago

  • Component changed from Permalinks to Toolbar

#9 @boonebgorges
11 years ago

I can't reproduce this on a default subdomain setup.

The mention of URLs like "subsite.subsite.example.com" makes me wonder if your setup might not be default. What is the URL of the root WP network? Is it subsite.example.com (goteborg.kfum.se) or example.com (kfum.se)? If it's the latter, how are you managing to get a URL like subsite.subsite.example.com? Are you using a custom sunrise.php file or some plugin that enables this kind of subdomain nesting?

#10 @jeremyfelt
10 years ago

  • Milestone Awaiting Review deleted
  • Resolution set to invalid
  • Status changed from reopened to closed
  • Version 3.3.1 deleted

I'm going to close this out as invalid as we're unable to reproduce the issue. Please re-open if necessary.

#11 @LewisCowles
10 years ago

  • Resolution invalid deleted
  • Status changed from closed to reopened

I am getting the wrong link for sub-path multi-site, so I am unsure if this is related...

I will try installing multi-site without any site data in a new vagrant to see if that helps reproduce...

The issue seems not to affect the home_url method, only admin_url.

The core code producing incorrect output is from wp-includes/admin-bar.php (Lines: 430-483)

	foreach ( (array) $wp_admin_bar->user->blogs as $blog ) {
		switch_to_blog( $blog->userblog_id );

		$blavatar = '<div class="blavatar"></div>';

		$blogname = $blog->blogname;

		if ( ! $blogname ) {
			$blogname = preg_replace( '#^(https?://)?(www.)?#', '', get_home_url() );
		}

		$menu_id  = 'blog-' . $blog->userblog_id;

		$wp_admin_bar->add_menu( array(
			'parent'    => 'my-sites-list',
			'id'        => $menu_id,
			'title'     => $blavatar . $blogname,
			'href'      => admin_url(),
		) );

		$wp_admin_bar->add_menu( array(
			'parent' => $menu_id,
			'id'     => $menu_id . '-d',
			'title'  => __( 'Dashboard' ),
			'href'   => admin_url(),
		) );

		if ( current_user_can( get_post_type_object( 'post' )->cap->create_posts ) ) {
			$wp_admin_bar->add_menu( array(
				'parent' => $menu_id,
				'id'     => $menu_id . '-n',
				'title'  => __( 'New Post' ),
				'href'   => admin_url( 'post-new.php' ),
			) );
		}

		if ( current_user_can( 'edit_posts' ) ) {
			$wp_admin_bar->add_menu( array(
				'parent' => $menu_id,
				'id'     => $menu_id . '-c',
				'title'  => __( 'Manage Comments' ),
				'href'   => admin_url( 'edit-comments.php' ),
			) );
		}

		$wp_admin_bar->add_menu( array(
			'parent' => $menu_id,
			'id'     => $menu_id . '-v',
			'title'  => __( 'Visit Site' ),
			'href'   => home_url( '/' ),
		) );

		restore_current_blog();
	}

as mentioned home_url works. Both home_url & admin_url seem to alias other methods, which I have taken the time to hook using filters so I can see the output (we know the input from var_dumping the $blog). I am unsure why this is not working, as it looks like the siteurl and path are both available...

object(stdClass)#8917 (10) { 
  ["userblog_id"]=> int(1) 
  ["blogname"]=> string(45) "Site *Main*" 
  ["domain"]=> string(9) "10.0.0.42" 
  ["path"]=> string(1) "/" 
  ["site_id"]=> string(1) "1" 
  ["siteurl"]=> string(16) "http://10.0.0.42" 
  ["archived"]=> string(1) "0" 
  ["mature"]=> string(1) "0" 
  ["spam"]=> string(1) "0" 
  ["deleted"]=> string(1) "0" 
} 
object(stdClass)#8916 (10) { 
  ["userblog_id"]=> int(4) 
  ["blogname"]=> string(32) "Site - UK" 
  ["domain"]=> string(9) "10.0.0.42" 
  ["path"]=> string(4) "/uk/" 
  ["site_id"]=> string(1) "1" 
  ["siteurl"]=> string(16) "http://10.0.0.42" 
  ["archived"]=> string(1) "0" 
  ["mature"]=> string(1) "0" 
  ["spam"]=> string(1) "0" 
  ["deleted"]=> string(1) "0" 
} 
object(stdClass)#8918 (10) { 
  ["userblog_id"]=> int(5) 
  ["blogname"]=> string(24) "Site - Germany" 
  ["domain"]=> string(9) "10.0.0.42" 
  ["path"]=> string(4) "/de/" 
  ["site_id"]=> string(1) "1" 
  ["siteurl"]=> string(16) "http://10.0.0.42" 
  ["archived"]=> string(1) "0" 
  ["mature"]=> string(1) "0" 
  ["spam"]=> string(1) "0" 
  ["deleted"]=> string(1) "0" 
}

#12 @LewisCowles
10 years ago

  • Resolution set to invalid
  • Status changed from reopened to closed

Looks like it's a problem with 'siteurl' option value. Updated that and all problems are gone...

Note: See TracTickets for help on using tickets.