Skip to content
Snippets Groups Projects
Commit f16fc37a authored by Erick Hitter's avatar Erick Hitter
Browse files

Finish options class

parent 26dc85d6
Branches
No related tags found
3 merge requests!6add linting,!5WIP: Add JUnit reporting,!4WIP: Initial release
...@@ -31,10 +31,14 @@ class Options { ...@@ -31,10 +31,14 @@ class Options {
]; ];
/** /**
* Hooks and other preparations * Retrieve full plugin options
*
* @return array
*/ */
public function setup() { private function get_all() : array {
// Hooks and such. $options = get_option( $this->name, [] );
$options = wp_parse_args( $options, $this->allowed_options );
return $options;
} }
/** /**
...@@ -48,9 +52,7 @@ class Options { ...@@ -48,9 +52,7 @@ class Options {
return false; return false;
} }
$options = get_option( $this->name, [] ); $options = $this->get_all();
$options = wp_parse_args( $options, $this->allowed_options );
return $options[ $option ] ?? false; return $options[ $option ] ?? false;
} }
...@@ -61,7 +63,23 @@ class Options { ...@@ -61,7 +63,23 @@ class Options {
* @param mixed $value Option value. * @param mixed $value Option value.
* @return bool * @return bool
*/ */
public function update( string $option, $value ) : bool { public function set( string $option, $value ) : bool {
return false; 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 );
} }
} }
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
/** /**
* Assorted helpers * Assorted helpers
* *
* @pacakge Camo_Image_Proxy * @package Camo_Image_Proxy
*/ */
namespace Camo_Image_Proxy; namespace Camo_Image_Proxy;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment