WC_Settings_API::get_option PHP Method

get_option() public method

Gets an option from the settings API, using defaults if necessary to prevent undefined notices.
public get_option ( string $key, mixed $empty_value = null ) : string
$key string
$empty_value mixed
return string The value specified for the option or a default value for the option.
    public function get_option($key, $empty_value = null)
    {
        if (empty($this->settings)) {
            $this->init_settings();
        }
        // Get option default if unset.
        if (!isset($this->settings[$key])) {
            $form_fields = $this->get_form_fields();
            $this->settings[$key] = isset($form_fields[$key]) ? $this->get_field_default($form_fields[$key]) : '';
        }
        if (!is_null($empty_value) && '' === $this->settings[$key]) {
            $this->settings[$key] = $empty_value;
        }
        return $this->settings[$key];
    }

Usage Example

Example #1
0
 /**
  * Proxy to parent's get_option and attempt to localize the result using gettext.
  *
  * @param string $key
  * @param mixed  $empty_value
  * @return string
  */
 public function get_option($key, $empty_value = null)
 {
     $value = parent::get_option($key, $empty_value);
     return apply_filters('woocommerce_email_get_option', __($value), $this, $value, $key, $empty_value);
 }
All Usage Examples Of WC_Settings_API::get_option