Skip to content

Instantly share code, notes, and snippets.

@leemason
Created January 20, 2014 14:57
Show Gist options
  • Save leemason/8521272 to your computer and use it in GitHub Desktop.
Save leemason/8521272 to your computer and use it in GitHub Desktop.
<?php
//current way
$options = array(
'key1' => 'value',
'key2' => array(
'key3' => ''
)
);
add_option('option1', $options);
$opt = get_option('option1');
echo $opt['key4thatdoesntexist'] == 'doesnt exists error';
//new way
$options = array(
'key1' => 'value',
'key2' => array(
'key3' => ''
)
);
add_option('option2', $options);
function something($options){
$defaults = array(
'key1' => '',
'key2' => array(
'key3' => ''
),
'key4thatdoesntexist' => ''
);
return recursive_array_function($options, $defaults);
}
add_filter('get_option_option2', 'something');
$opt = get_option('option2');//this is run through the above filter
echo $opt['key4thatdoesntexist'] == 'is part of the array because we added it in the filter (its empty, but it exists!)';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment