This week only. Pastebin PRO Accounts Christmas Special! Don't miss out!Want more features on Pastebin? Sign Up, it's FREE!

WordPress plugin settings migration

By: ulfben on Dec 19th, 2011  |  syntax: PHP  |  size: 0.81 KB  |  views: 120  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  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. }
clone this paste RAW Paste Data