wp-customize-global-styles-setting.php 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. <?php
  2. if ( class_exists( 'WP_Customize_Setting' ) && ! class_exists( 'WP_Customize_Global_Styles_Setting' ) ) {
  3. /**
  4. * Customize API: WP_Customize_Global_Styles_Setting class
  5. *
  6. * This handles saving and retrieving of the value.
  7. *
  8. */
  9. /**
  10. * Custom Setting to handle WP Global_Styles.
  11. *
  12. * @see WP_Customize_Setting
  13. */
  14. final class WP_Customize_Global_Styles_Setting extends WP_Customize_Setting {
  15. /**
  16. * The setting type.
  17. *
  18. * @var string
  19. */
  20. public $type = 'global_styles';
  21. /**
  22. * Setting Transport
  23. *
  24. * @var string
  25. */
  26. public $transport = 'postMessage';
  27. /**
  28. * User value
  29. *
  30. * @var string
  31. */
  32. public $user_value = '';
  33. /**
  34. * Fetch the value of the setting.
  35. *
  36. * @see WP_Customize_Setting::value()
  37. *
  38. * @return string
  39. */
  40. public function value() {
  41. return $this->user_value;
  42. }
  43. /**
  44. * Store the color in the Global Styles custom post
  45. *
  46. * @param string $color The input color.
  47. * @return WP_Post|WP_Error The post or a WP_Error if the value could not be saved.
  48. */
  49. public function update( $color ) {
  50. if ( empty( $color ) ) {
  51. return;
  52. }
  53. $this->new_value = $color;
  54. }
  55. }
  56. }