| 1 |
<?php |
| 2 |
namespace CatFolders\Models; |
| 3 |
|
| 4 |
defined( 'ABSPATH' ) || exit; |
| 5 |
|
| 6 |
class OptionModel { |
| 7 |
|
| 8 |
private static $defaults = array( |
| 9 |
'userrestriction' => '', // can't use userRestriction due to sanitize_key func |
| 10 |
'allowsvgupload' => '', |
| 11 |
); |
| 12 |
|
| 13 |
public static function update_option( $values = array() ) { |
| 14 |
$options = get_option( 'catf_settings', array() ); |
| 15 |
if ( ! is_array( $options ) ) { |
| 16 |
$options = array(); |
| 17 |
} |
| 18 |
foreach ( $values as $key => $val ) { |
| 19 |
if ( in_array( $key, array_keys( self::$defaults ), true ) ) { |
| 20 |
$options[ $key ] = $val; |
| 21 |
} |
| 22 |
} |
| 23 |
update_option( 'catf_settings', $options ); |
| 24 |
} |
| 25 |
|
| 26 |
public static function get_option( $name = '', $default = '' ) { |
| 27 |
$options = get_option( 'catf_settings', array() ); |
| 28 |
|
| 29 |
if ( ! is_array( $options ) ) { |
| 30 |
$options = array(); |
| 31 |
} |
| 32 |
|
| 33 |
if ( '' === $name ) { |
| 34 |
return wp_parse_args( $options, self::$defaults ); |
| 35 |
} |
| 36 |
|
| 37 |
return isset( $options[ $name ] ) ? $options[ $name ] : $default; |
| 38 |
} |
| 39 |
} |
| 40 |
|