Commit 26dc85d6 authored by Erick Hitter's avatar Erick Hitter
Browse files

Basic options class

parent ba58ff06
......@@ -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';
<?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;
}
}
<?php
/**
* Assorted helpers
*
* @pacakge Camo_Image_Proxy
*/
namespace Camo_Image_Proxy;
/**
* Access plugin options
*
* @return object
*/
function options() {
return Options::instance();
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment