WC_Settings_API::init_settings PHP Method

init_settings() public method

Store all settings in a single database entry and make sure the $settings array is either the default or the settings stored in the database.
Since: 1.0.0
public init_settings ( )
    public function init_settings()
    {
        $this->settings = get_option($this->get_option_key(), null);
        // If there are no settings defined, use defaults.
        if (!is_array($this->settings)) {
            $form_fields = $this->get_form_fields();
            $this->settings = array_merge(array_fill_keys(array_keys($form_fields), ''), wp_list_pluck($form_fields, 'default'));
        }
    }

Usage Example

 /**
  * Init settings for gateways.
  */
 public function init_settings()
 {
     parent::init_settings();
     $this->enabled = !empty($this->settings['enabled']) && 'yes' === $this->settings['enabled'] ? 'yes' : 'no';
 }