-
Notifications
You must be signed in to change notification settings - Fork 10.7k
Add the WooCommerce features engine #34616
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
Add the WooCommerce features engine #34616
Conversation
…e new features controller.
Aslo make the FeaturesUtil::declare_compatibility method require a plugin file path instead of directly a plugin name.
Test Results SummaryCommit SHA: 9b922e2
To view the full E2E test report, click here. To view all test reports, visit the WooCommerce Test Reports Dashboard. |
vedanshujain
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great work as always! I have added couple of minor comments.
plugins/woocommerce/src/Internal/DataStores/Orders/CustomOrdersTableController.php
Outdated
Show resolved
Hide resolved
vedanshujain
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! Subjected to CI passing
…bility-declaration
…bility-declaration
|
Note that some API tests are failing, but I manually verified and they seem to be working fine. |
|
Hi @Konamiman, thanks for merging this pull request. Please take a look at these follow-up tasks you may need to perform:
|
This reverts commit f65c775.
All Submissions:
Changes proposed in this Pull Request:
Background
In this context we define a feature as a major piece of the WooCommerce functionality that can be turned on or off via code API or via admin UI. Each feature has a unique alphanumeric identifier and a standardized name for the option that turns it on or off:
woocommerce_feature_{id}_enabled(the value of the option is eitheryesornolike any other settings related option).A feature can be mature or experimental, the later means that the feature either is still in development or is part of an experiment that could end up being successful or not; so the idea is that ultimately all the features that at one point are marked experimental eventually either become mature or are removed.
WooCommerce plugins may declare positive compatibility or negative compatibility with any of the existing features. Positive means that to the best of the plugin authors knowledge, the plugin will continue to work as expected when the feature is enabled. Negative means that there are known issues that will arise when the plugin is used with the feature enabled.
WooCommerce had already two "features" that were provided by the Admin code: enable analytics, and enable the new navigation. In this pull request these have been repurposed as part of the new "features engine"; as an exceptional case, the old enabling option name is used for those, instead of
woocommerce_feature_{id}_enabled.New classes
This pull request introduces two new classes:
An internal
FeaturesControllerclass. This class has methods to:A public
FeaturesUtilclass with static methods that are proxies toFeaturesController.FeaturesControlleris to be retrieved via the dependency injection container as usual,FeaturesUtilcan be used directly.Declaring feature compatibility
Both
FeaturesControllerandFeaturesUtilhave adeclare_compatibilitymethod that accepts a feature id, a plugin identifier and a boolean indicating positive or negative compatibility. It's mandatory to invoke these methods from inside thebefore_woocommerce_initaction, so that by the timewoocommerce_initis fired any plugin willing to declare feature compatibility has done so already. Plugins must use the method fromFeaturesUtiland not the method fromFeaturesController.The plugin identifier to be passed to
FeaturesUtil::declare_compatibilitymust be the path of the main plugin file, this will be converted todirectory/file.phpwhich is the format used by the keys in the array returned by the WordPressget_pluginsfunction. TheFeaturesController::declare_compatibilitymethod assumes that the plugin identifier it receives is already in this format.Thus this is the snippet that a plugin can use to declare compatibility with a feature (assuming it runs from the main plugin file):
The feature settings UI
This is how the settings page for the features looks now:
At first sight it might look like the only change is the addition of the "Experimental" section, but actually the changes are deeper: now the entire settings page is rendered by the
FeaturesControllerclass, and additionally, all the rendered settings are tied to options with the formatwoocommerce_feature_{id}_enabled. The analytics and new navigation options were previously rendered by Admin code (they keep their old names for the enabling options).This new settings page is still compatible with the
woocommerce_settings_featuresfilter. Any settings added there will be rendered in the "mature" settings section, right after the built-in WooCommerce settings.Compatibility with the
woocommerce_admin_disabledfilter is also maintained. This is how the settings page will render if this filter returnstrue:Enabling the custom orders table feature
Previously the custom orders table feature had to be enabled via the
CustomOrdersTableController::show_featuremethod. This is no longer the case (the new features engine is used instead), and to make this extra clear, thatshow_featuremethod will throw an exception. This method (and the companion,hide_feature) will eventually be removed once the custom orders table feature becomes mature.Compatibility with the old Admin settings
The
FeaturesControllerclass still uses the old option names for enabling/disabling the legacy features:woocommerce_analytics_enabledfor enabling analyticswoocommerce_navigation_enabledfor enabling the new navigationThe Admin code related to the features settings page rendering has been modified: the hookings to
woocommerce_get_sections_advancedandwoocommerce_get_settings_advancedhave been removed, and the methods that were the target of those have been turned into no-ops and marked as deprecated.The feature enabled changed action
Last but not least, a new
woocommerce_feature_enabled_changedaction is introduced. This is fired whenever the enabled status for a feature changes and provides the feature id and whether it has been enabled or disabled.What's missing
Apart from the revamped settings page there are no UI changes. An indication of which plugins are compatible with which features will be introduced in a separate pull request.
Closes #34419.
How to test the changes in this Pull Request:
Compatibility with the old settings and the custom order tables feature
Go to WooCommerce - Settings - Advanced - Features and verify that enabling and disabling "Analytics" and "New navigation" continues to work as expected.
Also verify that the custom orders table feature is properly enabled and disabled from that page (a quite immediate indication is that the "Custom data stores" section appears or disappears from the same settings page).
Declaring compatibility
Create a dummy plugin and add compatibility (positive or negative) with the custom orders table, as in the snippet shown above in "Declaring feature compatibility".
From the command line, verify that you can check compatibility either by plugin name...
...or by feature id:
Others
woocommerce_settings_featuresfilter are still rendered, e.g. add the following to your dummy plugin:woocommerce_admin_disabledfilter:Other information:
pnpm changelog add --filter=<project>?FOR PR REVIEWER ONLY: