2017-04-21 12:05:44 +00:00
|
|
|
<?php
|
|
|
|
if ( ! defined( 'ABSPATH' ) ) {
|
|
|
|
exit;
|
|
|
|
}
|
|
|
|
|
2017-04-26 15:50:38 +00:00
|
|
|
/**
|
|
|
|
* WC_Helper_Options Class
|
|
|
|
*
|
|
|
|
* An interface to the woocommerce_helper_data entry in the wp_options table.
|
|
|
|
*/
|
2017-04-21 12:05:44 +00:00
|
|
|
class WC_Helper_Options {
|
2017-05-03 10:33:39 +00:00
|
|
|
/**
|
|
|
|
* The option name used to store the helper data.
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
2017-04-21 12:05:44 +00:00
|
|
|
private static $option_name = 'woocommerce_helper_data';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Update an option by key
|
|
|
|
*
|
|
|
|
* All helper options are grouped in a single options entry. This method
|
|
|
|
* is not thread-safe, use with caution.
|
|
|
|
*
|
|
|
|
* @param string $key The key to update.
|
2018-03-05 18:59:17 +00:00
|
|
|
* @param mixed $value The new option value.
|
2017-04-21 12:05:44 +00:00
|
|
|
*
|
|
|
|
* @return bool True if the option has been updated.
|
|
|
|
*/
|
|
|
|
public static function update( $key, $value ) {
|
2018-03-05 18:59:17 +00:00
|
|
|
$options = get_option( self::$option_name, array() );
|
2017-04-21 12:05:44 +00:00
|
|
|
$options[ $key ] = $value;
|
|
|
|
return update_option( self::$option_name, $options, true );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get an option by key
|
|
|
|
*
|
|
|
|
* @see self::update
|
|
|
|
*
|
|
|
|
* @param string $key The key to fetch.
|
2018-03-05 18:59:17 +00:00
|
|
|
* @param mixed $default The default option to return if the key does not exist.
|
2017-04-21 12:05:44 +00:00
|
|
|
*
|
|
|
|
* @return mixed An option or the default.
|
|
|
|
*/
|
|
|
|
public static function get( $key, $default = false ) {
|
|
|
|
$options = get_option( self::$option_name, array() );
|
|
|
|
if ( array_key_exists( $key, $options ) ) {
|
|
|
|
return $options[ $key ];
|
|
|
|
}
|
|
|
|
|
|
|
|
return $default;
|
|
|
|
}
|
|
|
|
}
|