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

Finish options class

parent 26dc85d6
No related branches found
No related tags found
3 merge requests!6add linting,!5WIP: Add JUnit reporting,!4WIP: Initial release
This commit is part of merge request !6. Comments created here will be created in the context of that merge request.
......@@ -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 );
}
}
......@@ -2,7 +2,7 @@
/**
* Assorted helpers
*
* @pacakge Camo_Image_Proxy
* @package 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