MS_Model_Transient

Abstract Option model.

Defined (1)

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

/app/model/class-ms-model-transient.php  
  1. class MS_Model_Transient extends MS_Model { 
  2.  
  3. /** 
  4. * Save content in wp_option table. 
  5. * Update WP cache and instance singleton. 
  6. * @since 1.0.0 
  7. */ 
  8. public function save() { 
  9. $this->before_save(); 
  10.  
  11. $option_key = $this->option_key(); 
  12. $settings = array(); 
  13.  
  14. $data = MS_Factory::serialize_model( $this ); 
  15. foreach ( $data as $field => $val ) { 
  16. $settings[ $field ] = $this->$field; 
  17.  
  18. MS_Factory::set_transient( $option_key, $settings, DAY_IN_SECONDS ); 
  19.  
  20. $this->after_save(); 
  21.  
  22. wp_cache_set( $option_key, $this, 'MS_Model_Transient' ); 
  23.  
  24. /** 
  25. * Delete transient. 
  26. * @since 1.0.0 
  27. */ 
  28. public function delete() { 
  29. do_action( 'ms_model_transient_delete_before', $this ); 
  30.  
  31. $option_key = $this->option_key(); 
  32. MS_Factory::delete_transient( $option_key ); 
  33. wp_cache_delete( $option_key, 'MS_Model_Transient' ); 
  34.  
  35. do_action( 'ms_model_transient_delete_after', $this ); 
  36.  
  37. /** 
  38. * Returns the option name of the current object. 
  39. * @since 1.0.0 
  40. * @api Used by MS_Factory 
  41. * @return string The option key. 
  42. */ 
  43. public function option_key() { 
  44. // Option key should be all lowercase. 
  45. $key = strtolower( get_class( $this ) ); 
  46.  
  47. // Network-wide IS PRO ONLY! 
  48.  
  49. return substr( $key, 0, 45 ); 
  50.