Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use inline styles. #4824

Closed
wants to merge 36 commits into from
Closed
Show file tree
Hide file tree
Changes from 28 commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
fad2631
Use inline styles.
spacedmonkey Jul 10, 2023
a768486
Use inline styles for admin bar.
spacedmonkey Jul 10, 2023
0f4f4af
Merge branch 'trunk' into fix/inline-styles
spacedmonkey Sep 8, 2023
96b225e
Remove inline styles
spacedmonkey Sep 8, 2023
be4867c
Change custom background as well.
spacedmonkey Sep 8, 2023
9be777c
Tweek action proity.
spacedmonkey Sep 8, 2023
4e67c1d
Add spaces.
spacedmonkey Sep 8, 2023
d02a47a
Change selector.
spacedmonkey Sep 8, 2023
68e9d17
Apply suggestions from code review
spacedmonkey Sep 11, 2023
8ea7c2c
Change formatting.
spacedmonkey Sep 11, 2023
89ddbfc
Merge branch 'trunk' into fix/inline-styles
spacedmonkey Sep 12, 2023
ff00df3
Revert some of the changes.
spacedmonkey Sep 12, 2023
c89bed2
Another approach.
spacedmonkey Sep 12, 2023
8fd1ec8
Depreacte functions.
spacedmonkey Sep 13, 2023
3dbd386
More depreacte functions.
spacedmonkey Sep 13, 2023
05b09c3
Remove filters to fix tests.
spacedmonkey Sep 13, 2023
b35cd2e
Apply suggestions from code review
spacedmonkey Sep 19, 2023
ee514b2
Merge branch 'trunk' into fix/inline-styles
spacedmonkey Sep 19, 2023
988b3bd
Change function names.
spacedmonkey Sep 19, 2023
db6733f
Feedback.
spacedmonkey Sep 19, 2023
ab32c36
Add some comments.
spacedmonkey Sep 19, 2023
c7e7815
Add deprecated comments.
spacedmonkey Sep 19, 2023
21cbfb7
Formatting.
spacedmonkey Sep 19, 2023
40bcb76
Comment.
spacedmonkey Sep 19, 2023
96270b0
Merge branch 'trunk' into fix/inline-styles
spacedmonkey Sep 19, 2023
56640f3
Fix lints.
spacedmonkey Sep 19, 2023
baa01b7
Change handle name.
spacedmonkey Sep 19, 2023
800fe53
Use `wp_add_inline_style` to be safe.
spacedmonkey Sep 19, 2023
77ca89a
Apply suggestions from code review
spacedmonkey Sep 21, 2023
95d3f9a
Support custom callbacks.
spacedmonkey Sep 21, 2023
3982bd9
Apply suggestions from code review
spacedmonkey Sep 21, 2023
7732aaa
Apply suggestions from code review
spacedmonkey Sep 21, 2023
91c0d51
Apply suggestions from code review
spacedmonkey Sep 21, 2023
9fdc0f1
Merge branch 'trunk' into fix/inline-styles
spacedmonkey Sep 25, 2023
5b8bc3c
Remove IDE hints.
spacedmonkey Sep 25, 2023
6dffef3
Merge branch 'trunk' into fix/inline-styles
spacedmonkey Sep 25, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/wp-admin/includes/admin-filters.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@
add_action( 'admin_print_scripts', 'print_emoji_detection_script' );
add_action( 'admin_print_scripts', 'print_head_scripts', 20 );
add_action( 'admin_print_footer_scripts', '_wp_footer_scripts' );
add_action( 'admin_print_styles', 'print_emoji_styles' );
add_action( 'admin_enqueue_scripts', 'wp_enqueue_emoji_styles' );
add_action( 'admin_print_styles', 'print_emoji_styles' ); // Retained for backwards-compatibility. Unhooked by wp_enqueue_emoji_styles().
add_action( 'admin_print_styles', 'print_admin_styles', 20 );

add_action( 'admin_print_scripts-index.php', 'wp_localize_community_events' );
Expand Down
40 changes: 22 additions & 18 deletions src/wp-includes/admin-bar.php
Original file line number Diff line number Diff line change
Expand Up @@ -1224,33 +1224,37 @@ function wp_admin_bar_add_secondary_groups( $wp_admin_bar ) {
);
}



/**
* Prints style and scripts for the admin bar.
* Remove the `wp_admin_bar_header` action and use `wp_add_inline_style` function to render inline styles.
spacedmonkey marked this conversation as resolved.
Show resolved Hide resolved
*
* @since 3.1.0
* @since 6.4.0
*/
function wp_admin_bar_header() {
$type_attr = current_theme_supports( 'html5', 'style' ) ? '' : ' type="text/css"';
?>
<style<?php echo $type_attr; ?> media="print">#wpadminbar { display:none; }</style>
<?php
function wp_enqueue_admin_bar_header_styles() {
$action = is_admin() ? 'admin_head' : 'wp_head';
spacedmonkey marked this conversation as resolved.
Show resolved Hide resolved
if ( ! has_action( $action, 'wp_admin_bar_header' ) ) {
return;
}
remove_action( $action, 'wp_admin_bar_header' );
wp_add_inline_style( 'admin-bar', /* language=CSS */ '@media print { #wpadminbar { display:none; } }' );
spacedmonkey marked this conversation as resolved.
Show resolved Hide resolved
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See #4773 (comment), I don't think we should have IDE specific annotations in core, unless they are a standard pattern supported by various IDEs.

}

/**
* Prints default admin bar callback.
* Remove the `wp_head` action and use `wp_add_inline_style` function to render inline styles.
spacedmonkey marked this conversation as resolved.
Show resolved Hide resolved
*
* @since 3.1.0
* @since 6.4.0
*/
function _admin_bar_bump_cb() {
$type_attr = current_theme_supports( 'html5', 'style' ) ? '' : ' type="text/css"';
?>
<style<?php echo $type_attr; ?> media="screen">
html { margin-top: 32px !important; }
@media screen and ( max-width: 782px ) {
html { margin-top: 46px !important; }
function wp_enqueue_admin_bar_bump_styles() {
spacedmonkey marked this conversation as resolved.
Show resolved Hide resolved
if ( ! has_action( 'wp_head', '_admin_bar_bump_cb' ) ) {
spacedmonkey marked this conversation as resolved.
Show resolved Hide resolved
return;
}
</style>
<?php
remove_action( 'wp_head', '_admin_bar_bump_cb' );
$css = /* language=CSS */ '
spacedmonkey marked this conversation as resolved.
Show resolved Hide resolved
@media screen { html { margin-top: 32px !important; } }
@media screen and ( max-width: 782px ) { html { margin-top: 46px !important; } }
';
wp_add_inline_style( 'admin-bar', $css );
}

/**
Expand Down
9 changes: 7 additions & 2 deletions src/wp-includes/default-filters.php
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,8 @@
add_action( 'start_previewing_theme', 'wp_clean_theme_json_cache' );
add_action( 'after_switch_theme', '_wp_menus_changed' );
add_action( 'after_switch_theme', '_wp_sidebars_changed' );
add_action( 'wp_print_styles', 'print_emoji_styles' );
add_action( 'wp_enqueue_scripts', 'wp_enqueue_emoji_styles' );
add_action( 'wp_print_styles', 'print_emoji_styles' ); // Retained for backwards-compatibility. Unhooked by wp_enqueue_emoji_styles().

if ( isset( $_GET['replytocom'] ) ) {
add_filter( 'wp_robots', 'wp_robots_no_robots' );
Expand Down Expand Up @@ -652,6 +653,9 @@
// Don't remove. Wrong way to disable.
add_action( 'template_redirect', '_wp_admin_bar_init', 0 );
add_action( 'admin_init', '_wp_admin_bar_init' );
add_action( 'wp_enqueue_scripts', 'wp_enqueue_admin_bar_bump_styles' );
add_action( 'wp_enqueue_scripts', 'wp_enqueue_admin_bar_header_styles' );
add_action( 'admin_enqueue_scripts', 'wp_enqueue_admin_bar_header_styles' );
add_action( 'before_signup_header', '_wp_admin_bar_init' );
add_action( 'activate_header', '_wp_admin_bar_init' );
add_action( 'wp_body_open', 'wp_admin_bar_render', 0 );
Expand All @@ -673,7 +677,8 @@

add_action( 'embed_head', 'enqueue_embed_scripts', 1 );
add_action( 'embed_head', 'print_emoji_detection_script' );
add_action( 'embed_head', 'print_embed_styles' );
add_action( 'embed_head', 'wp_enqueue_embed_styles', 9 );
add_action( 'embed_head', 'print_embed_styles' ); // Retained for backwards-compatibility. Unhooked by wp_enqueue_embed_styles().
add_action( 'embed_head', 'wp_print_head_scripts', 20 );
add_action( 'embed_head', 'wp_print_styles', 20 );
add_action( 'embed_head', 'wp_robots' );
Expand Down
86 changes: 86 additions & 0 deletions src/wp-includes/deprecated.php
Original file line number Diff line number Diff line change
Expand Up @@ -5870,3 +5870,89 @@ function _wp_theme_json_webfonts_handler() {
add_action( 'wp_enqueue_scripts', $fn_generate_and_enqueue_styles );
add_action( 'admin_init', $fn_generate_and_enqueue_editor_styles );
}

/**
* Prints the CSS in the embed iframe header.
*
* @since 4.4.0
spacedmonkey marked this conversation as resolved.
Show resolved Hide resolved
* @deprecated 6.4.0 Use wp_enqueue_embed_styles() instead.
*/
function print_embed_styles() {
_deprecated_function( __FUNCTION__, '6.4.0', 'wp_enqueue_embed_styles' );

$type_attr = current_theme_supports( 'html5', 'style' ) ? '' : ' type="text/css"';
$suffix = SCRIPT_DEBUG ? '' : '.min';
?>
<style<?php echo $type_attr; ?>>
<?php echo file_get_contents( ABSPATH . WPINC . "/css/wp-embed-template$suffix.css" ); ?>
</style>
<?php
}

/**
* Prints the important emoji-related styles.
*
* @since 4.2.0
* @deprecated 6.4.0 Use wp_enqueue_emoji_styles() instead.
*/
function print_emoji_styles() {
_deprecated_function( __FUNCTION__, '6.4.0', 'wp_enqueue_emoji_styles' );
static $printed = false;

if ( $printed ) {
return;
}

$printed = true;

$type_attr = current_theme_supports( 'html5', 'style' ) ? '' : ' type="text/css"';
?>
<style<?php echo $type_attr; ?>>
img.wp-smiley,
img.emoji {
display: inline !important;
border: none !important;
box-shadow: none !important;
height: 1em !important;
width: 1em !important;
margin: 0 0.07em !important;
vertical-align: -0.1em !important;
background: none !important;
padding: 0 !important;
}
</style>
<?php
}

/**
* Prints style and scripts for the admin bar.
*
* @since 3.1.0
* @deprecated 6.4.0 Use wp_enqueue_admin_bar_header_styles() instead.
*/
function wp_admin_bar_header() {
_deprecated_function( __FUNCTION__, '6.4.0', 'wp_enqueue_admin_bar_header_styles' );
$type_attr = current_theme_supports( 'html5', 'style' ) ? '' : ' type="text/css"';
?>
<style<?php echo $type_attr; ?> media="print">#wpadminbar { display:none; }</style>
<?php
}

/**
* Prints default admin bar callback.
*
* @since 3.1.0
* @deprecated 6.4.0 Use wp_enqueue_admin_bar_bump_styles() instead.
*/
function _admin_bar_bump_cb() {
_deprecated_function( __FUNCTION__, '6.4.0', 'wp_enqueue_admin_bar_bump_styles' );
$type_attr = current_theme_supports( 'html5', 'style' ) ? '' : ' type="text/css"';
?>
<style<?php echo $type_attr; ?> media="screen">
html { margin-top: 32px !important; }
@media screen and ( max-width: 782px ) {
html { margin-top: 46px !important; }
}
</style>
<?php
}
22 changes: 12 additions & 10 deletions src/wp-includes/embed.php
Original file line number Diff line number Diff line change
Expand Up @@ -1059,18 +1059,20 @@ function enqueue_embed_scripts() {
}

/**
* Prints the CSS in the embed iframe header.
* Enqueue the CSS in the embed iframe header.
spacedmonkey marked this conversation as resolved.
Show resolved Hide resolved
*
* @since 4.4.0
* @since 6.4.0
*/
function print_embed_styles() {
$type_attr = current_theme_supports( 'html5', 'style' ) ? '' : ' type="text/css"';
$suffix = SCRIPT_DEBUG ? '' : '.min';
?>
<style<?php echo $type_attr; ?>>
<?php echo file_get_contents( ABSPATH . WPINC . "/css/wp-embed-template$suffix.css" ); ?>
</style>
<?php
function wp_enqueue_embed_styles() {
if ( ! has_action( 'embed_head', 'print_embed_styles' ) ) {
spacedmonkey marked this conversation as resolved.
Show resolved Hide resolved
return;
}
remove_action( 'embed_head', 'print_embed_styles' );
$suffix = wp_scripts_get_suffix();
spacedmonkey marked this conversation as resolved.
Show resolved Hide resolved
$handle = 'wp-embed-template';
wp_register_style( $handle, false );
wp_add_inline_style( $handle, file_get_contents( ABSPATH . WPINC . "/css/wp-embed-template$suffix.css" ) );
wp_enqueue_style( $handle );
}

/**
Expand Down
48 changes: 22 additions & 26 deletions src/wp-includes/formatting.php
Original file line number Diff line number Diff line change
Expand Up @@ -5858,36 +5858,32 @@ function wp_spaces_regexp() {
}

/**
* Prints the important emoji-related styles.
* Enqueue the important emoji-related styles.
spacedmonkey marked this conversation as resolved.
Show resolved Hide resolved
*
* @since 4.2.0
* @since 6.4.0
*/
function print_emoji_styles() {
static $printed = false;

if ( $printed ) {
function wp_enqueue_emoji_styles() {
$action = is_admin() ? 'admin_print_styles' : 'wp_print_styles';
spacedmonkey marked this conversation as resolved.
Show resolved Hide resolved
if ( ! has_action( $action, 'print_emoji_styles' ) ) {
return;
}

$printed = true;

$type_attr = current_theme_supports( 'html5', 'style' ) ? '' : ' type="text/css"';
?>
<style<?php echo $type_attr; ?>>
img.wp-smiley,
img.emoji {
display: inline !important;
border: none !important;
box-shadow: none !important;
height: 1em !important;
width: 1em !important;
margin: 0 0.07em !important;
vertical-align: -0.1em !important;
background: none !important;
padding: 0 !important;
}
</style>
<?php
remove_action( $action, 'print_emoji_styles' );
$emoji_styles = /* language=CSS */ '
spacedmonkey marked this conversation as resolved.
Show resolved Hide resolved
img.wp-smiley, img.emoji {
display: inline !important;
border: none !important;
box-shadow: none !important;
height: 1em !important;
width: 1em !important;
margin: 0 0.07em !important;
vertical-align: -0.1em !important;
background: none !important;
padding: 0 !important;
}';
$handle = 'wp-emoji-styles';
wp_register_style( $handle, false );
wp_add_inline_style( $handle, $emoji_styles );
wp_enqueue_style( $handle );
}

/**
Expand Down
19 changes: 10 additions & 9 deletions src/wp-includes/theme-templates.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,14 +118,8 @@ function the_block_template_skip_link() {
if ( ! $_wp_current_template_content ) {
return;
}
?>

<?php
/**
* Print the skip-link styles.
*/
?>
<style id="skip-link-styles">
$skip_link_styles = /* language=CSS */ '
.skip-link.screen-reader-text {
border: 0;
clip: rect(1px,1px,1px,1px);
Expand Down Expand Up @@ -154,8 +148,15 @@ function the_block_template_skip_link() {
top: 5px;
width: auto;
z-index: 100000;
}
</style>
}';

$handle = 'wp-block-template-skip-link';

wp_register_style( $handle, false );
wp_add_inline_style( $handle, $skip_link_styles );
wp_enqueue_style( $handle );
felixarntz marked this conversation as resolved.
Show resolved Hide resolved
?>
spacedmonkey marked this conversation as resolved.
Show resolved Hide resolved

<?php
spacedmonkey marked this conversation as resolved.
Show resolved Hide resolved
/**
* Print the skip-link script.
Expand Down
2 changes: 2 additions & 0 deletions tests/phpunit/tests/blocks/editor.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ public function set_up() {

parent::set_up();

remove_action( 'wp_print_styles', 'print_emoji_styles' );
spacedmonkey marked this conversation as resolved.
Show resolved Hide resolved

$args = array(
'post_title' => 'Example',
);
Expand Down
2 changes: 2 additions & 0 deletions tests/phpunit/tests/oembed/template.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ public function set_up() {

global $wp_scripts;
$wp_scripts = null;

remove_action( 'wp_print_styles', 'print_emoji_styles' );
}

public function tear_down() {
Expand Down
5 changes: 5 additions & 0 deletions tests/phpunit/tests/theme/wpAddGlobalStylesForBlocks.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ class Tests_Theme_WpAddGlobalStylesForBlocks extends WP_Theme_UnitTestCase {
*/
private $test_blocks = array();

public function set_up() {
parent::set_up();
remove_action( 'wp_print_styles', 'print_emoji_styles' );
}

public function tear_down() {
// Unregister test blocks.
if ( ! empty( $this->test_blocks ) ) {
Expand Down
Loading