<?php

namespace Shy\WordPress;



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


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

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

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

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