Jetpack_Sync_Module_Network_Options

The WordPress Core Jetpack Sync Module Network Options class.

Defined (1)

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

/sync/class.jetpack-sync-module-network-options.php  
  1. class Jetpack_Sync_Module_Network_Options extends Jetpack_Sync_Module { 
  2. private $network_options_whitelist; 
  3.  
  4. public function name() { 
  5. return 'network_options'; 
  6.  
  7. public function init_listeners( $callable ) { 
  8. if ( ! is_multisite() ) { 
  9. return; 
  10.  
  11. // multi site network options 
  12. add_action( 'add_site_option', $callable, 10, 2 ); 
  13. add_action( 'update_site_option', $callable, 10, 3 ); 
  14. add_action( 'delete_site_option', $callable, 10, 1 ); 
  15.  
  16. $whitelist_network_option_handler = array( $this, 'whitelist_network_options' ); 
  17. add_filter( 'jetpack_sync_before_enqueue_delete_site_option', $whitelist_network_option_handler ); 
  18. add_filter( 'jetpack_sync_before_enqueue_add_site_option', $whitelist_network_option_handler ); 
  19. add_filter( 'jetpack_sync_before_enqueue_update_site_option', $whitelist_network_option_handler ); 
  20.  
  21. public function init_full_sync_listeners( $callable ) { 
  22. add_action( 'jetpack_full_sync_network_options', $callable ); 
  23.  
  24. public function init_before_send() { 
  25. if ( ! is_multisite() ) { 
  26. return; 
  27.  
  28. // full sync 
  29. add_filter( 'jetpack_sync_before_send_jetpack_full_sync_network_options', array( 
  30. $this,  
  31. 'expand_network_options',  
  32. ) ); 
  33.  
  34. public function set_defaults() { 
  35. $this->network_options_whitelist = Jetpack_Sync_Defaults::$default_network_options_whitelist; 
  36.  
  37. function enqueue_full_sync_actions( $config, $max_items_to_enqueue, $state ) { 
  38. if ( ! is_multisite() ) { 
  39. return array( 0, true ); 
  40.  
  41. /** 
  42. * Tells the client to sync all options to the server 
  43. * @since 4.2.0 
  44. * @param boolean Whether to expand options (should always be true) 
  45. */ 
  46. do_action( 'jetpack_full_sync_network_options', true ); 
  47.  
  48. // The number of actions enqueued, and next module state (true == done) 
  49. return array( 1, true ); 
  50.  
  51. function estimate_full_sync_actions( $config ) { 
  52. if ( ! is_multisite() ) { 
  53. return 0; 
  54.  
  55. return 1; 
  56.  
  57. function get_full_sync_actions() { 
  58. return array( 'jetpack_full_sync_network_options' ); 
  59.  
  60. function get_all_network_options() { 
  61. $options = array(); 
  62. foreach ( $this->network_options_whitelist as $option ) { 
  63. $options[ $option ] = get_site_option( $option ); 
  64.  
  65. return $options; 
  66.  
  67. function set_network_options_whitelist( $options ) { 
  68. $this->network_options_whitelist = $options; 
  69.  
  70. function get_network_options_whitelist() { 
  71. return $this->network_options_whitelist; 
  72.  
  73. // reject non-whitelisted network options 
  74. function whitelist_network_options( $args ) { 
  75. if ( ! $this->is_whitelisted_network_option( $args[0] ) ) { 
  76. return false; 
  77.  
  78. return $args; 
  79.  
  80. function is_whitelisted_network_option( $option ) { 
  81. return is_multisite() && in_array( $option, $this->network_options_whitelist ); 
  82.  
  83. public function expand_network_options( $args ) { 
  84. if ( $args[0] ) { 
  85. return $this->get_all_network_options(); 
  86.  
  87. return $args;