Make WordPress Core

Changeset 60943


Ignore:
Timestamp:
10/16/2025 12:14:47 AM (2 months ago)
Author:
westonruter
Message:

Theme Editor: Add additional notice and warning when editing a CSS file.

  • 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 https://github.com/WordPress/wordpress-develop/pull/10279

Follow-up to [60934].

Props westonruter, peterwilsoncc, jorbin.
See #63012.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/theme-editor.php

    r60932 r60943  
    213213}
    214214
    215 if ( preg_match( '/\.css$/', $file ) && ! wp_is_block_theme() && current_user_can( 'customize' ) ) {
    216     $message = '<p><strong>' . __( 'Did you know?' ) . '</strong></p><p>' . sprintf(
    217         /* translators: %s: Link to Custom CSS section in the Customizer. */
    218         __( '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>.' ),
    219         esc_url( add_query_arg( 'autofocus[section]', 'custom_css', admin_url( 'customize.php' ) ) )
    220     ) . '</p>';
    221     wp_admin_notice(
    222         $message,
    223         array(
    224             'type' => 'info',
    225             'id'   => 'message',
    226         )
    227     );
     215if ( preg_match( '/\.css$/', $file ) ) {
     216    if ( ! wp_is_block_theme() && current_user_can( 'customize' ) ) {
     217        $message = '<p><strong>' . __( 'Did you know?' ) . '</strong></p><p>' . sprintf(
     218            /* translators: %s: Link to add custom CSS section in either the Customizer (classic themes) or Site Editor (block themes). */
     219            __( '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>.' ),
     220            esc_url( add_query_arg( 'autofocus[section]', 'custom_css', admin_url( 'customize.php' ) ) )
     221        ) . '</p>';
     222        wp_admin_notice(
     223            $message,
     224            array(
     225                'type' => 'info',
     226                'id'   => 'message',
     227            )
     228        );
     229    } elseif ( wp_is_block_theme() && current_user_can( 'edit_theme_options' ) ) {
     230        $site_editor_url = admin_url(
     231            add_query_arg(
     232                urlencode_deep(
     233                    array(
     234                        'p'       => '/styles',
     235                        'section' => '/css',
     236                    )
     237                ),
     238                'site-editor.php'
     239            )
     240        );
     241
     242        $message = '<p><strong>' . __( 'Did you know?' ) . '</strong></p><p>' . sprintf(
     243            /* translators: %s: Link to add custom CSS section in either the Customizer (classic themes) or Site Editor (block themes). */
     244            __( '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>.' ),
     245            esc_url( $site_editor_url )
     246        ) . '</p>';
     247        wp_admin_notice(
     248            $message,
     249            array(
     250                'type' => 'info',
     251                'id'   => 'message',
     252            )
     253        );
     254    }
     255    if ( file_exists( preg_replace( '/\.css$/', '.min.css', $file ) ) ) {
     256        $message = '<p><strong>' . __( 'There is a minified version of this stylesheet.' ) . '</strong></p><p>' .
     257            __( 'It is likely that this unminified stylesheet will not be served to visitors.' ) . '</p>';
     258        wp_admin_notice(
     259            $message,
     260            array(
     261                'type' => 'warning',
     262                'id'   => 'wp-css-min-warning',
     263            )
     264        );
     265    }
    228266}
    229267?>
Note: See TracChangeset for help on using the changeset viewer.