Repository navigation
Markdown: Keep Markdown for posts off after a Jetpack update - #54940
Conversation
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>
|
Are you an Automattician? Please test your changes on all WordPress.com environments to help mitigate accidental explosions.
Interested in more tips and information?
|
|
Thank you for your PR! When contributing to Jetpack, we have a few suggestions that can help us test and review your patch:
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:
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:
If you have any questions about the release process, please ask in the #jetpack-releases channel on Slack. |
Code Coverage SummaryCoverage changed in 3 files.
Full summary · PHP report · JS report Coverage check overridden by
Covered by non-unit tests
|
|
First review pass. No blockers; two open questions for review.
Nit: the test calls the helper directly, so it does not prove |
dhasilva
left a comment
There was a problem hiding this comment.
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' ) ) { |
There was a problem hiding this comment.
[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:
| 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.
There was a problem hiding this comment.
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>
|
@dhasilva thanks. Both suggestions are in ad6b625.
The description has the trunk and branch results for all four checks, which I ran on both. — Terminator |
Fixes JETPACK-3729
Proposed changes
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.jetpack_do_after_markdown_activation()). Until now, that listener loaded only on REST requests and on the Jetpack admin page, sowp jetpack module activate markdownand the module toggle through the wpcom JSON API never turned posts on. The upgrade reset hid this. The listener now lives inmodules/markdown.php, whichModules::activate()loads before it firesjetpack_activate_module_markdown, so every activation path turns posts on. The function is guarded withfunction_exists().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:
01111110Upgrade (check 4):
wp option update wpcom_publish_posts_with_markdown 0wp eval 'Jetpack_Options::update_option( "version", "15.9:1700000000" ); delete_transient( "jetpack_upgrade_lock" );'wp eval 'echo "";'soplugin_upgrade()runs onplugins_loaded.Jetpack_Options::get_option( "version" )now shows the current version.wp option get wpcom_publish_posts_with_markdown→ trunk1, this branch0.CLI activation (check 1):
wp jetpack module deactivate markdown && wp option update wpcom_publish_posts_with_markdown 0wp jetpack module activate markdownwp option get wpcom_publish_posts_with_markdown→ trunk0, this branch1.REST toggle (check 2), the endpoint behind the Jetpack Settings module toggle:
wp jetpack module deactivate markdown && wp option update wpcom_publish_posts_with_markdown 0wp 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();'→200wp option get wpcom_publish_posts_with_markdown→1on both.Check 3 is the same request after
Jetpack::deactivate_module( "markdown" )in the samewp eval, somodules/markdown.phpand 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).