Skip to content
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

Ensure all prompts to remove premium styles automatically work #40818

Draft
wants to merge 5 commits into
base: trunk
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: minor
Type: added

Adds reset global styles functionality to the wpcom global styles view.
Original file line number Diff line number Diff line change
Expand Up @@ -452,9 +452,11 @@ function wpcom_display_global_styles_launch_bar( $bar_controls ) {
if ( ! wpcom_should_limit_global_styles() || ! wpcom_global_styles_in_use() ) {
return $bar_controls;
}
$blog_id = get_current_blog_id();
$global_styles_id = WP_Theme_JSON_Resolver::get_user_global_styles_post_id();

if ( method_exists( '\WPCOM_Masterbar', 'get_calypso_site_slug' ) ) {
$site_slug = WPCOM_Masterbar::get_calypso_site_slug( get_current_blog_id() );
$site_slug = WPCOM_Masterbar::get_calypso_site_slug( $blog_id );
} else {
$home_url = home_url( '/' );
$site_slug = wp_parse_url( $home_url, PHP_URL_HOST );
Expand Down Expand Up @@ -540,12 +542,16 @@ class="launch-bar-global-styles-upgrade"
class="launch-bar-global-styles-reset"
href="https://wordpress.com/support/using-styles/#reset-all-styles"
target="_blank"
data-blog-id="<?php echo esc_attr( (string) $blog_id ); ?>"
data-global-styles-id="<?php echo esc_attr( (string) $global_styles_id ); ?>"
Comment on lines +545 to +546
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a first pass, but thinking of alternatives to exposing blog and global styles id to frontend.

Via a query e.g., ?reset-global-styles=true? Then the PHP could do all the work, and also double check that the user is logged in, has privileges etc.

If it fails for whatever reason, then we could render the link to the help docs.

>
<svg width="15" height="14" viewBox="0 0 15 14" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M5.8125 5.6875C5.8125 4.75552 6.56802 4 7.5 4C8.43198 4 9.1875 4.75552 9.1875 5.6875C9.1875 6.55621 8.53108 7.2716 7.6872 7.36473C7.58427 7.37609 7.5 7.45895 7.5 7.5625V8.5M7.5 9.25V10.375M13.5 7C13.5 10.3137 10.8137 13 7.5 13C4.18629 13 1.5 10.3137 1.5 7C1.5 3.68629 4.18629 1 7.5 1C10.8137 1 13.5 3.68629 13.5 7Z" stroke="#1E1E1E" stroke-width="1.5"/>
</svg>
<?php echo esc_html__( 'Remove premium styles', 'jetpack-mu-wpcom' ); ?>
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="15" height="15" aria-hidden="true" focusable="false"><path d="M18.2 17c0 .7-.6 1.2-1.2 1.2H7c-.7 0-1.2-.6-1.2-1.2V7c0-.7.6-1.2 1.2-1.2h3.2V4.2H7C5.5 4.2 4.2 5.5 4.2 7v10c0 1.5 1.2 2.8 2.8 2.8h10c1.5 0 2.8-1.2 2.8-2.8v-3.6h-1.5V17zM14.9 3v1.5h3.7l-6.4 6.4 1.1 1.1 6.4-6.4v3.7h1.5V3h-6.3z"></path></svg>
<svg class="icon-block" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="15" height="15" aria-hidden="true" focusable="false">
<path fill-rule="evenodd" clip-rule="evenodd" d="M12 18.5A6.5 6.5 0 0 1 6.93 7.931l9.139 9.138A6.473 6.473 0 0 1 12 18.5Zm5.123-2.498a6.5 6.5 0 0 0-9.124-9.124l9.124 9.124ZM4 12a8 8 0 1 1 16 0 8 8 0 0 1-16 0Z"></path>
</svg>
<svg class="icon-scheduled" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="15" height="15" aria-hidden="true" focusable="false">
<path fill-rule="evenodd" clip-rule="evenodd" d="M12 18.5a6.5 6.5 0 1 1 0-13 6.5 6.5 0 0 1 0 13ZM4 12a8 8 0 1 1 16 0 8 8 0 0 1-16 0Zm9 1V8h-1.5v3.5h-2V13H13Z"></path>
</svg>
</a>
<a class="launch-bar-global-styles-preview" href="<?php echo esc_url( $preview_location ); ?>">
<label><input type="checkbox" <?php echo wpcom_is_previewing_global_styles() ? 'checked' : ''; ?>><span></span></label>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,26 @@
/* global launchBarUserData */
import wpcomRequest from 'wpcom-proxy-request';
import { wpcomTrackEvent } from '../../common/tracks';

import './wpcom-global-styles-view.scss';

const restGlobalStyles = async ( globalStylesId, siteIdOrSlug ) => {
if ( ! globalStylesId || ! siteIdOrSlug ) {
return false;
}

// TODO find a way to PUT from the frontend preview.
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ignore this comment. I was in READ mode on sandbox.

return await wpcomRequest( {
path: `/sites/${ encodeURIComponent( siteIdOrSlug ) }/global-styles/${ globalStylesId }`,
apiNamespace: 'wp/v2',
method: 'POST',
body: {
id: globalStylesId,
settings: {},
styles: {},
},
} );
};

/**
* Records a Tracks click event.
* @param {string} button - Identifier of the button that has been clicked.
Expand Down Expand Up @@ -75,9 +93,21 @@ document.addEventListener( 'DOMContentLoaded', () => {
window.location = previewButton.href;
} );

resetButton?.addEventListener( 'click', event => {
resetButton?.addEventListener( 'click', async event => {
event.preventDefault();
recordEvent( 'wpcom_global_styles_gating_notice_reset_support' );
window.open( resetButton.href, '_blank' ).focus();
const globalStylesId = resetButton.dataset.globalStylesId;
const siteId = resetButton.dataset.blogId;
if ( globalStylesId && siteId ) {
resetButton?.classList.add( 'is-resetting' );
const result = await restGlobalStyles( globalStylesId, siteId );
if ( result ) {
window.location.reload();
} else {
resetButton?.classList.remove( 'is-resetting' );
}
} else {
window.open( resetButton.href, '_blank' ).focus();
}
} );
} );
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,7 @@
color: inherit;
font-weight: normal !important;

svg:first-child {
margin-right: 4px;
}

svg:last-child {
svg {
margin-left: 4px;
position: relative;
top: 1px;
Expand All @@ -73,6 +69,22 @@
background: transparent;
color: #676767;
}

&.is-resetting {
opacity: 0.5;
pointer-events: none;
cursor: default;
.icon-block {
display: none;
}
.icon-scheduled {
display: inline;
}
}

.icon-scheduled {
display: none;
}
}
}

Expand Down
Loading