Skip to content

Markdown: Keep Markdown for posts off after a Jetpack update - #54940

Merged
CGastrell merged 2 commits into
trunkfrom
fix/markdown-posts-reset-on-upgrade
Nov 16, 2026
Merged

CGastrell merged 2 commits into
trunkfrom
fix/markdown-posts-reset-on-upgrade

Conversation

@CGastrell

@CGastrell CGastrell commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

Fixes JETPACK-3729

Proposed changes

  • On every Jetpack version change, Jetpack::plugin_upgrade() turned "Markdown for posts" (wpcom_publish_posts_with_markdown) back on, so a site that had turned it off got it back after each update.
  • That reset came from Markdown: enable for posts whenever the module is active. #6608 (Jetpack 4.7.1), a one-time fix for sites whose option was off after Endpoints: allow to toggle Markdown for posts independent of comments #6406 stopped forcing it on in 4.7. It never had a version check. Every site on 4.7.1 or later already got it, so this PR deletes it.
  • Turning the Markdown module on turns "Markdown for posts" on (jetpack_do_after_markdown_activation()). Until now, that listener loaded only on REST requests and on the Jetpack admin page, so wp jetpack module activate markdown and the module toggle through the wpcom JSON API never turned posts on. The upgrade reset hid this. The listener now lives in modules/markdown.php, which Modules::activate() loads before it fires jetpack_activate_module_markdown, so every activation path turns posts on. The function is guarded with function_exists().
  • Calypso's Writing toggle writes the option itself and does not change.
  • Remaining case: a site where Markdown was activated by CLI or the wpcom JSON API since its last update, and posts were never turned on, stays off until someone turns it on in the Markdown settings panel.

Related product discussion/links

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

No.

Testing instructions

Run by the author on a local Docker site, on trunk and on this branch with the same script:

Check (posts off before each) Trunk This branch
1. CLI activation 0 1
2. REST toggle, Markdown inactive at page load 1 1
3. REST toggle, Markdown active at page load 1 1
4. Upgrade from 15.9 1 0

Upgrade (check 4):

  1. wp option update wpcom_publish_posts_with_markdown 0
  2. Pretend the site is upgrading from 15.9: wp eval 'Jetpack_Options::update_option( "version", "15.9:1700000000" ); delete_transient( "jetpack_upgrade_lock" );'
  3. Run wp eval 'echo "";' so plugin_upgrade() runs on plugins_loaded. Jetpack_Options::get_option( "version" ) now shows the current version.
  4. wp option get wpcom_publish_posts_with_markdown → trunk 1, this branch 0.

CLI activation (check 1):

  1. wp jetpack module deactivate markdown && wp option update wpcom_publish_posts_with_markdown 0
  2. wp jetpack module activate markdown
  3. wp option get wpcom_publish_posts_with_markdown → trunk 0, this branch 1.

REST toggle (check 2), the endpoint behind the Jetpack Settings module toggle:

  1. wp jetpack module deactivate markdown && wp option update wpcom_publish_posts_with_markdown 0
  2. wp eval 'wp_set_current_user( 1 ); do_action( "rest_api_init" ); $r = new WP_REST_Request( "POST", "/jetpack/v4/module/markdown/active" ); $r->set_param( "active", true ); echo rest_do_request( $r )->get_status();' → 200
  3. wp option get wpcom_publish_posts_with_markdown → 1 on both.

Check 3 is the same request after Jetpack::deactivate_module( "markdown" ) in the same wp eval, so modules/markdown.php and the endpoints file both load in one request. No fatal.

No unit test: the upgrade block is deleted, and the activation path is covered by the manual checks above. jetpack docker phpunit jetpack -- --filter='Jetpack_Core_Api_Module|Markdown' passes (81 tests).

The upgrade turned wpcom_publish_posts_with_markdown back on at every
version change. It was a one-time fix for sites upgrading to 4.7, so it
now runs only for upgrades from before 4.7.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@CGastrell CGastrell added Bug When a feature is broken and / or not performing as intended [Feature] Markdown [Status] Needs Review This PR is ready for review. [Plugin] Jetpack Issues about the Jetpack plugin. https://wordpress.org/plugins/jetpack/ labels Nov 13, 2026
@CGastrell CGastrell self-assigned this Nov 13, 2026
@github-actions

github-actions Bot commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

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 WoA dev 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 (Jetpack), and enable the fix/markdown-posts-reset-on-upgrade branch.
  • To test on Simple, run the following command on your sandbox:
bin/jetpack-downloader test jetpack fix/markdown-posts-reset-on-upgrade

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

@github-actions

Copy link
Copy Markdown
Contributor

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 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 🤖


Follow this PR Review Process:

  1. Ensure all required checks appearing at the bottom of this PR are passing.
  2. Make sure to test your changes on all platforms that it applies to. You're responsible for the quality of the code you ship.
  3. You can use GitHub's Reviewers functionality to request a review.
  4. When it's reviewed and merged, you will be pinged in Slack to deploy the changes to WordPress.com simple once the build is done.

If you have questions about anything, reach out in #jetpack-developers for guidance!


Jetpack plugin:

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

  • WordPress.com Simple releases happen as soon as you deploy your changes after merging this PR (PCYsg-Jjm-p2).
  • WoA releases happen weekly.
  • Releases to self-hosted sites happen monthly:
    • Scheduled release: December 8, 2026
    • Code freeze: December 7, 2026

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

@jp-launch-control

jp-launch-control Bot commented Nov 13, 2026 •

Copy link
Copy Markdown

Code Coverage Summary

Coverage changed in 3 files.

File Coverage Δ% Δ Uncovered
projects/plugins/jetpack/modules/markdown.php 0/10 (0.00%) 0.00% 3 ❤️‍🩹
projects/plugins/jetpack/_inc/lib/core-api/class.jetpack-core-api-module-endpoints.php 340/881 (38.59%) -0.03% -1 💚
projects/plugins/jetpack/class.jetpack.php 937/2372 (39.50%) 0.03% -2 💚

Full summary · PHP report · JS report

Coverage check overridden by Covered by non-unit tests Use to ignore the Code coverage requirement check when E2Es or other non-unit tests cover the code .

@CGastrell

Copy link
Copy Markdown
Contributor Author

First review pass. No blockers; two open questions for review.

  1. Sites lose the upgrade's side effect. Only jetpack_do_after_markdown_activation() (_inc/lib/core-api/class.jetpack-core-api-module-endpoints.php) turns "Markdown for posts" on when the module activates, and that file loads only on REST requests and the Jetpack admin page. A module turned on another way (wp jetpack module activate markdown, or from Calypso through the wpcom JSON API) never writes the option, so posts stay off. Until now, the next Jetpack update turned it on; with this PR it stays off. We can't heal only the "never set" case: update_option( $key, false ) on a missing option stores nothing, so "never set" and "turned off" look the same. Options: accept it and say so in the description, or register the activation hook where every activation path fires it.
  2. Delete the block instead of adding a public method? Every site on 4.7 or later already got the one-time reset, so the version check only helps a site jumping from 4.6 (2017) straight to 16.x. Jetpack::enable_markdown_for_posts_after_upgrade() is new public API we would have to deprecate later. Deleting the three lines is simpler; the cost is the unit test (nothing left to test, so "Covered by non-unit tests" plus the manual steps).

Nit: the test calls the helper directly, so it does not prove plugin_upgrade() passes $version; the description explains why (plugin_upgrade()'s upgrade lock).

@dhasilva dhasilva left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I reviewed f0dcc5c. There are no blockers. I left one suggestion inline, and my answers to your two open questions are below. CI is green, including PHP tests on 7.4 through 8.6. I didn't rerun the test or try the change on a site.

Q2: delete the block or keep it? I'd delete it. The version check now helps only a site that jumps from a 2017 release straight to 16.x. Such a site ends up with the module on and posts off, which the new Markdown panel shows and can switch on. Keeping the block adds a public method on Jetpack that would need _deprecated_function() later. If you keep it, the check is one release too early (see inline).

Q1: activations that never write the option. This is real, but fewer paths are affected than "every activation outside REST". Calypso's Writing toggle writes the option itself (site settings endpoint). That leaves wp jetpack module activate markdown and the module toggle sent through the wpcom JSON API. Both go through Modules::activate(), which fires jetpack_activate_module_markdown from update_active() (L597). The only listener is added in class.jetpack-core-api-module-endpoints.php, and that file loads only on rest_api_init and on the Jetpack admin page.

activate() loads the module file with require_once (L473) before it calls update_active() (L476). So moving the listener into modules/markdown.php covers every path. I'd do that in this PR, because this PR removes the reset on the next update that those activations relied on. After the move, deleting the block costs nothing for new activations. A site activated that way since its last update stays off until someone turns it on in the panel.

Generated by Claude.

* @return void
*/
public static function enable_markdown_for_posts_after_upgrade( $previous_version ) {
if ( version_compare( $previous_version, '4.7', '<' ) && ! get_option( 'wpcom_publish_posts_with_markdown' ) ) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

[suggestion] The reset this check keeps first shipped in 4.7.1, not 4.7. In 4.6, a pre_option_ filter in modules/markdown.php forced posts on. 4.7 removed that filter (#6406) without adding a reset, so plugin_upgrade() in the 4.7 tag doesn't have these lines. #6608 added them in 4.7.1: that is its milestone, and the lines are in the 4.7.1 tag. So 4.7.0 is the release that left sites with posts off, and < '4.7' skips exactly those sites. If you keep the block:

Suggested change
if ( version_compare( $previous_version, '4.7', '<' ) && ! get_option( 'wpcom_publish_posts_with_markdown' ) ) {
if ( version_compare( $previous_version, '4.7.1', '<' ) && ! get_option( 'wpcom_publish_posts_with_markdown' ) ) {

In the test, the 'from 4.7' row would then expect true, and a new 'from 4.7.1' row would expect false. The test name, the docblock above and the PR description ("#6608 (Jetpack 4.7)") would change to 4.7.1 too. I'd still delete the block instead (see the review summary).

Generated by Claude.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Confirmed against the tags: the reset is in 4.7.1 and not in 4.7. Moot now, because ad6b625 deletes the block. The description says 4.7.1.

— Terminator

…tion path

Every site on 4.7.1 or later already got the one-time reset, so delete it instead of adding a version check. Move the activation listener into modules/markdown.php, which Modules::activate() loads before it fires the hook, so CLI and wpcom JSON API activations turn posts on too. Guard the function with function_exists().

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@CGastrell CGastrell added the Covered by non-unit tests Use to ignore the Code coverage requirement check when E2Es or other non-unit tests cover the code label Nov 16, 2026
@CGastrell

Copy link
Copy Markdown
Contributor Author

@dhasilva thanks. Both suggestions are in ad6b625.

  • Q2: The upgrade block, the new public method and its unit test are deleted.
  • Q1: jetpack_do_after_markdown_activation() now lives in modules/markdown.php, guarded with function_exists(). I checked the load order you described. On a local site, wp jetpack module activate markdown now turns posts on (trunk: off). The REST toggle still turns posts on, with no fatal when both files load in one request.

The description has the trunk and branch results for all four checks, which I ran on both.

— Terminator

@CGastrell
CGastrell merged commit 05d7511 into trunk Nov 16, 2026
96 checks passed
@CGastrell
CGastrell deleted the fix/markdown-posts-reset-on-upgrade branch November 16, 2026 16:11
@github-actions github-actions Bot added [Status] UI Changes Add this to PRs that change the UI so documentation can be updated. and removed [Status] Needs Review This PR is ready for review. labels Nov 16, 2026
@github-actions github-actions Bot added this to the jetpack/16.5 milestone Nov 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Bug When a feature is broken and / or not performing as intended Covered by non-unit tests Use to ignore the Code coverage requirement check when E2Es or other non-unit tests cover the code [Feature] Markdown [Plugin] Jetpack Issues about the Jetpack plugin. https://wordpress.org/plugins/jetpack/ [Status] UI Changes Add this to PRs that change the UI so documentation can be updated. [Tests] Includes Tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants