Make WordPress Core


Ignore:
Timestamp:
03/14/2026 07:53:29 AM (5 months ago)
Author:
audrasjb
Message:

Toolbar: add CSS from admin color scheme on front-end.

This changeset introduces the wp_admin_bar_add_color_scheme_to_front_end() which is hooked on admin_bar_init in order to use the CSS from admin color schemes on the admin bar on front-end, as inline styles.

Props sabernhardt, huzaifaalmesbah, audrasjb, johnbillion, noruzzaman, JeffPaul, joedolson, huzaifaalmesbah, amesplant, r1k0, shailu25.
Fixes #64762.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/admin-bar.php

    r61979 r62025  
    14381438        return 'true' === $pref;
    14391439}
     1440
     1441/**
     1442 * Adds CSS from the administration color scheme stylesheet on the front end.
     1443 *
     1444 * @since 7.0.0
     1445 *
     1446 * @global array $_wp_admin_css_colors Registered administration color schemes.
     1447 */
     1448function wp_admin_bar_add_color_scheme_to_front_end() {
     1449        if ( is_admin() ) {
     1450                return;
     1451        }
     1452
     1453        global $_wp_admin_css_colors;
     1454
     1455        if ( empty( $_wp_admin_css_colors ) ) {
     1456                register_admin_color_schemes();
     1457        }
     1458
     1459        $color_scheme = get_user_option( 'admin_color' );
     1460
     1461        if ( empty( $color_scheme ) || ! isset( $_wp_admin_css_colors[ $color_scheme ] ) ) {
     1462                $color_scheme = 'modern';
     1463        }
     1464
     1465        $color = $_wp_admin_css_colors[ $color_scheme ] ?? null;
     1466        $url   = $color->url ?? '';
     1467
     1468        if ( $url ) {
     1469                $response = wp_remote_get( $url );
     1470                if ( ! is_wp_error( $response ) ) {
     1471                        $css = $response['body'];
     1472                        if ( is_string( $css ) && str_contains( $css, '#wpadminbar' ) ) {
     1473                                $start_position = strpos( $css, '#wpadminbar' );
     1474                                $end_position   = strpos( $css, '.wp-pointer' );
     1475                                if ( false !== $end_position && $end_position > $start_position ) {
     1476                                        $css = substr( $css, $start_position, $end_position - $start_position );
     1477                                        if ( SCRIPT_DEBUG ) {
     1478                                                $css = str_replace( '/* Pointers */', '', $css );
     1479                                        }
     1480                                }
     1481                                wp_add_inline_style( 'admin-bar', $css );
     1482                        }
     1483                }
     1484        }
     1485}
Note: See TracChangeset for help on using the changeset viewer.