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

MU WPCOM: Disable the Open Graph Tags according to the privacy of the site #39012

Merged
merged 10 commits into from
Sep 2, 2024

Conversation

arthur791004
Copy link
Contributor

@arthur791004 arthur791004 commented Aug 22, 2024

Fixes Automattic/wp-calypso#92385

Proposed changes:

  • Add filter to disable the action to print OG tags by either Jetpack or YoastSEO

Other information:

  • Have you written new tests for your changes, if applicable?
  • Have you checked the E2E test CI results, and verified that your changes do not break them?
  • Have you tested your changes on WordPress.com, if applicable (if so, you'll see a generated comment below with a script to run)?

Jetpack product discussion

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

Testing instructions:

  • Apply changes as below
    • On simple sites, apply changes to wpcom and sandbox your site
    • On atomic sites, apply changes to your site directly
  • Go to https://wordpress.com/settings/general/:site
  • Set the Privacy to one of the below
    • Coming Soon
    • Public & Prevent third-party sharing
  • Open your site with the Incognito mode
  • Make sure the OG tags are removed
  • If your site is an atomic site, then install YoastSEO and make sure the OG tags of YoastSEO are removed either

Copy link
Contributor

github-actions bot commented Aug 22, 2024

Are you an Automattician? Please test your changes on all WordPress.com environments to help mitigate accidental explosions.

  • To test on WoA, go to the Plugins menu on a WordPress.com Simple site. Click on the "Upload" button and follow the upgrade flow to be able to upload, install, and activate the Jetpack Beta plugin. Once the plugin is active, go to Jetpack > Jetpack Beta, select your plugin, and enable the feat/disable-seo-tag-by-privacy branch.

    • For jetpack-mu-wpcom changes, also add define( 'JETPACK_MU_WPCOM_LOAD_VIA_BETA_PLUGIN', true ); to your wp-config.php file.
  • To test on Simple, run the following command on your sandbox:

    bin/jetpack-downloader test jetpack-mu-wpcom-plugin feat/disable-seo-tag-by-privacy
    

Interested in more tips and information?

  • In your local development environment, use the jetpack rsync command to sync your changes to a WoA dev blog.
  • Read more about our development workflow here: PCYsg-eg0-p2
  • Figure out when your changes will be shipped to customers here: PCYsg-eg5-p2

Copy link
Contributor

github-actions bot commented Aug 22, 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 a "[Status]" label (In Progress, Needs Team Review, ...).
  • ✅ 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.


Follow this PR Review Process:

  1. Ensure all required checks appearing at the bottom of this PR are passing.
  2. Choose a review path based on your changes:
    • A. Team Review: add the "[Status] Needs Team Review" label
      • For most changes, including minor cross-team impacts.
      • Example: Updating a team-specific component or a small change to a shared library.
    • B. Crew Review: add the "[Status] Needs Review" label
      • For significant changes to core functionality.
      • Example: Major updates to a shared library or complex features.
    • C. Both: Start with Team, then request Crew
      • For complex changes or when you need extra confidence.
      • Example: Refactor affecting multiple systems.
  3. Get at least one approval before merging.

Still unsure? Reach out in #jetpack-developers for guidance!

@github-actions github-actions bot added the [Status] Needs Author Reply We would need you to make some changes or provide some more details about your PR. Thank you! label Aug 22, 2024
@arthur791004 arthur791004 force-pushed the feat/disable-seo-tag-by-privacy branch from dfd3ef7 to a272555 Compare August 22, 2024 04:56
@arthur791004 arthur791004 self-assigned this Aug 22, 2024
@arthur791004 arthur791004 force-pushed the feat/disable-seo-tag-by-privacy branch from a272555 to ea68063 Compare August 22, 2024 13:01
@arthur791004 arthur791004 requested a review from a team August 22, 2024 13:03
@arthur791004 arthur791004 added [Status] Needs Team Review and removed [Status] Needs Author Reply We would need you to make some changes or provide some more details about your PR. Thank you! labels Aug 22, 2024
@taipeicoder
Copy link
Contributor

Coming soon:

  • Without Yoast SEO - I still see the OG tags.
  • With Yoast SEO - No OG tags.

Public & Prevent third-party sharing:

  • Without Yoast SEO - I still see the OG tags.
  • With Yoast SEO - No OG tags.

@taipeicoder
Copy link
Contributor

taipeicoder commented Aug 23, 2024

jetpack_og_tags seems to be undefined, maybe it hasn't been declared yet? 😕

@fushar
Copy link
Contributor

fushar commented Aug 23, 2024

Maybe we should merge this first? Not sure if it's a dependency

@arthur791004
Copy link
Contributor Author

jetpack_og_tags seems to be undefined, maybe it hasn't been declared yet? 😕

I found you have to enable either publicize or sharedaddy module to see the feature

@arthur791004
Copy link
Contributor Author

Without Yoast SEO - I still see the OG tags.

It should be resolved by 4fe84c6

@arthur791004 arthur791004 force-pushed the feat/disable-seo-tag-by-privacy branch 2 times, most recently from 0c3aae8 to 960f993 Compare August 26, 2024 01:59
taipeicoder
taipeicoder previously approved these changes Aug 26, 2024
Copy link
Contributor

@taipeicoder taipeicoder left a comment

Choose a reason for hiding this comment

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

Coming soon:

  • ✅ Without Yoast SEO - No OG tags.
  • ✅ With Yoast SEO - No OG tags.

Public & Prevent third-party sharing:

  • ✅ Without Yoast SEO - No OG tags.
  • ✅ With Yoast SEO - No OG tags.

@arthur791004 arthur791004 force-pushed the feat/disable-seo-tag-by-privacy branch from 960f993 to 085b381 Compare August 26, 2024 02:50
@arthur791004 arthur791004 added the [Status] Needs Review To request a review from fellow Jetpack developers. Label will be renamed soon. label Aug 26, 2024
@arthur791004 arthur791004 requested a review from mdawaffe August 26, 2024 06:06
Copy link
Member

@mdawaffe mdawaffe left a comment

Choose a reason for hiding this comment

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

I wonder if wpcom_public_coming_soon has other implications that Jetpack should be aware of or take into account itself. I don't think that's a blocker for this PR.

I think you should get a review from someone on a Jetpack team for this, though. It's been a while since I've been well-informed enough to have a trustworthy opinion :)

* Disable the Open Graph Tags based on the value of either wpcom_public_coming_soon and wpcom_data_sharing_opt_out option.
*/
function remove_og_tags() {
if ( ! (bool) get_option( 'wpcom_public_coming_soon' ) && ! (bool) get_option( 'wpcom_data_sharing_opt_out' ) ) {
Copy link
Member

Choose a reason for hiding this comment

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

I don't think wpcom_data_sharing_opt_out is the right thing to check here. We don't, for example, turn off search engine access or social media expanded links if that setting is true.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The value of wpcom_data_sharing_opt_out is true when the Prevent third-party sharing for your site is checked. As a result, I think it would be better to avoid sharing on social media as well.

Copy link
Member

Choose a reason for hiding this comment

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

The third parties relevant for this option are Automattic's partners, not social media sites users share their content to. As described in the UI:

This option will prevent this [public] site’s content from being shared with our licensed network of content and research partners, including those that train AI models.

So turning off OG tags for public sites is outside of the original intent of this setting. I don't think the intent of this setting should expand to include social sharing. If you disagree, could you please make the case in a P2 discussion to get more perspectives involved?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Will limit the changes to the Coming Soon 🙂

Copy link
Member

Choose a reason for hiding this comment

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

Cool - thanks! Looks like the comment in the lines above needs updating too.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh thanks! Updated 👍

@arthur791004 arthur791004 requested a review from jeherve August 27, 2024 01:43
@arthur791004
Copy link
Contributor Author

I wonder if wpcom_public_coming_soon has other implications that Jetpack should be aware of or take into account itself. I don't think that's a blocker for this PR.

I think we can simply focus on the OG tags in this PR to limit the scope 🙂

@arthur791004 arthur791004 force-pushed the feat/disable-seo-tag-by-privacy branch from 085b381 to 365f8da Compare August 28, 2024 02:45
Comment on lines 74 to 85
if ( function_exists( 'jetpack_og_tags' ) ) {
// @phan-suppress-next-line PhanUndeclaredFunctionInCallable
remove_action( 'wp_head', 'jetpack_og_tags' );
}

// Avoid calling check_open_graph as it registers the jetpack_og_tags function when running wp_head action.
// @phan-suppress-next-line PhanUndeclaredClassInCallable
if ( class_exists( '\Jetpack', false ) && is_callable( 'Jetpack::init' ) ) {
// @phan-suppress-next-line PhanUndeclaredClassMethod
$jetpack = \Jetpack::init();
remove_action( 'wp_head', array( $jetpack, 'check_open_graph' ), 1 );
}
Copy link
Member

Choose a reason for hiding this comment

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

Would it be an option to simplify this logic and just force the Open Graph off with the jetpack_enable_open_graph filter?

I haven't tested but I would expect something like this to work (maybe with some priority changes?)

Suggested change
if ( function_exists( 'jetpack_og_tags' ) ) {
// @phan-suppress-next-line PhanUndeclaredFunctionInCallable
remove_action( 'wp_head', 'jetpack_og_tags' );
}
// Avoid calling check_open_graph as it registers the jetpack_og_tags function when running wp_head action.
// @phan-suppress-next-line PhanUndeclaredClassInCallable
if ( class_exists( '\Jetpack', false ) && is_callable( 'Jetpack::init' ) ) {
// @phan-suppress-next-line PhanUndeclaredClassMethod
$jetpack = \Jetpack::init();
remove_action( 'wp_head', array( $jetpack, 'check_open_graph' ), 1 );
}
add_filter( 'jetpack_enable_open_graph', '__return_false' );

If that works, I wouldn't be surprised if Yoast SEO offered a similar filter allowing one to shortcircuit their implementation.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The check_open_graph function would register the hook to turn on the open graph if certain modules are active so I'm not sure whether it's okay to do that.

However, after re-reading the code, the function also adds the following filter to turn off the open graph if there is any conflict plugin. So, I think I can simply add the same filter.

add_filter( 'jetpack_enable_open_graph', '__return_false', 99 );

If that works, I wouldn't be surprised if Yoast SEO offered a similar filter allowing one to shortcircuit their implementation.

The current way is recommended by https://developer.yoast.com/customization/yoast-seo/disabling-yoast-seo/. We can simply remove all actions for wpseo_head but I think it would be better to follow the official suggestion. Does it make sense?

Copy link
Member

Choose a reason for hiding this comment

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

but I think it would be better to follow the official suggestion

Yeah, definitely!

@arthur791004 arthur791004 force-pushed the feat/disable-seo-tag-by-privacy branch from 5b3452a to 9d379fa Compare August 28, 2024 14:04
@arthur791004 arthur791004 requested a review from a team September 2, 2024 02:29
Copy link
Contributor

@taipeicoder taipeicoder left a comment

Choose a reason for hiding this comment

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

Re-tested and LGTM 👍

@arthur791004 arthur791004 merged commit 368bf10 into trunk Sep 2, 2024
55 checks passed
@arthur791004 arthur791004 deleted the feat/disable-seo-tag-by-privacy branch September 2, 2024 07:52
@github-actions github-actions bot removed [Status] Needs Team Review [Status] Needs Review To request a review from fellow Jetpack developers. Label will be renamed soon. labels Sep 2, 2024
gogdzl pushed a commit that referenced this pull request Oct 25, 2024
… site (#39012)

* MU WPCOM: Disable the Open Graph Tags according to the privacy of the site

* changelog

* Fix lint

* Fix typo

* Remove Jetpack OG only when the feature is enabled

* Fix Jetpack OG

* Fix lint

* Remove OG tags only when the site is configured to Coming Soon

* Update comment

* Add filter to turn of Jetpack Open Graph Tags
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.

Remove OpenGraph metadata tags from "Coming Soon" sites
5 participants