Skip to content

Commit f74d896

Browse files
authored
Preview limited Global Styles by default (#76661)
- Custom styles are previewed by default, so there is less confusion around the site-editor and the front-end not matching up. - Both the site editor and the post editor display now a global notice when Global Styles are limited. Previous sidebar notices in the site editor have been removed. This notice has the following actions: - Upgrade now (primary): Visible in both editors – It opens the Plans page in a new tab. - Remove custom styles (link): Visible in the site editor only – It resets the styles to defaults (it’s easy and safe to do so in the editor). Once we have a support page explaining how to remove custom styles, we can show it in the post editor too. - Add a new notice to the view canvas. - Updates the E2E test to use the view canvas mode since that's the only place where we have a fragile CSS selector.
1 parent 2f5b018 commit f74d896

File tree

16 files changed

+252
-333
lines changed

16 files changed

+252
-333
lines changed

apps/editing-toolkit/editing-toolkit-plugin/wpcom-global-styles/global-style-sidebar-notice.tsx

-71
This file was deleted.

apps/editing-toolkit/editing-toolkit-plugin/wpcom-global-styles/index.js

+2-4
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,16 @@ import './public-path';
33

44
import domReady from '@wordpress/dom-ready';
55
import { registerPlugin } from '@wordpress/plugins';
6-
import GlobalStylesSidebarNotice from './global-style-sidebar-notice';
76
import GlobalStylesModal from './modal';
8-
import GlobalStylesNotice from './notice';
7+
import GlobalStylesNotices from './notices';
98
import './store';
109

1110
const showGlobalStylesComponents = () => {
1211
registerPlugin( 'wpcom-global-styles', {
1312
render: () => (
1413
<>
1514
<GlobalStylesModal />
16-
<GlobalStylesNotice />
17-
<GlobalStylesSidebarNotice />
15+
<GlobalStylesNotices />
1816
</>
1917
),
2018
} );

apps/editing-toolkit/editing-toolkit-plugin/wpcom-global-styles/index.php

+4-8
Original file line numberDiff line numberDiff line change
@@ -103,11 +103,6 @@ function wpcom_global_styles_has_blog_sticker( $blog_sticker, $blog_id ) {
103103
* @return void
104104
*/
105105
function wpcom_global_styles_enqueue_block_editor_assets() {
106-
$screen = get_current_screen();
107-
if ( ! $screen || 'site-editor' !== $screen->id ) {
108-
return;
109-
}
110-
111106
if ( ! wpcom_should_limit_global_styles() ) {
112107
return;
113108
}
@@ -153,6 +148,7 @@ function wpcom_global_styles_enqueue_block_editor_assets() {
153148
array(
154149
'assetsUrl' => plugins_url( 'dist/', __FILE__ ),
155150
'upgradeUrl' => "$calypso_domain/plans/$site_slug?plan=value_bundle&feature=style-customization",
151+
'previewUrl' => add_query_arg( 'hide-global-styles', '', home_url() ),
156152
'wpcomBlogId' => wpcom_global_styles_get_wpcom_current_blog_id(),
157153
)
158154
);
@@ -422,9 +418,9 @@ function wpcom_display_global_styles_launch_bar( $bar_controls ) {
422418
$upgrade_url = 'https://wordpress.com/plans/' . $site_slug . '?plan=value_bundle&feature=style-customization';
423419

424420
if ( wpcom_is_previewing_global_styles() ) {
425-
$preview_location = remove_query_arg( 'preview-global-styles' );
421+
$preview_location = add_query_arg( 'hide-global-styles', '' );
426422
} else {
427-
$preview_location = add_query_arg( 'preview-global-styles', '' );
423+
$preview_location = remove_query_arg( 'hide-global-styles' );
428424
}
429425

430426
ob_start(); ?>
@@ -533,5 +529,5 @@ function wpcom_is_previewing_global_styles( ?int $user_id = null ) {
533529
}
534530

535531
// phpcs:ignore WordPress.Security.NonceVerification.Recommended
536-
return isset( $_GET['preview-global-styles'] ) && user_can( $user_id, 'administrator' );
532+
return ! isset( $_GET['hide-global-styles'] ) && user_can( $user_id, 'administrator' );
537533
}

apps/editing-toolkit/editing-toolkit-plugin/wpcom-global-styles/modal.js

+16-24
Original file line numberDiff line numberDiff line change
@@ -2,53 +2,45 @@
22

33
import { recordTracksEvent } from '@automattic/calypso-analytics';
44
import { Button, Modal } from '@wordpress/components';
5-
import { subscribe, useDispatch, useSelect } from '@wordpress/data';
6-
import { useEffect, useState } from '@wordpress/element';
5+
import { useDispatch, useSelect } from '@wordpress/data';
6+
import { useEffect } from '@wordpress/element';
77
import { __ } from '@wordpress/i18n';
88
import React from 'react';
99
import image from './image.svg';
10+
import { useCanvas } from './use-canvas';
1011

1112
import './modal.scss';
1213

1314
const GlobalStylesModal = () => {
14-
const [ viewCanvasPath, setViewCanvasPath ] = useState();
15-
16-
// Since Gutenberg doesn't provide a stable selector to get the current path of
17-
// the view canvas, we need to infer it from the URL.
18-
useEffect( () => {
19-
const unsubscribe = subscribe( () => {
20-
// Subscriber callbacks run before the URL actually changes, so we need
21-
// to delay the execution.
22-
setTimeout( () => {
23-
const params = new URLSearchParams( window.location.search );
24-
25-
const canvasMode = params.get( 'canvas' ) ?? 'view';
26-
setViewCanvasPath( canvasMode === 'view' ? params.get( 'path' ) : undefined );
27-
}, 0 );
28-
}, 'core/edit-site' );
29-
30-
return () => unsubscribe();
31-
}, [] );
15+
const isSiteEditor = useSelect( ( select ) => !! select( 'core/edit-site' ), [] );
16+
const { viewCanvasPath } = useCanvas();
3217

3318
const isVisible = useSelect(
3419
( select ) => {
20+
if ( ! isSiteEditor ) {
21+
return false;
22+
}
23+
3524
const currentSidebar =
3625
select( 'core/interface' ).getActiveComplementaryArea( 'core/edit-site' );
26+
3727
return select( 'automattic/wpcom-global-styles' ).isModalVisible(
3828
currentSidebar,
3929
viewCanvasPath
4030
);
4131
},
42-
[ viewCanvasPath ]
32+
[ viewCanvasPath, isSiteEditor ]
4333
);
4434

4535
const { dismissModal } = useDispatch( 'automattic/wpcom-global-styles' );
4636
const { set: setPreference } = useDispatch( 'core/preferences' );
4737

4838
// Hide the welcome guide modal, so it doesn't conflict with our modal.
4939
useEffect( () => {
50-
setPreference( 'core/edit-site', 'welcomeGuideStyles', false );
51-
}, [ setPreference ] );
40+
if ( isSiteEditor ) {
41+
setPreference( 'core/edit-site', 'welcomeGuideStyles', false );
42+
}
43+
}, [ setPreference, isSiteEditor ] );
5244

5345
useEffect( () => {
5446
if ( isVisible ) {
@@ -65,7 +57,7 @@ const GlobalStylesModal = () => {
6557
} );
6658
};
6759

68-
if ( ! isVisible ) {
60+
if ( ! isSiteEditor || ! isVisible ) {
6961
return null;
7062
}
7163

apps/editing-toolkit/editing-toolkit-plugin/wpcom-global-styles/notice.js

-98
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,8 @@
11
.wpcom-global-styles-notice {
2-
margin: 0 0 0 0;
3-
4-
.notice-margin {
5-
margin: 16px 0 0;
6-
}
2+
margin: 0 0 12px;
3+
color: var(--color-text);
74

85
.components-notice__content {
96
margin-right: 0;
107
}
11-
12-
a {
13-
display: inline;
14-
}
15-
16-
.components-button.is-link {
17-
color: var(--color-link);
18-
19-
&:hover {
20-
color: var(--color-link-light);
21-
}
22-
}
238
}

0 commit comments

Comments
 (0)