[wp-trac] [WordPress Trac] #20082: Admin bar links to wrong site in multisite (subdomain) network

WordPress Trac noreply at wordpress.org
Wed Oct 7 09:56:53 UTC 2015


#20082: Admin bar links to wrong site in multisite (subdomain) network
--------------------------+------------------------
 Reporter:  niklasbr      |       Owner:
     Type:  defect (bug)  |      Status:  reopened
 Priority:  normal        |   Milestone:
Component:  Toolbar       |     Version:
 Severity:  normal        |  Resolution:
 Keywords:                |     Focuses:  multisite
--------------------------+------------------------
Changes (by LewisCowles):

 * status:  closed => reopened
 * resolution:  invalid =>


Comment:

 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"
 }
 }}}

--
Ticket URL: <https://core.trac.wordpress.org/ticket/20082#comment:11>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list