Няма описание

class-wc-helper-options.php 1.4KB

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