Skip to content

Commit 5e7fd3f

Browse files
committed
Toolbar: Revert add CSS from admin color scheme on front-end.
The implementation issues a server-side HTTP request on every front-end page load and extracts the toolbar CSS via fragile substring matching. Alternatives are too large to land this late in the release cycle, so the fix is deferred to a future release. Reverts [62025]. Props desrosj, jorbin, mukesh27, sabernhardt, wildworks. See #64762. git-svn-id: https://develop.svn.wordpress.org/trunk@62349 602fd350-edb4-49c9-b593-d223f7449a82
1 parent 8b45167 commit 5e7fd3f

3 files changed

Lines changed: 2 additions & 54 deletions

File tree

src/wp-includes/admin-bar.php

Lines changed: 0 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1466,49 +1466,3 @@ function _get_admin_bar_pref( $context = 'front', $user = 0 ) {
14661466

14671467
return 'true' === $pref;
14681468
}
1469-
1470-
/**
1471-
* Adds CSS from the administration color scheme stylesheet on the front end.
1472-
*
1473-
* @since 7.0.0
1474-
*
1475-
* @global array $_wp_admin_css_colors Registered administration color schemes.
1476-
*/
1477-
function wp_admin_bar_add_color_scheme_to_front_end() {
1478-
if ( is_admin() ) {
1479-
return;
1480-
}
1481-
1482-
global $_wp_admin_css_colors;
1483-
1484-
if ( empty( $_wp_admin_css_colors ) ) {
1485-
register_admin_color_schemes();
1486-
}
1487-
1488-
$color_scheme = get_user_option( 'admin_color' );
1489-
1490-
if ( empty( $color_scheme ) || ! isset( $_wp_admin_css_colors[ $color_scheme ] ) ) {
1491-
$color_scheme = 'modern';
1492-
}
1493-
1494-
$color = $_wp_admin_css_colors[ $color_scheme ] ?? null;
1495-
$url = $color->url ?? '';
1496-
1497-
if ( $url ) {
1498-
$response = wp_remote_get( $url );
1499-
if ( ! is_wp_error( $response ) ) {
1500-
$css = $response['body'];
1501-
if ( is_string( $css ) && str_contains( $css, '#wpadminbar' ) ) {
1502-
$start_position = strpos( $css, '#wpadminbar' );
1503-
$end_position = strpos( $css, '.wp-pointer' );
1504-
if ( false !== $end_position && $end_position > $start_position ) {
1505-
$css = substr( $css, $start_position, $end_position - $start_position );
1506-
if ( SCRIPT_DEBUG ) {
1507-
$css = str_replace( '/* Pointers */', '', $css );
1508-
}
1509-
}
1510-
wp_add_inline_style( 'admin-bar', $css );
1511-
}
1512-
}
1513-
}
1514-
}

src/wp-includes/default-filters.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -700,7 +700,6 @@
700700
add_action( 'wp_body_open', 'wp_admin_bar_render', 0 );
701701
add_action( 'wp_footer', 'wp_admin_bar_render', 1000 ); // Back-compat for themes not using `wp_body_open`.
702702
add_action( 'in_admin_header', 'wp_admin_bar_render', 0 );
703-
add_action( 'admin_bar_init', 'wp_admin_bar_add_color_scheme_to_front_end', 0 );
704703

705704
// Former admin filters that can also be hooked on the front end.
706705
add_action( 'media_buttons', 'media_buttons' );

tests/phpunit/tests/dependencies/wpStyleLoaderSrc.php

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,20 +12,15 @@ class Tests_Dependencies_wpStyleLoaderSrc extends WP_UnitTestCase {
1212

1313
/**
1414
* Tests that PHP warnings are not thrown when wp_style_loader_src() is called
15-
* before the `$_wp_admin_css_colors` global is set within the admin.
15+
* before the `$_wp_admin_css_colors` global is set.
1616
*
1717
* The warnings that we should not see:
1818
* `Warning: Trying to access array offset on null`.
1919
* `Warning: Attempt to read property "url" on null`.
2020
*
2121
* @ticket 61302
22-
* @ticket 64762
2322
*/
2423
public function test_without_wp_admin_css_colors_global() {
25-
if ( is_admin() ) {
26-
$this->assertFalse( wp_style_loader_src( '', 'colors' ) );
27-
} else {
28-
$this->assertStringContainsString( '/colors.css', wp_style_loader_src( '', 'colors' ) );
29-
}
24+
$this->assertFalse( wp_style_loader_src( '', 'colors' ) );
3025
}
3126
}

0 commit comments

Comments
 (0)