views
5 months ago
class-wc-helper-admin.php
4 months ago
class-wc-helper-api.php
1 year ago
class-wc-helper-compat.php
5 years ago
class-wc-helper-options.php
3 years ago
class-wc-helper-orders-api.php
2 years ago
class-wc-helper-sanitization.php
1 year ago
class-wc-helper-subscriptions-api.php
4 months ago
class-wc-helper-updater.php
2 months ago
class-wc-helper.php
4 months ago
class-wc-plugin-api-updater.php
1 year ago
class-wc-product-usage-notice.php
1 year ago
class-wc-woo-helper-connection.php
4 months ago
class-wc-woo-update-manager-plugin.php
2 years ago
class-wc-helper-options.php
61 lines
| 1 | <?php |
| 2 | /** |
| 3 | * WooCommerce Admin Helper Options |
| 4 | * |
| 5 | * @package WooCommerce\Admin\Helper |
| 6 | */ |
| 7 | |
| 8 | if ( ! defined( 'ABSPATH' ) ) { |
| 9 | exit; |
| 10 | } |
| 11 | |
| 12 | /** |
| 13 | * WC_Helper_Options Class |
| 14 | * |
| 15 | * An interface to the woocommerce_helper_data entry in the wp_options table. |
| 16 | */ |
| 17 | class WC_Helper_Options { |
| 18 | /** |
| 19 | * The option name used to store the helper data. |
| 20 | * |
| 21 | * @var string |
| 22 | */ |
| 23 | private static $option_name = 'woocommerce_helper_data'; |
| 24 | |
| 25 | /** |
| 26 | * Update an option by key |
| 27 | * |
| 28 | * All helper options are grouped in a single options entry. This method |
| 29 | * is not thread-safe, use with caution. |
| 30 | * |
| 31 | * @param string $key The key to update. |
| 32 | * @param mixed $value The new option value. |
| 33 | * |
| 34 | * @return bool True if the option has been updated. |
| 35 | */ |
| 36 | public static function update( $key, $value ) { |
| 37 | $options = get_option( self::$option_name, array() ); |
| 38 | $options[ $key ] = $value; |
| 39 | return update_option( self::$option_name, $options, true ); |
| 40 | } |
| 41 | |
| 42 | /** |
| 43 | * Get an option by key |
| 44 | * |
| 45 | * @see self::update |
| 46 | * |
| 47 | * @param string $key The key to fetch. |
| 48 | * @param mixed $default The default option to return if the key does not exist. |
| 49 | * |
| 50 | * @return mixed An option or the default. |
| 51 | */ |
| 52 | public static function get( $key, $default = false ) { |
| 53 | $options = get_option( self::$option_name, array() ); |
| 54 | if ( is_array( $options ) && array_key_exists( $key, $options ) ) { |
| 55 | return $options[ $key ]; |
| 56 | } |
| 57 | |
| 58 | return $default; |
| 59 | } |
| 60 | } |
| 61 |