Hi everyone,
I'm updating a plugin of mine that has been neglected for a while, and one of the things I'm changing is how the options are stored.
I want to use an array instead of individual options. To clean up afterwards, I want the old rows deleted. This is what I have so far:
function MyFunction() {
$new_options = array(
'html' => 'option1',
'fromaddress' => 'option2',
'from' => 'option3',
'subject' => 'option4',
'text' => 'option5',
'adminsubject' => 'option6',
'admintext' => 'option7'
);
// if old options exist, update to new system
foreach( $new_options as $key => $value ) {
if( $existing = get_option( 'newuseremail' . $key ) ) {
$new_options[$key] = $existing;
delete_option( 'newuseremail' . $key );
}
}
update_option('newuseremail_options', $new_options);
}
where newuseremail_options is the name of the option in the table, and newuseremail + suffix of new key was the old option name.
When I save the options going from the old style to the new, the new array gets added, but the old options don't get deleted.
What am I doing wrong here?
The whole plugin code is in the pastebin, but its a little bit messy at the moment, and there might appear to be some irrelevant parts.
Thanks in advance
Alex