Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
85.71% covered (warning)
85.71%
6 / 7
100.00% covered (success)
100.00%
1 / 1
CRAP
n/a
0 / 0
wpcom_hide_non_breaking_space_markers
100.00% covered (success)
100.00%
6 / 6
100.00% covered (success)
100.00%
1 / 1
4
1<?php
2/**
3 * Hide the block editor's non-breaking space markers on sites that opt out of them.
4 *
5 * @package automattic/jetpack-mu-wpcom
6 */
7
8/**
9 * Reset the marker Gutenberg draws on non-breaking spaces in the selected block, for sites with the
10 * `hide-non-breaking-space-markers` blog sticker.
11 */
12function wpcom_hide_non_breaking_space_markers() {
13    if ( ! is_admin() || ! wpcom_has_blog_sticker( 'hide-non-breaking-space-markers', get_wpcom_blog_id() ) ) {
14        return;
15    }
16
17    // Opt-in accommodation overriding the marker in Gutenberg's rich-text/content.scss (a dot from 24.3,
18    // an outline before); drop it once Gutenberg ships its own preference to hide the markers.
19    // The hook fires again for each editor iframe, which shares this registration.
20    if ( ! wp_style_is( 'wpcom-hide-non-breaking-space-markers', 'registered' ) ) {
21        wp_register_style( 'wpcom-hide-non-breaking-space-markers', false, array(), '1.0' );
22        // !important because concatenated or copied sheets can print Gutenberg's rule after this one.
23        wp_add_inline_style( 'wpcom-hide-non-breaking-space-markers', '.is-selected .non-breaking-space{background:none!important;outline:none!important;opacity:1!important}' );
24    }
25    wp_enqueue_style( 'wpcom-hide-non-breaking-space-markers' );
26}
27add_action( 'enqueue_block_assets', 'wpcom_hide_non_breaking_space_markers' );