get_option_names() public static method

* Jetpack Options API
public static get_option_names ( $type = 'compact' )
 /**
  * Deletes the given option.  May be passed multiple option names as an array.
  * Updates jetpack_options and/or deletes jetpack_$name as appropriate.
  *
  * @param string|array $names
  */
 function delete_option($names)
 {
     $names = (array) $names;
     foreach (array_diff($names, Jetpack::get_option_names(), Jetpack::get_option_names('non_compact')) as $unknown_name) {
         trigger_error(sprintf('Invalid Jetpack option name: %s', $unknown_name), E_USER_WARNING);
     }
     foreach (array_intersect($names, Jetpack::get_option_names('non_compact')) as $name) {
         delete_option("jetpack_{$name}");
     }
     $options = get_option('jetpack_options');
     if (!is_array($options)) {
         $options = array();
     }
     $to_delete = array_intersect($names, Jetpack::get_option_names(), array_keys($options));
     if ($to_delete) {
         foreach ($to_delete as $name) {
             unset($options[$name]);
         }
         return update_option('jetpack_options', $options);
     }
     return true;
 }
Example #2
0
 /**
  * Must never be called statically
  */
 function plugin_upgrade()
 {
     // Upgrade: 1.1 -> 1.2
     if (get_option('jetpack_id')) {
         // Move individual jetpack options to single array of options
         $options = array();
         foreach (Jetpack::get_option_names() as $option) {
             if (false !== ($value = get_option("jetpack_{$option}"))) {
                 $options[$option] = $value;
             }
         }
         if ($options) {
             Jetpack::update_options($options);
             foreach (array_keys($options) as $option) {
                 delete_option("jetpack_{$option}");
             }
         }
         // Add missing version and old_version options
         if (!($version = Jetpack::get_option('version'))) {
             $version = $old_version = '1.1:' . time();
             Jetpack::update_options(compact('version', 'old_version'));
         }
     }
     // Upgrade from a single user token to a user_id-indexed array and a master_user ID
     if (!Jetpack::get_option('user_tokens')) {
         if ($user_token = Jetpack::get_option('user_token')) {
             $token_parts = explode('.', $user_token);
             if (isset($token_parts[2])) {
                 $master_user = $token_parts[2];
                 $user_tokens = array($master_user => $user_token);
                 Jetpack::update_options(compact('master_user', 'user_tokens'));
                 Jetpack::delete_option('user_token');
             } else {
                 // @todo: is this even possible?
                 trigger_error(sprintf('Jetpack::plugin_upgrade found no user_id in user_token "%s"', $user_token), E_USER_WARNING);
             }
         }
     }
 }