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

WP.com API: Allow Users to Insert Header Code #34881

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

Conversation

Aurorum
Copy link
Contributor

@Aurorum Aurorum commented Jan 6, 2024

Required for Automattic/wp-calypso#86079

Proposed changes:

  • This adds an endpoint that ultimately allows users to include Header code on their site.

I thought about adding a separate endpoint like Custom CSS in case it handles a large amount of code, but I decided against it for a few reasons: realistically, I think this will mainly be used for a couple of meta tags; the endpoint already handles large amounts of data (including subscription email HTML and post categories!) and this isn't any larger relative to those, and also I don't think I can add another endpoint on the Calypso side since that's not open-source.

Jetpack product discussion

See Automattic/wp-calypso#56023.

Does this pull request change what data or activity we track or use?

No.

Testing instructions:

I always need help testing endpoints. :) I haven't actually been able to do this from an Atomic site, but I have from a Jetpack one.

  1. Load the Calypso PR and navigate to /settings/header-code/site
  2. Include some header code
  3. Confirm that it's run when you load the site

For example - saving this on the Calypso side:
Screenshot 2024-01-06 at 15 26 22

Should lead to this:
Screenshot 2024-01-06 at 15 47 13

@github-actions github-actions bot added [Feature] WPCOM API [Plugin] Jetpack Issues about the Jetpack plugin. https://wordpress.org/plugins/jetpack/ labels Jan 6, 2024
Copy link
Contributor

github-actions bot commented Jan 6, 2024

Thank you for your PR!

When contributing to Jetpack, we have a few suggestions that can help us test and review your patch:

  • ✅ Include a description of your PR changes.
  • ✅ Add testing instructions.
  • ✅ Specify whether this PR includes any changes to data or privacy.
  • ✅ Add changelog entries to affected projects

This comment will be updated as you work on your PR and make changes. If you think that some of those checks are not needed for your PR, please explain why you think so. Thanks for cooperation 🤖


The e2e test report can be found here. Please note that it can take a few minutes after the e2e tests checks are complete for the report to be available.



Jetpack plugin:

The Jetpack plugin has different release cadences depending on the platform:

  • WordPress.com Simple releases happen daily.
  • WoA releases happen weekly.
  • Releases to self-hosted sites happen monthly. The next release is scheduled for February 6, 2024 (scheduled code freeze on February 5, 2024).

If you have any questions about the release process, please ask in the #jetpack-releases channel on Slack.

@github-actions github-actions bot added the OSS Citizen This Pull Request was opened by an Open Source contributor. label Jan 6, 2024
}

if ( ! empty( $option ) && ! is_admin() ) {
echo wp_unslash( $option, 'post' ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
Copy link
Contributor Author

Choose a reason for hiding this comment

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

What's the best way of handling escaping for something like this? I wasn't quite sure.

Copy link
Contributor

Choose a reason for hiding this comment

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

In theory, probably some form of wp_kses(). But since the intent of this is to allow for <script> tags there doesn't seem much point in bothering, since if script tags are allowed an attacker able to set this option could do anything they want anyway.

Pointing that out in a comment might be helpful.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks, will do!

@anomiex anomiex added the [Status] Needs Review To request a review from Crew. Label will be renamed soon. label Jan 8, 2024
@@ -1115,6 +1116,13 @@ function ( $category_id ) {

break;

case 'jetpack_header_code':
if ( update_option( $key, $value ) ) {
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 perform any safety checks on save? Are we good with any input without any verification?

Copy link
Contributor Author

@Aurorum Aurorum Jan 10, 2024

Choose a reason for hiding this comment

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

Are we good with any input without any verification?

I think so, but happy to be corrected if I'm missing anything obvious. It also seems consistent with what the other options do.

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.

It also may be worth discussing if this field should have a UI in Jetpack, or if it's enough to have it in WP.com.

@Aurorum
Copy link
Contributor Author

Aurorum commented Jan 10, 2024

Would someone from Jetpack mind checking for a product review decision on that? Happy to include some UI if it's something which Jetpack folks would be keen on.

@jeherve
Copy link
Member

jeherve commented Jan 10, 2024

Would someone from Jetpack mind checking for a product review decision on that? Happy to include some UI if it's something which Jetpack folks would be keen on.

That is definitely something we would need to discuss before we move forward. I'll comment on the original issue so we can continue this discussion.
Automattic/wp-calypso#56023 (comment)

@jeherve jeherve added [Status] Blocked / Hold [Status] Needs Product Review Consider posting about this on an internal P2 for discussion and removed [Status] Needs Review To request a review from Crew. Label will be renamed soon. labels Jan 10, 2024
Copy link
Contributor

This PR has been marked as stale. This happened because:

  • It has been inactive for the past 3 months.
  • It hasn’t been labeled `[Pri] BLOCKER`, `[Pri] High`, etc.

If this PR is still useful, please do a [trunk merge or rebase](https://github.com/Automattic/jetpack/blob/trunk/docs/git-workflow.md#keeping-your-branch-up-to-date) and otherwise make sure it's up to date and has clear testing instructions. You may also want to ping possible reviewers in case they've forgotten about it. Please close this PR if you think it's not valid anymore — if you do, please add a brief explanation.

If the PR is not updated (or at least commented on) in another month, it will be automatically closed.

@Aurorum
Copy link
Contributor Author

Aurorum commented Apr 10, 2024

I still feel this PR is useful! But also still awaiting a product review…wonder if it might be possible to get a decision on that?

Copy link
Contributor

This PR has been marked as stale. This happened because:

  • It has been inactive for the past 3 months.
  • It hasn’t been labeled `[Pri] BLOCKER`, `[Pri] High`, etc.

If this PR is still useful, please do a [trunk merge or rebase](https://github.com/Automattic/jetpack/blob/trunk/docs/git-workflow.md#keeping-your-branch-up-to-date) and otherwise make sure it's up to date and has clear testing instructions. You may also want to ping possible reviewers in case they've forgotten about it. Please close this PR if you think it's not valid anymore — if you do, please add a brief explanation.

If the PR is not updated (or at least commented on) in another month, it will be automatically closed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] WPCOM API OSS Citizen This Pull Request was opened by an Open Source contributor. [Plugin] Jetpack Issues about the Jetpack plugin. https://wordpress.org/plugins/jetpack/ [Status] Blocked / Hold [Status] Needs Product Review Consider posting about this on an internal P2 for discussion [Status] Stale
4 participants