Jetpack_Sync_Options

Simple class to read/write to the options table, bypassing problematic caching with get_option/set_option.

Defined (1)

The class is defined in the following location(s).

/sync/class.jetpack-sync-options.php  
  1. class Jetpack_Sync_Options { 
  2.  
  3. static function delete_option( $name ) { 
  4. global $wpdb; 
  5. $wpdb->query( $wpdb->prepare( "DELETE FROM $wpdb->options WHERE option_name = %s", $name ) ); 
  6.  
  7. static function update_option( $name, $value, $autoload = false ) { 
  8.  
  9. $autoload_value = $autoload ? 'yes' : 'no'; 
  10.  
  11. // we write our own option updating code to bypass filters/caching/etc on set_option/get_option 
  12. global $wpdb; 
  13. $serialized_value = maybe_serialize( $value ); 
  14. // try updating, if no update then insert 
  15. // TODO: try to deal with the fact that unchanged values can return updated_num = 0 
  16. // below we used "insert ignore" to at least suppress the resulting error 
  17. $updated_num = $wpdb->query( 
  18. $wpdb->prepare( 
  19. "UPDATE $wpdb->options SET option_value = %s WHERE option_name = %s",  
  20. $serialized_value,  
  21. $name 
  22. ); 
  23.  
  24. if ( ! $updated_num ) { 
  25. $updated_num = $wpdb->query( 
  26. $wpdb->prepare( 
  27. "INSERT IGNORE INTO $wpdb->options ( option_name, option_value, autoload ) VALUES ( %s, %s, '$autoload_value' )",  
  28. $name,  
  29. $serialized_value 
  30. ); 
  31. return $updated_num; 
  32.  
  33. static function get_option( $name, $default = null ) { 
  34. global $wpdb; 
  35. $value = $wpdb->get_var(  
  36. $wpdb->prepare( 
  37. "SELECT option_value FROM $wpdb->options WHERE option_name = %s LIMIT 1",  
  38. $name 
  39. ); 
  40. $value = maybe_unserialize( $value ); 
  41.  
  42. if ( $value === null && $default !== null ) { 
  43. return $default; 
  44.  
  45. return $value; 
  46.