Skip to content

Subscriptions Widget: Add fallbacks for values associated with widget instance keys #44265

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

Merged

Conversation

coder-karen
Copy link
Contributor

@coder-karen coder-karen commented Jul 10, 2025

Fixes VULCAN-247

Proposed changes:

  • This PR adds fallback (default) values for values associated with widget instance keys, within the update function.
  • This prevents PHP warnings from occurring due to undefined array keys.
  • The scenario in which this was happening was from within a site creation process (Headstart), via API. However not all information is being included in this process.
  • Initially, I approached this by setting blank defaults, to display as close to expected as possible. However, if keys weren't set, this could result in missing or incomplete widget settings or unexpected display issues.
  • Now, we merge the new widget settings over the old instance, and then over the defaults, to ensure all expected keys are present while preserving any existing values not explicitly updated (including blank values). This approach prevents accidental data loss, maintains compatibility with legacy or partial configurations, and guarantees that the widget always has a complete set of settings.
  • Additionally, using defaults from within the update function is also used by several other widgets (eg. Milestone, Gallery, Instagram Widget).

Logs: e0ddd44d3db9ab1d7ef595112dce260e-logstash

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:

  • Code-review
  • You can also test that general updating works as expected. To do that, with the PR applied on a test site you'd need to install the Classic Widgets plugin. You'll need a legacy theme as well, such as Twenty Seventeen. Under Appearance > Widget, move a Blog Subscriptions widget to a widget area. The regular defaults should fill in. Remove some content and click save - updating should work as expected. Also test the checkbox to ensure it saves properly.

On Simple - presumably you'd need a site using legacy widgets (old site?), so I'm not too sure how to test that.

@coder-karen coder-karen self-assigned this Jul 10, 2025
@coder-karen coder-karen added [Type] Bug When a feature is broken and / or not performing as intended [Feature] Subscriptions All subscription-related things such as paid and unpaid, user management, and newsletter settings. [Status] In Progress labels Jul 10, 2025
Copy link
Contributor

github-actions bot commented Jul 10, 2025

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 update/subscriptions-widget-update-function-defaults branch.
  • To test on Simple, run the following command on your sandbox:
bin/jetpack-downloader test jetpack update/subscriptions-widget-update-function-defaults

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 github-actions bot added the [Plugin] Jetpack Issues about the Jetpack plugin. https://wordpress.org/plugins/jetpack/ label Jul 10, 2025
Copy link
Contributor

github-actions bot commented Jul 10, 2025

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 a "[Type]" label (Bug, Enhancement, Janitorial, Task).
  • ✅ 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: August 5, 2025
    • Code freeze: August 4, 2025

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

Copy link

jp-launch-control bot commented Jul 10, 2025

Code Coverage Summary

This PR did not change code coverage!

That could be good or bad, depending on the situation. Everything covered before, and still is? Great! Nothing was covered before? Not so great. 🤷

Full summary · PHP report · JS report

@coder-karen coder-karen marked this pull request as ready for review July 11, 2025 11:05
$instance['title'] = wp_strip_all_tags( stripslashes( $instance['title'] ) );
$instance['title_following'] = wp_strip_all_tags( stripslashes( $instance['title_following'] ) );
$instance['subscribe_logged_in'] = wp_filter_post_kses( stripslashes( $instance['subscribe_logged_in'] ) );
$instance['subscribe_button'] = wp_strip_all_tags( stripslashes( $instance['subscribe_button'] ) );
}

$instance['show_subscribers_total'] = isset( $new_instance['show_subscribers_total'] ) && $new_instance['show_subscribers_total'];
Copy link
Contributor Author

Choose a reason for hiding this comment

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

We leave the original checks here, as these are for checkboxes. Otherwise, the checkbox would always revert to the default value when unchecked, ignoring the user’s action.

@coder-karen coder-karen added [Status] Needs Review This PR is ready for review. and removed [Status] In Progress labels Jul 11, 2025
@coder-karen coder-karen requested a review from a team July 11, 2025 11:32
Copy link
Contributor

@darssen darssen left a comment

Choose a reason for hiding this comment

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

Thanks for working on this @coder-karen.

From a code review perspective, changes look good. 👍

@coder-karen coder-karen merged commit 4327540 into trunk Jul 21, 2025
67 checks passed
@coder-karen coder-karen deleted the update/subscriptions-widget-update-function-defaults branch July 21, 2025 09:26
@github-actions github-actions bot removed the [Status] Needs Review This PR is ready for review. label Jul 21, 2025
@github-actions github-actions bot added this to the jetpack/14.9 milestone Jul 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Subscriptions All subscription-related things such as paid and unpaid, user management, and newsletter settings. [Plugin] Jetpack Issues about the Jetpack plugin. https://wordpress.org/plugins/jetpack/ [Type] Bug When a feature is broken and / or not performing as intended
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants