1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55:
<?php
/**
* Class for loading functions to store and retrieve data from wp_options table
* @package InboundPro
* @subpackage DataInterface
*/
if ( ! class_exists( 'Inbound_Options_API' ) ) {
class Inbound_Options_API {
/**
* Gets option value in name space object
* @param STRING $namespace option_name
* @param STRING $key target key in dataset to get data outof
* @param MIXED $default default data to return if no data exists
*/
public static function get_option( $namespace , $key , $default = null ) {
$options = get_option( $namespace , array() ) ;
if (!isset( $options[ $key ] )) {
add_option( $namespace , '', '', 'no' );
return $default;
} else {
return $options[ $key ];
}
}
/**
* Updates option value in name space object
* @param STRING $namespace option_name
* @param STRING $key target key in dataset to set data into
* @param MIXED $value value to set into key
* @param STRING $autoload (optional) defaults to no but can be set to yes for creating new cachable options.
*/
public static function update_option( $namespace , $key , $value , $autoload = 'no' ) {
$options = get_option( $namespace , array() );
if (!$options || !is_array( $options ) ) {
add_option( $namespace , '', '', $autoload );
$options = array();
}
$options[$key] = $value;
update_option( $namespace , $options ) ;
}
}
}