Skip to content
52 changes: 39 additions & 13 deletions src/wp-admin/theme-editor.php
Original file line number Diff line number Diff line change
Expand Up @@ -212,19 +212,45 @@
);
}

if ( preg_match( '/\.css$/', $file ) && ! wp_is_block_theme() && current_user_can( 'customize' ) ) {
$message = '<p><strong>' . __( 'Did you know?' ) . '</strong></p><p>' . sprintf(
/* translators: %s: Link to Custom CSS section in the Customizer. */
__( 'There is no need to change your CSS here &mdash; you can edit and live preview CSS changes in the <a href="%s">built-in CSS editor</a>.' ),
esc_url( add_query_arg( 'autofocus[section]', 'custom_css', admin_url( 'customize.php' ) ) )
) . '</p>';
wp_admin_notice(
$message,
array(
'type' => 'info',
'id' => 'message',
)
);
if ( preg_match( '/\.css$/', $file ) ) {
if ( ! wp_is_block_theme() && current_user_can( 'customize' ) ) {
$message = '<p><strong>' . __( 'Did you know?' ) . '</strong></p><p>' . sprintf(
/* translators: %s: Link to add custom CSS section in either the Customizer (classic themes) or Site Editor (block themes). */
__( 'There is no need to change your CSS here &mdash; you can edit and live preview CSS changes in the <a href="%s">built-in CSS editor</a>.' ),
esc_url( add_query_arg( 'autofocus[section]', 'custom_css', admin_url( 'customize.php' ) ) )
) . '</p>';
wp_admin_notice(
$message,
array(
'type' => 'info',
'id' => 'message',
)
);
} elseif ( wp_is_block_theme() && current_user_can( 'edit_theme_options' ) ) {
$message = '<p><strong>' . __( 'Did you know?' ) . '</strong></p><p>' . sprintf(
/* translators: %s: Link to add custom CSS section in either the Customizer (classic themes) or Site Editor (block themes). */
__( 'There is no need to change your CSS here &mdash; you can edit and live preview CSS changes in the <a href="%s">built-in CSS editor</a>.' ),
esc_url( admin_url( 'site-editor.php?p=%2Fstyles&section=%2Fcss' ) )
) . '</p>';
wp_admin_notice(
$message,
array(
'type' => 'info',
'id' => 'message',
)
);
}
if ( file_exists( preg_replace( '/\.css$/', '.min.css', $file ) ) ) {
Copy link
Member

Choose a reason for hiding this comment

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

@westonruter In the development version, SCRIPT_DEBUG is set to true, so this notice does not makes sense since it loads CSS from the unminified .css file. However, in production, SCRIPT_DEBUG is false, meaning that CSS won’t be applied as it load .min.css file.

This creates a bit of a trade-off not sure if we actually need this notice in that case 🤔

Copy link
Member Author

Choose a reason for hiding this comment

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

I'm not sure I understand. The issue is that the changes to style.css may not be served to visitors, depending on whether SCRIPT_DEBUG is enabled. If someone temporarily enables script debug, then they would confused why their fix no longer appears after changing the file and turning script debug off. So the warning seems important.

Copy link
Member

Choose a reason for hiding this comment

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

Got it. Thanks for clarification.

$message = '<p><strong>' . __( 'There is a minified version of this stylesheet.' ) . '</strong></p><p>' .
__( 'It is likely that this unminified stylesheet will not be served to visitors.' ) . '</p>';
wp_admin_notice(
$message,
array(
'type' => 'warning',
'id' => 'wp-css-min-warning',
)
);
}
}
?>

Expand Down
Loading