class.jetpack-sync-module-updates.php
| 1 | <?php |
| 2 | |
| 3 | class Jetpack_Sync_Module_Updates extends Jetpack_Sync_Module { |
| 4 | function name() { |
| 5 | return 'updates'; |
| 6 | } |
| 7 | |
| 8 | public function init_listeners( $callable ) { |
| 9 | add_action( 'set_site_transient_update_plugins', $callable, 10, 1 ); |
| 10 | add_action( 'set_site_transient_update_themes', $callable, 10, 1 ); |
| 11 | add_action( 'set_site_transient_update_core', $callable, 10, 1 ); |
| 12 | |
| 13 | add_filter( 'jetpack_sync_before_enqueue_set_site_transient_update_plugins', array( |
| 14 | $this, |
| 15 | 'filter_update_keys', |
| 16 | ), 10, 2 ); |
| 17 | add_filter( 'jetpack_sync_before_enqueue_upgrader_process_complete', array( |
| 18 | $this, |
| 19 | 'filter_upgrader_process_complete', |
| 20 | ), 10, 2 ); |
| 21 | } |
| 22 | |
| 23 | public function init_full_sync_listeners( $callable ) { |
| 24 | add_action( 'jetpack_full_sync_updates', $callable ); |
| 25 | } |
| 26 | |
| 27 | public function init_before_send() { |
| 28 | // full sync |
| 29 | add_filter( 'jetpack_sync_before_send_jetpack_full_sync_updates', array( $this, 'expand_updates' ) ); |
| 30 | } |
| 31 | |
| 32 | public function enqueue_full_sync_actions( $config ) { |
| 33 | /** |
| 34 | * Tells the client to sync all updates to the server |
| 35 | * |
| 36 | * @since 4.2.0 |
| 37 | * |
| 38 | * @param boolean Whether to expand updates (should always be true) |
| 39 | */ |
| 40 | do_action( 'jetpack_full_sync_updates', true ); |
| 41 | |
| 42 | return 1; // The number of actions enqueued |
| 43 | } |
| 44 | |
| 45 | public function estimate_full_sync_actions( $config ) { |
| 46 | return 1; |
| 47 | } |
| 48 | |
| 49 | function get_full_sync_actions() { |
| 50 | return array( 'jetpack_full_sync_updates' ); |
| 51 | } |
| 52 | |
| 53 | public function get_all_updates() { |
| 54 | return array( |
| 55 | 'core' => get_site_transient( 'update_core' ), |
| 56 | 'plugins' => get_site_transient( 'update_plugins' ), |
| 57 | 'themes' => get_site_transient( 'update_themes' ), |
| 58 | ); |
| 59 | } |
| 60 | |
| 61 | // removes unnecessary keys from synced updates data |
| 62 | function filter_update_keys( $args ) { |
| 63 | $updates = $args[0]; |
| 64 | |
| 65 | if ( isset( $updates->no_update ) ) { |
| 66 | unset( $updates->no_update ); |
| 67 | } |
| 68 | |
| 69 | return $args; |
| 70 | } |
| 71 | |
| 72 | function filter_upgrader_process_complete( $args ) { |
| 73 | array_shift( $args ); |
| 74 | |
| 75 | return $args; |
| 76 | } |
| 77 | |
| 78 | public function expand_updates( $args ) { |
| 79 | if ( $args[0] ) { |
| 80 | return $this->get_all_updates(); |
| 81 | } |
| 82 | |
| 83 | return $args; |
| 84 | } |
| 85 | } |
| 86 |