Site_Option.php
76 lines
| 1 | <?php |
| 2 | /** |
| 3 | * WordPress Customize Setting classes |
| 4 | * |
| 5 | * @package Kirki |
| 6 | * @subpackage Modules |
| 7 | * @since 3.0.0 |
| 8 | */ |
| 9 | |
| 10 | namespace Kirki\Util\Setting; |
| 11 | |
| 12 | /** |
| 13 | * Handles saving and sanitizing of user-meta. |
| 14 | * |
| 15 | * @since 3.0.0 |
| 16 | * @see WP_Customize_Setting |
| 17 | */ |
| 18 | class Site_Option extends \WP_Customize_Setting { |
| 19 | |
| 20 | /** |
| 21 | * Type of customize settings. |
| 22 | * |
| 23 | * @access public |
| 24 | * @since 3.0.0 |
| 25 | * @var string |
| 26 | */ |
| 27 | public $type = 'site_option'; |
| 28 | |
| 29 | /** |
| 30 | * Get the root value for a setting, especially for multidimensional ones. |
| 31 | * |
| 32 | * @access protected |
| 33 | * @since 3.0.0 |
| 34 | * @param mixed $default Value to return if root does not exist. |
| 35 | * @return mixed |
| 36 | */ |
| 37 | protected function get_root_value( $default = null ) { |
| 38 | return get_site_option( $this->id_data['base'], $default ); |
| 39 | } |
| 40 | |
| 41 | /** |
| 42 | * Set the root value for a setting, especially for multidimensional ones. |
| 43 | * |
| 44 | * @access protected |
| 45 | * @since 3.0.0 |
| 46 | * @param mixed $value Value to set as root of multidimensional setting. |
| 47 | * @return bool Whether the multidimensional root was updated successfully. |
| 48 | */ |
| 49 | protected function set_root_value( $value ) { |
| 50 | return update_site_option( $this->id_data['base'], $value ); |
| 51 | } |
| 52 | |
| 53 | /** |
| 54 | * Save the value of the setting, using the related API. |
| 55 | * |
| 56 | * @access protected |
| 57 | * @since 3.0.0 |
| 58 | * @param mixed $value The value to update. |
| 59 | * @return bool The result of saving the value. |
| 60 | */ |
| 61 | protected function update( $value ) { |
| 62 | return $this->set_root_value( $value ); |
| 63 | } |
| 64 | |
| 65 | /** |
| 66 | * Fetch the value of the setting. |
| 67 | * |
| 68 | * @access protected |
| 69 | * @since 3.0.0 |
| 70 | * @return mixed The value. |
| 71 | */ |
| 72 | public function value() { |
| 73 | return $this->get_root_value( $this->default ); |
| 74 | } |
| 75 | } |
| 76 |