Class CMB2_Option
Handles getting/setting of values to an option array
for a specific option key
Methods summary
public
|
#
__construct( string $option_key = '' )
Initiate option object
Parameters
- $option_key
Option key where data will be saved.
Leave empty for temporary data store.
Since
2.0.0
|
public
mixed
|
#
delete_option( )
Delete the option from the db
Delete the option from the db
Returns
mixed Delete success or failure
Since
2.0.0
|
public
array
|
#
remove( string $field_id, boolean $resave = false )
Removes an option from an option array
Removes an option from an option array
Parameters
- $field_id
- Option array field key.
- $resave
- Whether or not to resave.
Returns
array Modified options
Since
1.0.1
|
public
array
|
#
get( string $field_id, mixed $default = false )
Retrieves an option from an option array
Retrieves an option from an option array
Parameters
- $field_id
- Option array field key.
- $default
- Fallback value for the option.
Returns
array Requested field or default
Since
1.0.1
|
public
boolean
|
#
update( string $field_id, mixed $value = '', boolean $resave = false, boolean $single = true )
Updates Option data
Parameters
- $field_id
- Option array field key.
- $value
- Value to update data with.
- $resave
- Whether to re-save the data.
- $single
- Whether data should not be an array.
Returns
boolean Return status of update.
Since
1.0.1
|
public
boolean
|
#
set( array $options = array() )
Saves the option array
Needs to be run after finished using remove/update_option
Saves the option array
Needs to be run after finished using remove/update_option
Parameters
- $options
- Optional options to override.
Returns
boolean Success/Failure
Since
1.0.1
Uses
apply_filters() Calls 'cmb2_override_option_save_{$this->key}' hook
to allow overwriting the option value to be stored.
|
public
mixed
|
#
get_options( mixed $default = null )
Retrieve option value based on name of option.
Retrieve option value based on name of option.
Parameters
- $default
- Optional. Default value to return if the option does not exist.
Returns
mixed Value set for the option.
Since
1.0.1
Uses
apply_filters() Calls 'cmb2_override_option_get_{$this->key}' hook to allow
overwriting the option value to be retrieved.
|
public
mixed
|
#
__get( string $field )
Magic getter for our object.
Magic getter for our object.
Parameters
- $field
- Requested property.
Returns
mixed
Throws
Exception Throws an exception if the field is invalid.
Since
2.6.0
|