Automattic / jetpack

Security, performance, marketing, and design tools — Jetpack is made by WordPress experts to make WP sites safer and faster, and help you grow your traffic.
https://jetpack.com/
Other
1.58k stars 797 forks source link

Blocks: Membership Endpoint Request WordPress.com Connection in Editor #39308

Closed BrookeDot closed 5 days ago

BrookeDot commented 1 week ago

Impacted plugin

Jetpack

What

Prevent WordPress.com Notice in Editor when no Jetpack connection is present

How

When an editor with edit_posts permissions is logged in but has not connected Jetpack visiting Post > Add New results in a message to connect Jetpack: Screenshot 2024-09-09 at 15 53 33

This appears to stem from the membership endpoint: https://example.com/wp-json/wpcom/v2/memberships/status?source=gutenberg&type=all&is_editable=true&_locale=user

My browser returns a 500 error and the following response body:

{"code":"missing_token","message":"Please connect your user account to WordPress.com","data":404}

Source: https://github.com/Automattic/jetpack/blob/trunk/projects/plugins/jetpack/_inc/lib/core-api/wpcom-endpoints/memberships.php#L243-L248

Most Jetpack blocks only ask you to connect Jetpack when they are inserted: Screenshot 2024-09-09 at 16 28 53

Alerting the editor to connect Jetpack on every page load seems a bit over zealous and if a reason is not provided as to why, the alert seems unhelpful.

Replicate:

1) Create a Jetpack site with a primary Jetpack connection 2) Log in as an editor who is not connected to Jetpack 3) Visit Post > Add New 4) See the Connect Jetpack Message

Current Workaround

Disable Jetpack Blocks

jeherve commented 1 week ago

This seems like a bug, we shouldn't be displaying such a banner to all unconnected users. I wonder if it may be linked to the changes in #38961. @arthur791004 Could you take a look when you get the chance?

millerf commented 1 week ago

Is there any way to disable those blocks when no connection is present, to prevent users to insert them altogether?

jeherve commented 1 week ago

Yes, that may be one way around the issue. We could add a connection check before we register the block here, e.g.: https://github.com/Automattic/jetpack/blob/a6c16b2318275f612c91151c759b5d3bfd9767e5/projects/plugins/jetpack/extensions/blocks/donations/donations.php#L22

We do that for other blocks, like here for example: https://github.com/Automattic/jetpack/blob/7066fdb12e42d56fb88097e3d69beb1cd4e02eef/projects/plugins/jetpack/extensions/blocks/subscriptions/subscriptions.php#L48-L51

millerf commented 1 week ago

Created https://github.com/Automattic/jetpack/pull/39315 (WiP until tests pass)

@BrookeDot it would be great if you could test the PR on your site...

BrookeDot commented 6 days ago

This seems like a bug

I was on the fence if this was an enhancement or a bug, while nothing was "broken" I did find that the user experience could be improved so I agree with the reclassification as a bug.

@BrookeDot it would be great if you could test the PR on your site...

Sounds good, either I or someone on WPVIP will be able to test this out and comment if the PR works as expected here in the next few days.