2013-08-22 10:58:03 +00:00
< ? php
/**
2018-04-12 10:13:01 +00:00
* WooCommerce Account Settings .
2013-08-22 10:58:03 +00:00
*
2020-08-05 16:36:24 +00:00
* @ package WooCommerce\Admin
2013-08-22 10:58:03 +00:00
*/
2018-04-12 10:13:01 +00:00
defined ( 'ABSPATH' ) || exit ;
2013-08-22 10:58:03 +00:00
2018-04-12 15:59:42 +00:00
if ( class_exists ( 'WC_Settings_Accounts' , false ) ) {
return new WC_Settings_Accounts ();
}
/**
* WC_Settings_Accounts .
*/
class WC_Settings_Accounts extends WC_Settings_Page {
2013-08-22 10:58:03 +00:00
/**
2018-04-12 15:59:42 +00:00
* Constructor .
2013-08-22 10:58:03 +00:00
*/
2018-04-12 15:59:42 +00:00
public function __construct () {
$this -> id = 'account' ;
$this -> label = __ ( 'Accounts & Privacy' , 'woocommerce' );
parent :: __construct ();
2013-08-22 10:58:03 +00:00
}
2018-04-12 15:59:42 +00:00
/**
* Get settings array .
*
* @ return array
*/
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
2020-09-16 10:27:05 +00:00
protected function get_settings_for_default_section () {
2018-11-05 13:47:28 +00:00
$erasure_text = esc_html__ ( 'account erasure request' , 'woocommerce' );
2020-06-18 13:37:29 +00:00
$privacy_text = esc_html__ ( 'privacy page' , 'woocommerce' );
2018-10-13 00:49:05 +00:00
if ( current_user_can ( 'manage_privacy_options' ) ) {
2019-12-11 01:12:50 +00:00
if ( version_compare ( get_bloginfo ( 'version' ), '5.3' , '<' ) ) {
$erasure_text = sprintf ( '<a href="%s">%s</a>' , esc_url ( admin_url ( 'tools.php?page=remove_personal_data' ) ), $erasure_text );
} else {
$erasure_text = sprintf ( '<a href="%s">%s</a>' , esc_url ( admin_url ( 'erase-personal-data.php' ) ), $erasure_text );
}
2020-06-18 13:37:29 +00:00
$privacy_text = sprintf ( '<a href="%s">%s</a>' , esc_url ( admin_url ( 'options-privacy.php' ) ), $privacy_text );
2018-10-13 00:49:05 +00:00
}
2019-04-08 22:11:39 +00:00
$account_settings = array (
2019-01-07 11:22:29 +00:00
array (
2019-04-08 22:11:39 +00:00
'title' => '' ,
'type' => 'title' ,
'id' => 'account_registration_options' ,
),
array (
'title' => __ ( 'Guest checkout' , 'woocommerce' ),
'desc' => __ ( 'Allow customers to place orders without an account' , 'woocommerce' ),
'id' => 'woocommerce_enable_guest_checkout' ,
'default' => 'yes' ,
'type' => 'checkbox' ,
'checkboxgroup' => 'start' ,
'autoload' => false ,
),
array (
'title' => __ ( 'Login' , 'woocommerce' ),
'desc' => __ ( 'Allow customers to log into an existing account during checkout' , 'woocommerce' ),
'id' => 'woocommerce_enable_checkout_login_reminder' ,
'default' => 'no' ,
'type' => 'checkbox' ,
'checkboxgroup' => 'end' ,
'autoload' => false ,
),
array (
'title' => __ ( 'Account creation' , 'woocommerce' ),
'desc' => __ ( 'Allow customers to create an account during checkout' , 'woocommerce' ),
'id' => 'woocommerce_enable_signup_and_login_from_checkout' ,
'default' => 'no' ,
'type' => 'checkbox' ,
'checkboxgroup' => 'start' ,
'autoload' => false ,
),
array (
'desc' => __ ( 'Allow customers to create an account on the "My account" page' , 'woocommerce' ),
'id' => 'woocommerce_enable_myaccount_registration' ,
'default' => 'no' ,
'type' => 'checkbox' ,
'checkboxgroup' => '' ,
'autoload' => false ,
),
array (
2019-06-12 10:13:41 +00:00
'desc' => __ ( 'When creating an account, automatically generate an account username for the customer based on their name, surname or email' , 'woocommerce' ),
2019-04-08 22:11:39 +00:00
'id' => 'woocommerce_registration_generate_username' ,
'default' => 'yes' ,
'type' => 'checkbox' ,
'checkboxgroup' => '' ,
'autoload' => false ,
),
array (
'desc' => __ ( 'When creating an account, automatically generate an account password' , 'woocommerce' ),
'id' => 'woocommerce_registration_generate_password' ,
'default' => 'yes' ,
'type' => 'checkbox' ,
'checkboxgroup' => 'end' ,
'autoload' => false ,
),
array (
'title' => __ ( 'Account erasure requests' , 'woocommerce' ),
'desc' => __ ( 'Remove personal data from orders on request' , 'woocommerce' ),
/* Translators: %s URL to erasure request screen. */
'desc_tip' => sprintf ( esc_html__ ( 'When handling an %s, should personal data within orders be retained or removed?' , 'woocommerce' ), $erasure_text ),
'id' => 'woocommerce_erasure_request_removes_order_data' ,
'type' => 'checkbox' ,
'default' => 'no' ,
'checkboxgroup' => 'start' ,
'autoload' => false ,
),
array (
'desc' => __ ( 'Remove access to downloads on request' , 'woocommerce' ),
/* Translators: %s URL to erasure request screen. */
'desc_tip' => sprintf ( esc_html__ ( 'When handling an %s, should access to downloadable files be revoked and download logs cleared?' , 'woocommerce' ), $erasure_text ),
'id' => 'woocommerce_erasure_request_removes_download_data' ,
'type' => 'checkbox' ,
'default' => 'no' ,
'checkboxgroup' => 'end' ,
'autoload' => false ,
),
array (
'title' => __ ( 'Personal data removal' , 'woocommerce' ),
'desc' => __ ( 'Allow personal data to be removed in bulk from orders' , 'woocommerce' ),
2020-02-12 14:13:13 +00:00
'desc_tip' => __ ( 'Adds an option to the orders screen for removing personal data in bulk. Note that removing personal data cannot be undone.' , 'woocommerce' ),
2019-04-08 22:11:39 +00:00
'id' => 'woocommerce_allow_bulk_remove_personal_data' ,
'type' => 'checkbox' ,
'checkboxgroup' => 'start' ,
'default' => 'no' ,
'autoload' => false ,
),
array (
'type' => 'sectionend' ,
'id' => 'account_registration_options' ,
),
array (
'title' => __ ( 'Privacy policy' , 'woocommerce' ),
'type' => 'title' ,
'id' => 'privacy_policy_options' ,
2020-06-18 13:37:29 +00:00
/* translators: %s: privacy page link. */
'desc' => sprintf ( esc_html__ ( 'This section controls the display of your website privacy policy. The privacy notices below will not show up unless a %s is set.' , 'woocommerce' ), $privacy_text ),
2019-04-08 22:11:39 +00:00
),
2018-04-17 17:32:31 +00:00
2019-04-08 22:11:39 +00:00
array (
'title' => __ ( 'Registration privacy policy' , 'woocommerce' ),
'desc_tip' => __ ( 'Optionally add some text about your store privacy policy to show on account registration forms.' , 'woocommerce' ),
'id' => 'woocommerce_registration_privacy_policy_text' ,
/* translators: %s privacy policy page name and link */
'default' => sprintf ( __ ( 'Your personal data will be used to support your experience throughout this website, to manage access to your account, and for other purposes described in our %s.' , 'woocommerce' ), '[privacy_policy]' ),
'type' => 'textarea' ,
'css' => 'min-width: 50%; height: 75px;' ,
),
2018-04-17 17:32:31 +00:00
2019-04-08 22:11:39 +00:00
array (
'title' => __ ( 'Checkout privacy policy' , 'woocommerce' ),
'desc_tip' => __ ( 'Optionally add some text about your store privacy policy to show during checkout.' , 'woocommerce' ),
'id' => 'woocommerce_checkout_privacy_policy_text' ,
/* translators: %s privacy policy page name and link */
'default' => sprintf ( __ ( 'Your personal data will be used to process your order, support your experience throughout this website, and for other purposes described in our %s.' , 'woocommerce' ), '[privacy_policy]' ),
'type' => 'textarea' ,
'css' => 'min-width: 50%; height: 75px;' ,
),
array (
'type' => 'sectionend' ,
'id' => 'privacy_policy_options' ,
),
array (
'title' => __ ( 'Personal data retention' , 'woocommerce' ),
'desc' => __ ( 'Choose how long to retain personal data when it\'s no longer needed for processing. Leave the following options blank to retain this data indefinitely.' , 'woocommerce' ),
'type' => 'title' ,
'id' => 'personal_data_retention' ,
),
array (
'title' => __ ( 'Retain inactive accounts ' , 'woocommerce' ),
'desc_tip' => __ ( 'Inactive accounts are those which have not logged in, or placed an order, for the specified duration. They will be deleted. Any orders will be converted into guest orders.' , 'woocommerce' ),
'id' => 'woocommerce_delete_inactive_accounts' ,
'type' => 'relative_date_selector' ,
'placeholder' => __ ( 'N/A' , 'woocommerce' ),
'default' => array (
'number' => '' ,
'unit' => 'months' ,
2019-02-28 00:30:54 +00:00
),
2019-04-08 22:11:39 +00:00
'autoload' => false ,
),
array (
'title' => __ ( 'Retain pending orders ' , 'woocommerce' ),
'desc_tip' => __ ( 'Pending orders are unpaid and may have been abandoned by the customer. They will be trashed after the specified duration.' , 'woocommerce' ),
'id' => 'woocommerce_trash_pending_orders' ,
'type' => 'relative_date_selector' ,
'placeholder' => __ ( 'N/A' , 'woocommerce' ),
'default' => '' ,
'autoload' => false ,
),
array (
'title' => __ ( 'Retain failed orders' , 'woocommerce' ),
'desc_tip' => __ ( 'Failed orders are unpaid and may have been abandoned by the customer. They will be trashed after the specified duration.' , 'woocommerce' ),
'id' => 'woocommerce_trash_failed_orders' ,
'type' => 'relative_date_selector' ,
'placeholder' => __ ( 'N/A' , 'woocommerce' ),
'default' => '' ,
'autoload' => false ,
),
array (
'title' => __ ( 'Retain cancelled orders' , 'woocommerce' ),
'desc_tip' => __ ( 'Cancelled orders are unpaid and may have been cancelled by the store owner or customer. They will be trashed after the specified duration.' , 'woocommerce' ),
'id' => 'woocommerce_trash_cancelled_orders' ,
'type' => 'relative_date_selector' ,
'placeholder' => __ ( 'N/A' , 'woocommerce' ),
'default' => '' ,
'autoload' => false ,
),
array (
'title' => __ ( 'Retain completed orders' , 'woocommerce' ),
'desc_tip' => __ ( 'Retain completed orders for a specified duration before anonymizing the personal data within them.' , 'woocommerce' ),
'id' => 'woocommerce_anonymize_completed_orders' ,
'type' => 'relative_date_selector' ,
'placeholder' => __ ( 'N/A' , 'woocommerce' ),
'default' => array (
'number' => '' ,
'unit' => 'months' ,
2019-02-28 00:30:54 +00:00
),
2019-04-08 22:11:39 +00:00
'autoload' => false ,
),
array (
'type' => 'sectionend' ,
'id' => 'personal_data_retention' ,
),
);
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
2020-09-16 10:27:05 +00:00
return apply_filters (
2019-04-08 22:11:39 +00:00
'woocommerce_' . $this -> id . '_settings' ,
$account_settings
2018-04-12 15:59:42 +00:00
);
}
}
2013-08-22 10:58:03 +00:00
2014-08-31 08:22:03 +00:00
return new WC_Settings_Accounts ();