[wp-trac] [WordPress Trac] #43963: Add admin body class for multisite blog ID and network admin context

WordPress Trac noreply at wordpress.org
Fri May 4 16:58:17 UTC 2018


#43963: Add admin body class for multisite blog ID and network admin context
---------------------------------------+-----------------------------
 Reporter:  dryanpress                 |      Owner:  (none)
     Type:  enhancement                |     Status:  new
 Priority:  normal                     |  Milestone:  Awaiting Review
Component:  Administration             |    Version:
 Severity:  minor                      |   Keywords:
  Focuses:  administration, multisite  |
---------------------------------------+-----------------------------
 In multisite, it'd be great to have an admin body class to safely scope
 CSS to specific blogs (i.e. `blog-2` or `network-admin`) available by
 default. I often filter `admin_body_class` to add these.

 One situation where I often use this is conditional override of the text
 Site Title in the Admin Bar with a logo -- but only if the logo exists.
 PHP can certainly be used to check context before printing conditional
 CSS, but the body class adds a safe, client-side scope and clear approach
 for avoiding in-admin style collisions.

 Example:

 {{{
 if ( ! empty( $logo ) ) {
         ?>
         body.blog-<?php echo esc_attr( $site_id ); ?> li#wp-admin-bar-
 site-name > a.ab-item:first-of-type,
         body.blog-<?php echo esc_attr( $site_id ); ?> #wpadminbar .ab-top-
 menu > li#wp-admin-bar-site-name.menupop:hover > .ab-item:first-of-type,
         body.blog-<?php echo esc_attr( $site_id ); ?> #wpadminbar .ab-top-
 menu > li#wp-admin-bar-site-name.menupop.hover > .ab-item:first-of-type {
                 font-size: 0; // safely hide default text
                 background-image: url("<?php echo esc_url( $logo ); ?>");
                 background-size: <?php echo esc_html( $logo_width ); ?>;
                 background-position: center;
                 background-repeat: no-repeat;
                 min-width: 120px;
         }
         <?php
 }
 }}}

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/43963>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list