Make the WC_Settings_Page::get_settings_for_section final

This helps on conveying the notion that the method to be overriden
is get_settings_for_section_core instead (or get_settings_for_X_section
methods must be added).
This commit is contained in:
Nestor Soriano 2021-04-13 09:31:50 +02:00
parent 56cc063d7f
commit 5af12170d7
No known key found for this signature in database
GPG Key ID: 08110F3518C12CAD
2 changed files with 10 additions and 11 deletions

View File

@ -77,7 +77,7 @@ if ( ! class_exists( 'WC_Settings_Page', false ) ) :
/**
* Get settings array for the default section.
*
* @deprecated 5.4.0 'get_settings_for_section' (passing an empty string for default section) should be used instead.
* @deprecated 5.4.0 Use 'get_settings_for_section' (passing an empty string for default section)
*
* @return array Settings array, each item being an associative array representing a setting.
*/
@ -101,7 +101,7 @@ if ( ! class_exists( 'WC_Settings_Page', false ) ) :
*
* @return array Settings array, each item being an associative array representing a setting.
*/
public function get_settings_for_section( $section_id ) {
final public function get_settings_for_section( $section_id ) {
if ( '' === $section_id ) {
$method_name = 'get_settings_for_default_section';
} else {
@ -122,6 +122,9 @@ if ( ! class_exists( 'WC_Settings_Page', false ) ) :
* This method is invoked from 'get_settings_for_section' when no 'get_settings_for_{current_section}_section'
* method exists in the class.
*
* When overriding, note that the 'woocommerce_get_settings_' filter must NOT be triggered,
* as this is already done by 'get_settings_for_section'.
*
* @param string $section_id The section name to get the settings for.
*
* @return array Settings array, each item being an associative array representing a setting.

View File

@ -88,19 +88,15 @@ class WC_Settings_Shipping extends WC_Settings_Page {
}
/**
* Get settings for the current section.
* Get settings for the default section.
*
* @param string $section_id The id of the section to return settings for.
* The original implementation of 'get_settings' was returning the settings for the "Options" section
* when the supplied value for $current_section was ''.
*
* @return array
*/
public function get_settings_for_section( $section_id = '' ) {
/*
The original implementation of this function was returning the settings for the "Options" section
when the supplied value for $current_section was '', which is the id for the "Zones" section.
We need this workaround to keep compatibility.
*/
return parent::get_settings_for_section( '' === $section_id ? 'options' : $section_id );
protected function get_settings_for_default_section() {
return $this->get_settings_for_options_section();
}
/**