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

Basic options class

parent ba58ff06
No related branches found
No related tags found
3 merge requests!6add linting,!5WIP: Add JUnit reporting,!4WIP: Initial release
......@@ -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();
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment