<?php

namespace Shy\WordPress;



/**
 * Options wrapper.
 */
class Options implements \ArrayAccess
{
	/**
	 * Remember a default value.
	 * 
	 * Creates a closure and hooks it into the 'default_option_*' filter.
	 * 
	 * @param string $option
	 * @param mixed  $value
	 */
	public function setDefault( $option, $value )
	{
		add_filter( 'default_option_' . $option, function () use ( $value ) {
			return $value;
		} );
	}


	public function offsetExists( $option )
	{
		// Unfortunately, we can’t really tell whether it exists…
		$value = get_option( $option );
		return false !== $value && null !== $value;
	}

	public function offsetGet( $option )
	{
		return get_option( $option );
	}

	public function offsetSet( $option, $value )
	{
		update_option( $option, $value );
	}

	public function offsetUnset( $option )
	{
		delete_option( $option );
	}
}
