Pressbooks\Options::sanitize PHP Метод

sanitize() публичный Метод

Sanitize various options (boolean, string, integer, float).
public sanitize ( array $input ) : array
$input array
Результат array $options
    function sanitize($input)
    {
        $options = array();
        if (!is_array($input)) {
            $input = array();
        }
        if (property_exists($this, 'booleans')) {
            foreach ($this->booleans as $key) {
                if (!isset($input[$key]) || 1 != @$input[$key]) {
                    $options[$key] = 0;
                } else {
                    $options[$key] = 1;
                }
            }
        }
        if (property_exists($this, 'strings')) {
            foreach ($this->strings as $key) {
                if (empty($input[$key])) {
                    unset($options[$key]);
                } else {
                    $options[$key] = sanitize_text_field($input[$key]);
                }
            }
        }
        if (property_exists($this, 'urls')) {
            foreach ($this->urls as $key) {
                if (empty($input[$key])) {
                    unset($options[$key]);
                } else {
                    $value = trim(strip_tags(stripslashes($input[$key])));
                    if ($value) {
                        $options[$key] = \Pressbooks\Sanitize\canonicalize_url($value);
                    } else {
                        unset($options[$key]);
                    }
                }
            }
        }
        if (property_exists($this, 'integers')) {
            foreach ($this->integers as $key) {
                if (empty($input[$key])) {
                    unset($options[$key]);
                } else {
                    $options[$key] = absint($input[$key]);
                }
            }
        }
        if (property_exists($this, 'floats')) {
            foreach ($this->floats as $key) {
                if (empty($input[$key])) {
                    unset($options[$key]);
                } else {
                    $options[$key] = filter_var($input[$key], FILTER_VALIDATE_FLOAT);
                }
            }
        }
        if (property_exists($this, 'predefined')) {
            foreach ($this->predefined as $key) {
                if (empty($input[$key])) {
                    unset($options[$key]);
                } else {
                    $options[$key] = $input[$key];
                }
            }
        }
        return $options;
    }