A customizable, open-source ecommerce platform built on WordPress. Build any commerce solution you can imagine.
Go to file
Nestor Soriano 5a11d9e064
Refactor the settings pages, and add unit tests for them.
This commit fixes some inconsistencies in the settings pages, and
makes all the existing pages extensible by adding new sections
(that was possible in some pages, but not in others). Main changes:

1. Modify the 'get_sections' method so that it invokes a new protected
   'get_own_sections' method and then triggers the
   'woocommerce_get_sections_' . id filter.

This way the filter is triggered only in the base class
and not in each of the derived classes too.

2. Change the get_settings() method so that it has its signature
   changed to get_settings( $current_section = '' )
   in the base class and in all the derived class.

Some derived classes were already using this signature, but others
(those not having multiple sections natively) weren't, making then
effectively impossible to define multiple sections for these pages
via filters.

With this change all the section pages act consistently and allow
both adding new settings to the default "General" section
and creating new sections via filters.

3. Change the implementation of 'get_settings' in the base class
   so that it searches for a 'get_settings_for_{section_id}_section'
   method in the class and executes it, otherwise it executes the new
   protected method get_settings_for_section( $current_section ); then
   it triggers the 'woocommerce_get_settings_' . id filter.

This makes it easier to separate the code that returns the list
of filters in multiple methods, one per section, instead of using
one big if-else-else... block.

So now instead of overriding get_settings($current_section='') derived
classes need to implement get_settings_for_{$current_section}_section
for each section, or override get_settings_for_section($current_section)
or both. 'get_settings_for_section' returns an empty array by default.

Also, 'woocommerce_get_settings_' . id is triggered in one single
place too.

Other improvements:

* Remove duplicated code from 'output' in 'WC_Settings_Page' children.

Some classes inherited from 'WC_Settings_Page' override the 'output'
method with custom code, which in all cases ended up repeating the code
of the original method as a fallback. These repetitions have been
replaced with 'parent::output()'.

* Fix inconsistencies for 'save' and 'output' in WC_Settings_Tax/Emails

The 'WC_Settings_Tax' and 'WC_Settings_Emails' classes had some
inconsistencies in their 'save' and 'output' methods that prevented the
proper creation new sections and the addition of new settings via the
'woocommerce_get_sections_' and 'woocommerce_get_settings_' filters.
Now they work as expected.

* Deduplicate parts of 'save' in 'WC_Settings_Page' and children.

Two methods have been added to 'WC_Settings_Page' class:
'save_settings_for_current_section' and 'do_update_options_action'.
These are intended to be invoked by derived classes in their 'save'
methods, in order to remove code repetition.

* Add some helper methods to WC_Unit_Test_Case.

Methods added:
- assertOutputsHTML
- assertEqualsHTML
- normalize_html
- capture_output_from
2021-04-12 12:42:26 +02:00
.github Merge pull request #29509 from woocommerce/add/feedback-label-action 2021-04-07 22:55:20 -03:00
.wordpress-org Add new storefront screenshots 2020-08-27 12:35:35 +02:00
assets Merge pull request #29510 from woocommerce/fix/29359 2021-03-30 07:09:00 -07:00
bin Use composer 2.0+ to update files. 2021-04-05 14:31:27 +05:30
i18n Update i18n/states.php 2021-04-07 13:31:04 -03:00
includes Refactor the settings pages, and add unit tests for them. 2021-04-12 12:42:26 +02:00
lib Update dependency league/container to v3.3.5 2021-03-16 12:12:49 +00:00
packages Add note on unit tests 2019-06-26 15:17:52 +01:00
sample-data Update shopmanager display name 2019-01-16 16:01:39 +02:00
src Update default GIT branch 2021-02-25 20:51:14 -03:00
templates Bump version for template closes #29595 2021-04-06 11:37:52 -07:00
tests Refactor the settings pages, and add unit tests for them. 2021-04-12 12:42:26 +02:00
.codecov.yml Disable Codecov checks for each PR 2020-01-22 16:17:45 -03:00
.distignore Changed CHANGELOG.txt to changelog.txt 2020-08-12 16:55:08 -03:00
.editorconfig HTTPS for everybody 2016-05-26 22:48:49 -03:00
.eslintignore Ignore vendor files 2018-11-06 15:31:12 -05:00
.eslintrc.js Restore useE2EEsLintConfig const in .eslintrc.js, but pointing directly 2021-01-29 17:20:29 +01:00
.gitattributes LF line endings on checkout for PHP files 2020-08-23 11:37:58 +02:00
.gitignore gitignore unneeded eslint cache file 2021-04-05 08:20:26 -07:00
.nvmrc bump node to version 12 2020-10-27 15:05:32 -03:00
.stylelintrc Updated .stylelintrc config 2018-11-19 19:08:08 -02:00
CODE_OF_CONDUCT.md Fixed a typo 2017-06-19 16:22:40 -03:00
Gruntfile.js Only uglify the changed file when Grunt watching 2020-12-15 12:40:05 -08:00
README.md Adding hiring links to the main README 2021-03-26 08:24:19 -05:00
SECURITY.md Removed the reference to WP mobile apps. 2020-10-02 11:51:35 +02:00
changelog.txt Collapse changelogs for 5.2 beta and rc, add last minute entries 2021-04-08 16:16:50 +02:00
composer.json Update Blocks to 4.7.1 2021-04-05 12:02:48 +02:00
composer.lock Update Blocks to 4.7.1 2021-04-05 12:02:48 +02:00
lerna.json add lerna 2020-05-08 13:53:39 -03:00
license.txt update license/readme URLs to HTTPS where appropriate 2019-05-16 09:32:06 -03:00
package-lock.json package lock maintenance, remove simple products in group product test 2021-03-15 14:04:37 -03:00
package.json Update version in package.json to 5.3 2021-03-19 11:56:29 +01:00
phpcs.xml Created dummy `woocommerce/woocommerce-lib` package to contain dependencies 2020-11-18 13:54:20 -08:00
phpunit.xml Added dependency injection infrastructure for unit tests: 2020-07-24 09:23:05 +02:00
readme.txt Change stable tag in readme.txt to 5.2 2021-04-08 16:18:03 +02:00
renovate.json Marked all of the feature plugin packages as ignored in the renovate config 2020-05-27 13:49:54 -07:00
tsconfig.base.json Adjusted the package exports to be easier to consume 2020-09-21 11:21:35 -07:00
tsconfig.json Refactored the factory to use a repository instead of an adapter so that we can expose more API functionality 2020-09-07 16:00:27 -07:00
uninstall.php Restored original behaviour of the constant. 2020-02-06 13:39:46 +01:00
woocommerce.php Update minimum required version of WordPress to 5.5 2021-03-19 11:08:37 +01:00

README.md

WooCommerce

license Latest Stable Version WordPress.org downloads WordPress.org rating Build Status codecov

Welcome to the WooCommerce repository on GitHub. Here you can browse the source, look at open issues and keep track of development. We recommend all developers to follow the WooCommerce development blog to stay up to date about everything happening in the project. You can also follow @DevelopWC on Twitter for the latest development updates.

If you are not a developer, please use the WooCommerce plugin page on WordPress.org.

Documentation

Reporting Security Issues

To disclose a security issue to our team, please submit a report via HackerOne here.

Support

This repository is not suitable for support. Please don't use our issue tracker for support requests, but for core WooCommerce issues only. Support can take place through the appropriate channels:

Support requests in issues on this repository will be closed on sight.

Contributing to WooCommerce

If you have a patch or have stumbled upon an issue with WooCommerce core, you can contribute this back to the code. Please read our contributor guidelines for more information how you can do this.



Made with 💜 by WooCommerce.
We're hiring! Come work with us!