1 | <?php |
||
43 | class CMB2_Option { |
||
44 | |||
45 | /** |
||
46 | * Options array |
||
47 | * @var array |
||
48 | */ |
||
49 | protected $options = array(); |
||
50 | |||
51 | /** |
||
52 | * Current option key |
||
53 | * @var string |
||
54 | */ |
||
55 | protected $key = ''; |
||
56 | |||
57 | /** |
||
58 | * Initiate option object |
||
59 | * @param string $option_key Option key where data will be saved. |
||
60 | * Leave empty for temporary data store. |
||
61 | * @since 2.0.0 |
||
62 | */ |
||
63 | public function __construct( $option_key = '' ) { |
||
66 | |||
67 | /** |
||
68 | * Delete the option from the db |
||
69 | * @since 2.0.0 |
||
70 | * @return bool Delete success or failure |
||
71 | */ |
||
72 | public function delete_option() { |
||
77 | |||
78 | /** |
||
79 | * Removes an option from an option array |
||
80 | * @since 1.0.1 |
||
81 | * @param string $field_id Option array field key |
||
82 | 2 | * @return array Modified options |
|
83 | 2 | */ |
|
84 | public function remove( $field_id, $resave = false ) { |
||
98 | |||
99 | /** |
||
100 | * Retrieves an option from an option array |
||
101 | * @since 1.0.1 |
||
102 | * @param string $field_id Option array field key |
||
103 | 1 | * @param mixed $default Fallback value for the option |
|
104 | 1 | * @return array Requested field or default |
|
105 | */ |
||
106 | 1 | public function get( $field_id, $default = false ) { |
|
117 | 1 | ||
118 | /** |
||
119 | * Updates Option data |
||
120 | * @since 1.0.1 |
||
121 | 1 | * @param string $field_id Option array field key |
|
122 | * @param mixed $value Value to update data with |
||
123 | * @param bool $resave Whether to re-save the data |
||
124 | * @param bool $single Whether data should not be an array |
||
125 | * @return boolean Return status of update |
||
126 | */ |
||
127 | public function update( $field_id, $value = '', $resave = false, $single = true ) { |
||
147 | |||
148 | /** |
||
149 | * Saves the option array |
||
150 | * Needs to be run after finished using remove/update_option |
||
151 | * @uses apply_filters() Calls 'cmb2_override_option_save_{$this->key}' hook |
||
152 | * to allow overwriting the option value to be stored. |
||
153 | * |
||
154 | * @since 1.0.1 |
||
155 | * @param array $options Optional options to override |
||
156 | 3 | * @return bool Success/Failure |
|
157 | 3 | */ |
|
158 | public function set( $options = array() ) { |
||
176 | |||
177 | /** |
||
178 | * Retrieve option value based on name of option. |
||
179 | * @uses apply_filters() Calls 'cmb2_override_option_get_{$this->key}' hook to allow |
||
180 | * overwriting the option value to be retrieved. |
||
181 | * |
||
182 | * @since 1.0.1 |
||
183 | * @param mixed $default Optional. Default value to return if the option does not exist. |
||
184 | * @return mixed Value set for the option. |
||
185 | */ |
||
186 | public function get_options( $default = null ) { |
||
201 | |||
202 | } |
||
203 |
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.