WordPress.org

Make WordPress Core


Ignore:
Timestamp:
06/22/2021 01:32:42 PM (4 months ago)
Author:
desrosj
Message:

Widgets: Add editor styles to the widgets block editor.

This updates the widgets screen to load the editor styles in the same way as the post editor. This combined with the package updates in [51198] and [51199] ensures that the blocks added to sidebars more accurately reflect what will be displayed on the front end of the site.

Props isabel_brison, noisysocks, andraganescu, audrasjb, jorbin, caseymilne, desrosj.
Fixes #53344. See #53388.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/block-editor.php

    r51149 r51200  
    465465    );
    466466}
     467
     468/**
     469 * Creates an array of theme styles to load into the block editor.
     470 *
     471 * @since 5.8.0
     472 *
     473 * @global array $editor_styles
     474 *
     475 * @return array An array of theme styles for the block editor. Includes default font family
     476 *               style and theme stylesheets.
     477 */
     478function get_block_editor_theme_styles() {
     479    global $editor_styles;
     480
     481    $styles = array(
     482        array(
     483            'css'            => 'body { font-family: -apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,Oxygen-Sans,Ubuntu,Cantarell,"Helvetica Neue",sans-serif }',
     484            '__unstableType' => 'core',
     485        ),
     486    );
     487    if ( $editor_styles && current_theme_supports( 'editor-styles' ) ) {
     488        foreach ( $editor_styles as $style ) {
     489            if ( preg_match( '~^(https?:)?//~', $style ) ) {
     490                $response = wp_remote_get( $style );
     491                if ( ! is_wp_error( $response ) ) {
     492                    $styles[] = array(
     493                        'css'            => wp_remote_retrieve_body( $response ),
     494                        '__unstableType' => 'theme',
     495                    );
     496                }
     497            } else {
     498                $file = get_theme_file_path( $style );
     499                if ( is_file( $file ) ) {
     500                    $styles[] = array(
     501                        'css'            => file_get_contents( $file ),
     502                        'baseURL'        => get_theme_file_uri( $style ),
     503                        '__unstableType' => 'theme',
     504                    );
     505                }
     506            }
     507        }
     508    }
     509
     510    return $styles;
     511}
Note: See TracChangeset for help on using the changeset viewer.