1. /* This is my plugin activation_hook. What am I doing wrong? Why are the options not being updated correctly? */
  2. function cud_install_options(){
  3.     $defaults = array(
  4.         'custom_upload_dir' => '',
  5.         'all_parents' => true,
  6.         'flatten_hierarchy' => false,
  7.         'only_leaf_nodes' => false,
  8.         'only_base_nodes' => false,
  9.         'test_ids'  => '-1',
  10.         'template' => ''
  11.     ); 
  12.     $old = get_option('custom_upload_dir');
  13.     if(is_array($old)){
  14.         if(!empty($old['template'])){ //update deprecated placeholders
  15.             $newtags = array('%post_id%','%postname%','%author%','%monthnum%');
  16.             $oldtags = array('%ID%', '%post_name%','%post_author%','%month%');
  17.             $old['template'] = str_replace($oldtags, $newtags, $old['template']);
  18.         }  
  19.         $defaults = array_merge($defaults, $old);  
  20.     }      
  21.     update_option('custom_upload_dir', $defaults);
  22. }