-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Add Theme File Editor notice when editing a stylesheet for a block theme and warn when there is a minified version available #10279
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
Conversation
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the Core Committers: Use this line as a base for the props when committing in SVN:
To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
Co-authored-by: Aaron Jorbin <[email protected]>
src/wp-admin/theme-editor.php
Outdated
); | ||
} | ||
if ( file_exists( preg_replace( '/\.css$/', '.min.css', $file ) ) ) { | ||
$message = '<p><strong>' . __( 'There is a minified version of this stylesheet.' ) . '</strong></p><p>' . sprintf( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The sprintf can also be eliminated since there is no substitution (sorry, didn't catch that earlier)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The apologies should be mine!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed in 9383f2e
Co-authored-by: Aaron Jorbin <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks good, thanks.
A couple of notes inline: I think it's best practice if translator comments are uniform for repeated strings. WP CLI throws a warning if they differ. Someone on the polyglots team will be able to confirm.
I've suggested an ID for the new warning message, feel free to come up with a better name.
Co-authored-by: Peter Wilson <[email protected]>
Co-authored-by: Peter Wilson <[email protected]>
Co-authored-by: Peter Wilson <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks good to me and tests well.
Testing notes:
- 2025: Link goes to site editor
- 2025: Warning shown when editing stylesheet
- 2014: Link goes to customizer
- 2014:
touch src/wp-content/themes/twentyfourteen/style.min.css
causes the warning to be shown. - 2014: Without the fake file, the warning is not shown.
FYI: In the SVN commit, I'm improving the construction of the Site Editor URL as follows: --- a/src/wp-admin/theme-editor.php
+++ b/src/wp-admin/theme-editor.php
@@ -227,10 +227,22 @@ if ( preg_match( '/\.css$/', $file ) ) {
)
);
} elseif ( wp_is_block_theme() && current_user_can( 'edit_theme_options' ) ) {
+ $site_editor_url = admin_url(
+ add_query_arg(
+ urlencode_deep(
+ array(
+ 'p' => '/styles',
+ 'section' => '/css',
+ )
+ ),
+ 'site-editor.php'
+ )
+ );
+
$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 — 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§ion=%2Fcss' ) )
+ esc_url( $site_editor_url )
) . '</p>';
wp_admin_notice(
$message, |
* When a block theme is active, add a notice to advise using Additional CSS in the Site Editor. A similar notice is already directing users to Custom CSS in the Customizer when a classic theme is active. * When there is a minified file (`*.min.css`) present for the current CSS file, warn that any edits may not be served to visitors. Developed in #10279 Follow-up to [60934]. Props westonruter, peterwilsoncc, jorbin. See #63012. git-svn-id: https://develop.svn.wordpress.org/trunk@60943 602fd350-edb4-49c9-b593-d223f7449a82
* When a block theme is active, add a notice to advise using Additional CSS in the Site Editor. A similar notice is already directing users to Custom CSS in the Customizer when a classic theme is active. * When there is a minified file (`*.min.css`) present for the current CSS file, warn that any edits may not be served to visitors. Developed in WordPress/wordpress-develop#10279 Follow-up to [60934]. Props westonruter, peterwilsoncc, jorbin. See #63012. Built from https://develop.svn.wordpress.org/trunk@60943 git-svn-id: http://core.svn.wordpress.org/trunk@60279 1a063a9b-81f0-0310-95a4-ce76da25c4cd
* When a block theme is active, add a notice to advise using Additional CSS in the Site Editor. A similar notice is already directing users to Custom CSS in the Customizer when a classic theme is active. * When there is a minified file (`*.min.css`) present for the current CSS file, warn that any edits may not be served to visitors. Developed in WordPress/wordpress-develop#10279 Follow-up to [60934]. Props westonruter, peterwilsoncc, jorbin. See #63012. Built from https://develop.svn.wordpress.org/trunk@60943 git-svn-id: https://core.svn.wordpress.org/trunk@60279 1a063a9b-81f0-0310-95a4-ce76da25c4cd
) | ||
); | ||
} | ||
if ( file_exists( preg_replace( '/\.css$/', '.min.css', $file ) ) ) { |
There was a problem hiding this comment.
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 🤔
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
This is a follow-up to #10081 (r60934 and b56b386) based on a discussion with @peterwilsoncc. A CSS comment was added to the
style.css
for TT2 and TT5 to warn against editing since thestyle.min.css
will likely be served instead:However, the user may not see this easily. Therefore, this PR adds an admin notice when editing a CSS file when there is also a
.min.css
version for that same file name in the current theme.Additionally, for non-block themes there was an admin info notice about using the Custom CSS in the Customizer to edit CSS, but there was no corresponding notice to prompt users to use Additional CSS in the Site Editor for block themes. So this rectifies that issue. The new notices appear as follows when editing
style.css
in TT5:Trac ticket: https://core.trac.wordpress.org/ticket/63012
This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the Core Handbook for more details.