Advertisement
Guest User

Untitled

a guest
Sep 25th, 2017
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.13 KB | None | 0 0
  1. // If the old 'fl_link_color' hasn't been set
  2. // Or if the new 'fl_visual_options' hasn't been set
  3. // Then, add the defaults
  4. if ((!get_option( 'fl_link_color' )) || (!get_option( 'fl_visual_options' ))) {
  5.     global $options;
  6. //Create an array to hold the defaults.
  7.     $defaults = array();
  8.    
  9.     foreach ($options as $value) {
  10.         //Similar to saving. Go through each value grabbing the key & value (item).
  11.         foreach($value as $key => $item) {
  12.             //Match the ids against the key.
  13.             if(preg_match('/^id/i', $key)) {
  14.                 //replace the id so we can grab the correct numbered default value.
  15.                 $num = preg_replace('/^id(.*)/i', 'std$1', $key);
  16.                 //Make sure said value exists as it may not have a default value
  17.                 //Notice the use of $value as we want to grab the value from the
  18.                 //Previous loop, not this one.
  19.                 if(isset($value[$num])) {
  20.                     //Store value in the defaults array using the field name as key
  21.                     //And grabbing the value from the previous loop using the replaced
  22.                     //ID as the key name.
  23.                     $defaults[$item] = $value[$num];
  24.                 }
  25.             }
  26.         }
  27.        
  28.     }
  29.     //Store new ones
  30.     update_option( 'fl_visual_options', $defaults);
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement