Jetpack_Sync_Module_Updates

The WordPress Core Jetpack Sync Module Updates class.

Defined (1)

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

/sync/class.jetpack-sync-module-updates.php  
  1. class Jetpack_Sync_Module_Updates extends Jetpack_Sync_Module { 
  2.  
  3. const UPDATES_CHECKSUM_OPTION_NAME = 'jetpack_updates_sync_checksum'; 
  4.  
  5. function name() { 
  6. return 'updates'; 
  7.  
  8. public function init_listeners( $callable ) { 
  9.  
  10. add_action( 'set_site_transient_update_plugins', array( $this, 'validate_update_change' ), 10, 3 ); 
  11. add_action( 'set_site_transient_update_themes', array( $this, 'validate_update_change' ), 10, 3 ); 
  12. add_action( 'set_site_transient_update_core', array( $this, 'validate_update_change' ), 10, 3 ); 
  13.  
  14. add_action( 'jetpack_update_plugins_change', $callable ); 
  15. add_action( 'jetpack_update_themes_change', $callable ); 
  16. add_action( 'jetpack_update_core_change', $callable ); 
  17.  
  18. add_filter( 'jetpack_sync_before_enqueue_jetpack_update_plugins_change', array( 
  19. $this,  
  20. 'filter_update_keys',  
  21. ), 10, 2 ); 
  22. add_filter( 'jetpack_sync_before_enqueue_upgrader_process_complete', array( 
  23. $this,  
  24. 'filter_upgrader_process_complete',  
  25. ), 10, 2 ); 
  26.  
  27. add_action( 'automatic_updates_complete', $callable ); 
  28.  
  29. public function init_full_sync_listeners( $callable ) { 
  30. add_action( 'jetpack_full_sync_updates', $callable ); 
  31.  
  32. public function init_before_send() { 
  33. add_filter( 'jetpack_sync_before_send_jetpack_full_sync_updates', array( $this, 'expand_updates' ) ); 
  34. add_filter( 'jetpack_sync_before_send_jetpack_update_themes_change', array( $this, 'expand_themes' ) ); 
  35.  
  36. public function get_update_checksum( $value ) { 
  37. // Create an new array so we don't modify the object passed in. 
  38. $a_value = (array) $value; 
  39.  
  40. // ignore `last_checked` 
  41. unset( $a_value['last_checked'] ); 
  42. unset( $a_value['checked'] ); 
  43. if ( empty( $a_value ) ) { 
  44. return false; 
  45. return $this->get_check_sum( $a_value ); 
  46.  
  47. public function validate_update_change( $value, $expiration, $transient ) { 
  48.  
  49. $new_checksum = $this->get_update_checksum( $value ); 
  50. if ( false === $new_checksum ) { 
  51. return; 
  52.  
  53. $checksums = get_option( self::UPDATES_CHECKSUM_OPTION_NAME, array() ); 
  54.  
  55. if ( isset( $checksums[ $transient ] ) && $checksums[ $transient ] === $new_checksum ) { 
  56. return; 
  57.  
  58. $checksums[ $transient ] = $new_checksum; 
  59.  
  60. update_option( self::UPDATES_CHECKSUM_OPTION_NAME, $checksums ); 
  61. // possible $transient value are update_plugins, update_themes, update_core 
  62. do_action( "jetpack_{$transient}_change", $value ); 
  63.  
  64. public function enqueue_full_sync_actions( $config, $max_items_to_enqueue, $state ) { 
  65. /** 
  66. * Tells the client to sync all updates to the server 
  67. * @since 4.2.0 
  68. * @param boolean Whether to expand updates (should always be true) 
  69. */ 
  70. do_action( 'jetpack_full_sync_updates', true ); 
  71.  
  72. // The number of actions enqueued, and next module state (true == done) 
  73. return array( 1, true ); 
  74.  
  75. public function estimate_full_sync_actions( $config ) { 
  76. return 1; 
  77.  
  78. function get_full_sync_actions() { 
  79. return array( 'jetpack_full_sync_updates' ); 
  80.  
  81. public function get_all_updates() { 
  82. return array( 
  83. 'core' => get_site_transient( 'update_core' ),  
  84. 'plugins' => get_site_transient( 'update_plugins' ),  
  85. 'themes' => get_site_transient( 'update_themes' ),  
  86. ); 
  87.  
  88. // removes unnecessary keys from synced updates data 
  89. function filter_update_keys( $args ) { 
  90. $updates = $args[0]; 
  91.  
  92. if ( isset( $updates->no_update ) ) { 
  93. unset( $updates->no_update ); 
  94.  
  95. return $args; 
  96.  
  97. function filter_upgrader_process_complete( $args ) { 
  98. array_shift( $args ); 
  99.  
  100. return $args; 
  101.  
  102. public function expand_updates( $args ) { 
  103. if ( $args[0] ) { 
  104. return $this->get_all_updates(); 
  105.  
  106. return $args; 
  107.  
  108. public function expand_themes( $args ) { 
  109. foreach ( $args[0]->response as $stylesheet => &$theme_data ) { 
  110. $theme = wp_get_theme( $stylesheet ); 
  111. $theme_data['name'] = $theme->name; 
  112. return $args;