I'm not entirely sure this is Wordpress' fault, but I figure I'd ask anyway and see if anyone else has experienced any problems like this before.
I'm trying to save an array to a wp_options table row. The data is coming from a custom metabox and is being saved when the save_post hook is triggered. I assumed this should do the trick:
update_option("myOptionName", $myArray);
I started getting 4(?!) of each value I saved. For instance:
$myArray = array("option1");
update_option("myOptionName", $myArray);
get_option("myOptionName");
// array([0]=>"option1", [1]=>"option1", [2]=>"option1", [3]=>"option1");
Needless to say, this behavior is extremely annoying. It works perfectly well with strings, but never arrays. I've tried to get around this by trying json_encode to store it as a string-y entity, but even that isn't working. The problem could very well be the legacy code I've inherited by taking on this project, but I see nothing pointing to save_post.
Has anyone ever seen a situation like this before?
EDIT: As requested ... the save function:
# SAVE BRICK DATA
function brick_update() {
// Verify if this is an auto save routine.
if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
return;
}
// Check permissions
if ( !current_user_can( 'publish_posts' ) ) { // Check for capabilities
wp_die( 'Sorry, you do not have the capabilities access to this page. :(' );
}
if (!wp_verify_nonce($_REQUEST['brickupdate'], 'brickupdate')) {
return;
}
$newView = array();
$currentView = get_option('ci_guidesbrick_posts');
if (!is_array($currentView)) {
$currentView = (array)$currentView;
}
for (var i = 0, i < count($currentView), i++) {
$newView[i] = $currentView[i];
}
$newView[] = $_REQUEST['postID'];
update_option('ci_guidesbrick_posts', $newView );
}