WC_Register_WP_Admin_Settings::register_page_settings()publicWC 3.0.0

Registers settings to a specific group.

Method of the class: WC_Register_WP_Admin_Settings{}

No Hooks.

Return

Array.

Usage

$WC_Register_WP_Admin_Settings = new WC_Register_WP_Admin_Settings();
$WC_Register_WP_Admin_Settings->register_page_settings( $settings );
$settings(array) (required)
Existing registered settings.

Changelog

Since 3.0.0 Introduced.

WC_Register_WP_Admin_Settings::register_page_settings() code WC 9.3.3

public function register_page_settings( $settings ) {
	/**
	 * WP admin settings can be broken down into separate sections from
	 * a UI standpoint. This will grab all the sections associated with
	 * a particular setting group (like 'products') and register them
	 * to the REST API.
	 */
	$sections = $this->object->get_sections();
	if ( empty( $sections ) ) {
		// Default section is just an empty string, per admin page classes.
		$sections = array( ''  => '' );
	}

	/**
	 * We are using 'WC_Settings_Page::get_settings' on purpose even thought it's deprecated.
	 * See the method documentation for an explanation.
	 */

	foreach ( $sections as $section => $section_label ) {
		$settings_from_section = $this->object->get_settings( $section );
		foreach ( $settings_from_section as $setting ) {
			if ( ! isset( $setting['id'] ) ) {
				continue;
			}
			$setting['option_key'] = $setting['id'];
			$new_setting           = $this->register_setting( $setting );
			if ( $new_setting ) {
				$settings[] = $new_setting;
			}
		}
	}
	return $settings;
}