diff --git a/camo-image-proxy.php b/camo-image-proxy.php index d9f8865450d85a91b16b8655674e7a29209baef8..3833b1d7e796a6818a110c3eb1bf647838bd779f 100755 --- a/camo-image-proxy.php +++ b/camo-image-proxy.php @@ -20,3 +20,13 @@ define( __NAMESPACE__ . '\PLUGIN_PATH', dirname( __FILE__ ) ); * Trait for singletons */ require_once PLUGIN_PATH . '/inc/trait-singleton.php'; + +/** + * Plugin options + */ +require_once PLUGIN_PATH . '/inc/class-options.php'; + +/** + * Assorted functions + */ +require_once PLUGIN_PATH . '/inc/functions.php'; diff --git a/inc/class-options.php b/inc/class-options.php new file mode 100644 index 0000000000000000000000000000000000000000..084f38dfa047167ab189bb18d4dc4e8b729bce64 --- /dev/null +++ b/inc/class-options.php @@ -0,0 +1,67 @@ +<?php +/** + * Plugin options + * + * @package Camo_Image_Proxy + */ + +namespace Camo_Image_Proxy; + +/** + * Class Options + */ +class Options { + use Singleton; + + /** + * Option name + * + * @var string + */ + private $name = 'camo_image_proxy_opts'; + + /** + * Allowed options + * + * @var array + */ + private $allowed_options = [ + 'host' => '', + 'key' => '', + ]; + + /** + * Hooks and other preparations + */ + public function setup() { + // Hooks and such. + } + + /** + * Get plugin option + * + * @param string $option Plugin option to retrieve. + * @return mixed + */ + public function get( string $option ) { + if ( ! array_key_exists( $option, $this->allowed_options ) ) { + return false; + } + + $options = get_option( $this->name, [] ); + $options = wp_parse_args( $options, $this->allowed_options ); + + return $options[ $option ] ?? false; + } + + /** + * Set plugin option + * + * @param string $option Plugin option to set. + * @param mixed $value Option value. + * @return bool + */ + public function update( string $option, $value ) : bool { + return false; + } +} diff --git a/inc/functions.php b/inc/functions.php new file mode 100644 index 0000000000000000000000000000000000000000..1e11a12262e43cb09c07e2bee856c5121e21c05f --- /dev/null +++ b/inc/functions.php @@ -0,0 +1,17 @@ +<?php +/** + * Assorted helpers + * + * @pacakge Camo_Image_Proxy + */ + +namespace Camo_Image_Proxy; + +/** + * Access plugin options + * + * @return object + */ +function options() { + return Options::instance(); +}