Created
January 20, 2014 14:57
-
-
Save leemason/8521272 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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