Created
November 17, 2010 19:35
-
-
Save felipelavinz/703908 to your computer and use it in GitHub Desktop.
Save array data on WordPress Widgets
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 | |
/** | |
* To be used on a WordPress Widget object | |
* Fields named as '_foo_bar' will become $new_instance['foo']['bar'] = $val | |
* Fields named as '_lorem_ipsum_dolor' become $new_instance['lorem']['ipsum']['dolor'] = $val | |
**/ | |
function update( $new_instance, $old_instance ) { | |
foreach ( $new_instance as $key => $val ) { | |
if ( strpos($key, '_') === 0 && substr_count($key, '_') >= 2 ) { | |
$new_key = explode('_', $key); $l = count($new_key); | |
switch ( $l ) : | |
case 3: | |
$new_instance[$new_key[1]][$new_key[2]] = $val; | |
break; | |
case 4: | |
$new_instance[$new_key[1]][$new_key[2]][$new_key[3]] = $val; | |
break; | |
endswitch; | |
unset($new_instance[$key]); | |
} | |
} | |
return $new_instance; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment