diff --git a/inc/class-options.php b/inc/class-options.php index 084f38dfa047167ab189bb18d4dc4e8b729bce64..492720515ef80189d36467797337d932b7b936e2 100644 --- a/inc/class-options.php +++ b/inc/class-options.php @@ -31,10 +31,14 @@ class Options { ]; /** - * Hooks and other preparations + * Retrieve full plugin options + * + * @return array */ - public function setup() { - // Hooks and such. + private function get_all() : array { + $options = get_option( $this->name, [] ); + $options = wp_parse_args( $options, $this->allowed_options ); + return $options; } /** @@ -48,9 +52,7 @@ class Options { return false; } - $options = get_option( $this->name, [] ); - $options = wp_parse_args( $options, $this->allowed_options ); - + $options = $this->get_all(); return $options[ $option ] ?? false; } @@ -61,7 +63,23 @@ class Options { * @param mixed $value Option value. * @return bool */ - public function update( string $option, $value ) : bool { - return false; + public function set( string $option, $value ) : bool { + switch ( $option ) { + case 'host': + $value = esc_url( $value ); + break; + + case 'key': + $value = sanitize_text_field( $value ); + break; + + default: + return false; + } + + $options = $this->get_all(); + $options[ $option ] = $value; + + return update_option( $this->name, $options ); } } diff --git a/inc/functions.php b/inc/functions.php index 1e11a12262e43cb09c07e2bee856c5121e21c05f..7666210550e2455d5e4c01e6b60553f45ddc0699 100644 --- a/inc/functions.php +++ b/inc/functions.php @@ -2,7 +2,7 @@ /** * Assorted helpers * - * @pacakge Camo_Image_Proxy + * @package Camo_Image_Proxy */ namespace Camo_Image_Proxy;