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

Settings: Allow Users to Insert Header Code #86079

Open
wants to merge 9 commits into
base: trunk
Choose a base branch
from

Conversation

Aurorum
Copy link
Contributor

@Aurorum Aurorum commented Jan 6, 2024

Fixes #56023

Requires Automattic/jetpack#34881 (also, I need to add a version check here once that Jetpack PR is merged)

Proposed Changes

Allows user to directly edit their <head> element without relying on a third-party plugin. A plugin to insert code in the Header element is now the eighth most popular on WP.com (!!), so hopefully this will make things easier for both users and those in Support.

Rather than using a default textbox which created a strange experience, it felt more appropriate to use CodeMirror. Unfortunately, that means adding another package, but I've used the same one already used in Automattic projects like Newspack so I don't think that's a problem.

Testing Instructions

  1. Apply the Jetpack PR
  2. Go to Settings > General and scroll to "Site Tools" on an Atomic or Jetpack site (this didn't really seem to fit within any section, and the section cards are quite small for a code editor!)
  3. Select "Header code"
  4. Enter some header code, and verify that it's included on your site
Screenshot 2024-01-08 at 08 30 22

Pre-merge Checklist

Can't access P2s, but have tested on Simple and Atomic - the former can't access this page from Settings, and a direct link shows an upgrade nudge.

  • Has the general commit checklist been followed? (PCYsg-hS-p2)
  • [] Have you written new tests for your changes?
  • Have you tested the feature in Simple (P9HQHe-k8-p2), Atomic (P9HQHe-jW-p2), and self-hosted Jetpack sites (PCYsg-g6b-p2)?
  • Have you checked for TypeScript, React or other console errors?
  • Have you used memoizing on expensive computations? More info in Memoizing with create-selector and Using memoizing selectors and Our Approach to Data
  • Have we added the "[Status] String Freeze" label as soon as any new strings were ready for translation (p4TIVU-5Jq-p2)?
  • For changes affecting Jetpack: Have we added the "[Status] Needs Privacy Updates" label if this pull request changes what data or activity we track or use (p4TIVU-ajp-p2)?

cc @tyxla - it looks like you've worked on Settings regularly before, might this maybe fall into your remit? thanks!! :)

@Aurorum
Copy link
Contributor Author

Aurorum commented Jan 6, 2024

@donalirl do you have a link to this document that I could include here? Thanks!

On the page, we could also link to the support doc being created in 1210-gh-Automattic/en.support-docs-content, so customers know how to use this screen without needing to contact us.

@donalirl
Copy link

donalirl commented Jan 8, 2024

@Aurorum Yes! This is the doc: https://wordpress.com/support/adding-code-to-headers/

Right now the instructions are for the plugin but we can update it to provide instructions for this feature instead.

@Aurorum
Copy link
Contributor Author

Aurorum commented Jan 8, 2024

Thanks @donalirl! I've added it to the text - let me know if there's anything that I should change.

Screenshot 2024-01-08 at 08 30 22

Copy link
Member

@tyxla tyxla left a comment

Choose a reason for hiding this comment

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

Thank you for working on this @Aurorum 🙌
I don't work on settings nowadays, but of course, happy to do a general broader review.
This could use a Jetpack person to review it - cc @anomiex since he seems to be helping with reviewing on the Jetpack side.

client/my-sites/site-settings/header-code/index.jsx Outdated Show resolved Hide resolved
client/my-sites/site-settings/header-code/index.jsx Outdated Show resolved Hide resolved
client/my-sites/site-settings/header-code/index.jsx Outdated Show resolved Hide resolved
client/my-sites/site-settings/header-code/index.jsx Outdated Show resolved Hide resolved
client/my-sites/site-settings/header-code/index.jsx Outdated Show resolved Hide resolved
@@ -111,6 +112,11 @@ export function startSiteOwnerTransfer( context, next ) {
next();
}

export function headerCode( context, next ) {
context.primary = <HeaderCodeSettings />;
Copy link
Member

Choose a reason for hiding this comment

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

Will all site types support this? I see Jetpack sites will, but what about WP.com simple / Atomic / etc.?

Copy link
Contributor

Choose a reason for hiding this comment

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

The code in Automattic/jetpack#34881 explicitly excludes Simple. As things stand I don't see anything stopping it from Atomic.

Copy link
Member

Choose a reason for hiding this comment

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

In that case, we should make sure to redirect in Calypso if someone tries to access this with a WP.com simple site.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

See my comments below!

client/my-sites/site-settings/site-tools/index.jsx Outdated Show resolved Hide resolved
client/my-sites/site-settings/index.js Show resolved Hide resolved
package.json Outdated Show resolved Hide resolved
@anomiex
Copy link
Contributor

anomiex commented Jan 8, 2024

This could use a Jetpack person to review it - cc @anomiex since he seems to be helping with reviewing on the Jetpack side.

I can't say I know much about Calypso's settings either. 😅 Mostly I saw the OSS Citizen PR come across and added the Needs Review tag to it, then left a comment to answer a question asked regarding escaping.

@tyxla
Copy link
Member

tyxla commented Jan 8, 2024

This could use a Jetpack person to review it - cc @anomiex since he seems to be helping with reviewing on the Jetpack side.

I can't say I know much about Calypso's settings either. 😅 Mostly I saw the OSS Citizen PR come across and added the Needs Review tag to it, then left a comment to answer a question asked regarding escaping.

I'm totally fine to do the Calypso-side review, but lack the product context, for which a Jetpack person could be useful (to test the feature at the bare minimum).

@Aurorum
Copy link
Contributor Author

Aurorum commented Jan 8, 2024

Thank you so much for the detailed review @tyxla - very much appreciated! I've addressed the recommendations you made.

Just wanted to touch a little further about access - this is primarily intended for WordPress.com Atomic sites to make it easier for them to insert code without needing to install a third-party plugin. Jetpack is only used to include the code on the user's site. I didn't see the harm in letting Jetpack sites access this too though. I've just worked on the basis of the the original issue, so let me know if things should be changed. :)

Custom code can't be inserted on Simple sites. I've handled this by hiding this option from the Settings page, and they still won't be able to add custom code if they use a direct link. Instead, they'll see an upgrade nudge and the button will be disabled:

Screenshot 2024-01-08 at 17 42 40

If you'd like to redirect them away directly instead, just let me know! I think that a few other screens on Calypso take this approach (eg. the Earn page), but I don't think it'll make much difference either way.

I hope that clarifies access, and thanks again for the review!! :)

client/my-sites/site-settings/header-code/index.jsx Outdated Show resolved Hide resolved
<>
<NavigationHeader
title={ translate( 'Header Code' ) }
subtitle={ translate( 'Insert code within the Header element of your site.' ) }
Copy link
Member

Choose a reason for hiding this comment

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

"Header element" is definitely confusing when we talk about the "head" element. So we might want to change it indeed.

</HeaderCake>
<Card>
<UpsellNudge
plan={ PLAN_BUSINESS }
Copy link
Member

Choose a reason for hiding this comment

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

But PLAN_BUSINESS is the WP.com plan, not the Jetpack plan. That upsell wouldn't make sense for a non-Atomic Jetpack site, because a non-Atomic Jetpack site can't purchase a WP.com plan. Does that makes sense?

client/my-sites/site-settings/header-code/index.jsx Outdated Show resolved Hide resolved
client/my-sites/site-settings/header-code/index.jsx Outdated Show resolved Hide resolved
client/my-sites/site-settings/header-code/index.jsx Outdated Show resolved Hide resolved
client/my-sites/site-settings/header-code/index.jsx Outdated Show resolved Hide resolved
<Card>
<UpsellNudge
plan={ PLAN_BUSINESS }
title={ translate( 'Add custom code to your site with the %(planName)s plan.', {
Copy link
Member

Choose a reason for hiding this comment

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

What about Personal (AKA Starter) and Premium (AKA Explorer) plans? Does only the WP.com business plan have this feature?

client/my-sites/site-settings/header-code/style.scss Outdated Show resolved Hide resolved
client/my-sites/site-settings/index.js Show resolved Hide resolved
@tyxla
Copy link
Member

tyxla commented Jan 9, 2024

Thank you so much for the detailed review @tyxla - very much appreciated! I've addressed the recommendations you made.

Thank you for the great work once more!

Just wanted to touch a little further about access - this is primarily intended for WordPress.com Atomic sites to make it easier for them to insert code without needing to install a third-party plugin. Jetpack is only used to include the code on the user's site. I didn't see the harm in letting Jetpack sites access this too though. I've just worked on the basis of the the original issue, so let me know if things should be changed. :)

Understood. I just wanted to clarify that Jetpack sites can't purchase a WP.com Creator plan because they are different plans. Jetpack Creator and WP.com Creator are two different products, and this isn't reflected in the plan upsell nudge and potentially a few other places. Let me know if that makes sense.

If you'd like to redirect them away directly instead, just let me know! I think that a few other screens on Calypso take this approach (eg. the Earn page), but I don't think it'll make much difference either way.

Yes, we should redirect those settings pages if they're not available for a particular site type.

@Aurorum
Copy link
Contributor Author

Aurorum commented Jan 9, 2024 via email

@tyxla
Copy link
Member

tyxla commented Jan 9, 2024

just a very quick question - is it possible to have a Jetpack site which isn't Atomic?

Yes. Atomic sites are essentially hosted on the WP.com Atomic platform, which is powered by Jetpack and a few more plugins. However, any WordPress site that's hosted anywhere can also have Jetpack installed and be connected to WP.com through Jetpack - we call those Jetpack sites, and they're not Atomic sites because they're not hosted on WP.com. Let me know if that makes sense!

@Aurorum
Copy link
Contributor Author

Aurorum commented Jan 9, 2024 via email

@Aurorum
Copy link
Contributor Author

Aurorum commented Jan 9, 2024

Thanks again for the review @tyxla! I've addressed the latest set of feedback - it now redirects WP.com Simple sites to General settings (whereas previously these sites would have seen the upgrade nudge.

If I'm still misunderstanding access even after this change, please let me know!

@tyxla
Copy link
Member

tyxla commented Jan 10, 2024

Sorry - my mistake, I meant whether it was possible to have a Jetpack site that is Atomic!! I thought Atomic referred to WP.com sites on the Creator plan or above with plugins installed.

Atomic sites are powered by Jetpack, which also makes them Jetpack sites. Also, the jetpack property of an Atomic site is true.

@Aurorum
Copy link
Contributor Author

Aurorum commented Jan 10, 2024

Ah, okay, thank you! I would’ve assumed that the access was set correctly on that basis though - Atomic/Jetpack sites would be able to access this feature.

I’ve tested with an Atomic, Simple and Jetpack site and I’m pretty sure this is in the right place - but it’s the same logic as what I included in the upsell nudge, so please let me know if I’ve missed something! :)

@tyxla
Copy link
Member

tyxla commented Jan 10, 2024

Thanks for the great work @Aurorum, I'll take another look 👍

@Aurorum
Copy link
Contributor Author

Aurorum commented Jan 10, 2024

No rush at all, thanks so much for taking the time to review. :)

Copy link
Member

@tyxla tyxla left a comment

Choose a reason for hiding this comment

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

Thank you @Aurorum, great work so far! I've tested this and left some more feedback after giving it a try. Hope that helps, let me know if you have any questions.

client/my-sites/site-settings/header-code/index.jsx Outdated Show resolved Hide resolved
client/my-sites/site-settings/header-code/index.jsx Outdated Show resolved Hide resolved
@@ -219,6 +231,7 @@ export default compose( [
showClone: 'active' === rewindState.state && ! isAtomic,
showDeleteContent: isAtomic || ( ! isJetpack && ! isVip && ! isP2Hub ),
showDeleteSite: ( ! isJetpack || isAtomic ) && ! isVip && sitePurchasesLoaded,
showHeaderCode: isJetpack || isAtomic,
Copy link
Member

Choose a reason for hiding this comment

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

Should we show this only to admins? (if the current user has the capability to manage_options)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not necessary in this case! The entire page is blocked for non-admins.

client/my-sites/site-settings/header-code/index.jsx Outdated Show resolved Hide resolved
client/my-sites/site-settings/header-code/index.jsx Outdated Show resolved Hide resolved
client/my-sites/site-settings/header-code/style.scss Outdated Show resolved Hide resolved
Comment on lines 20 to 21
margin-bottom: 1em;
min-height: 250px;
Copy link
Member

Choose a reason for hiding this comment

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

Would be nice to avoid adding extra styles and keep consistency with the existing design. Perhaps a min-height is not necessary, and the margin bottom can also be omitted.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'd like to (respectfully!) push back on removing the min-height, if that's okay. The section already provides a lot of space so it feels weird without it, and it's also very hard to see much of the code without expanding it. That creates an extra step if, for example, a user wants to tweak the value of some code they've pasted.

Screenshot 2024-01-10 at 11 39 26

I think a bit of extra styling is justified when it would make things a little easier and look better - but, of course, happy to be overruled!

Copy link
Member

Choose a reason for hiding this comment

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

What if we use the TextareaAutosize component which will automatically resize to show the text if it's more lines? Will that resolve your height concerns?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think the trouble then emerges if some users have a lot of code and would need to scroll to the bottom for the "Save" button even to make a tiny change, which means it'd probably be necessary to have a max-height on that too (plus it still leaves a lot of space!).

Copy link
Member

Choose a reason for hiding this comment

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

Okay, let's go with what you suggested for now. We can always reconsider and change with TextareaAutosize at a later time. Thanks for considering it 👍

client/my-sites/site-settings/header-code/style.scss Outdated Show resolved Hide resolved
client/my-sites/site-settings/index.js Show resolved Hide resolved
client/my-sites/site-settings/site-tools/index.jsx Outdated Show resolved Hide resolved
@tyxla
Copy link
Member

tyxla commented Jan 10, 2024

Another thing: when the Jetpack PR gets landed, and Jetpack gets released with it, there will still be users who use the old Jetpack version. Once that happens, we might need a Jetpack version check here that ensure that we load and display this UI only when the API is supported by the current Jetpack version.

@Aurorum
Copy link
Contributor Author

Aurorum commented Jan 10, 2024

Thanks for another round of great feedback @tyxla! 🙌 Should be addressed now.

Not to worry about the Jetpack version check - very much got that in mind, but just waiting to see which Jetpack release the endpoint will be included in. :)

@tyxla
Copy link
Member

tyxla commented Jan 10, 2024

Not to worry about the Jetpack version check - very much got that in mind, but just waiting to see which Jetpack release the endpoint will be included in. :)

It's important to keep in mind, because AFAIK we officially support "Jetpack's current version - 1", meaning that once the Jetpack API changes are released, we'll still need to support the previous version of Jetpack and not display this field. Alternatively, we could land this one on the next release after the one with the API. Then, no additional checks would be needed. Let me know if that makes sense.

@Aurorum
Copy link
Contributor Author

Aurorum commented Jan 10, 2024

Got it! I was intending to use versionCompare when the Jetpack PR lands (see this PR's description) but happy to add something now and change the value depending on how the Jetpack PR progresses.

@tyxla
Copy link
Member

tyxla commented Jan 10, 2024

This looks pretty good @Aurorum, thank you for the great work 🙌 🚀

Other than the Jetpack version concerns, I think this will be good to go.

I'm happy to do a last round of review once the corresponding Jetpack API change is released and you take the version into consideration - let me know and I'll re-review and help you with shipping it.

@tyxla
Copy link
Member

tyxla commented Jan 10, 2024

Got it! I was intending to use versionCompare when the Jetpack PR lands (see this PR's description) but happy to add something now and change the value depending on how the Jetpack PR progresses.

No need to add it now. It can wait until after the Jetpack release that contains the API additions.

@Aurorum
Copy link
Contributor Author

Aurorum commented Jan 10, 2024

Thanks so much @tyxla - very much appreciated! I'll give you a ping once the Jetpack PR lands and I've added a version check here. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Atomic Sites: Add a Built-In Method to Put Code In Header
4 participants