Jetpack_Sync_Module_Options

The WordPress Core Jetpack Sync Module Options class.

Defined (1)

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

/sync/class.jetpack-sync-module-options.php  
  1. class Jetpack_Sync_Module_Options extends Jetpack_Sync_Module { 
  2. private $options_whitelist; 
  3.  
  4. public function name() { 
  5. return 'options'; 
  6.  
  7. public function init_listeners( $callable ) { 
  8. // options 
  9. add_action( 'added_option', $callable, 10, 2 ); 
  10. add_action( 'updated_option', $callable, 10, 3 ); 
  11. add_action( 'deleted_option', $callable, 10, 1 ); 
  12.  
  13. // Sync Core Icon: Detect changes in Core's Site Icon and make it syncable. 
  14. add_action( 'add_option_site_icon', array( $this, 'jetpack_sync_core_icon' ) ); 
  15. add_action( 'update_option_site_icon', array( $this, 'jetpack_sync_core_icon' ) ); 
  16. add_action( 'delete_option_site_icon', array( $this, 'jetpack_sync_core_icon' ) ); 
  17.  
  18. $whitelist_option_handler = array( $this, 'whitelist_options' ); 
  19. add_filter( 'jetpack_sync_before_enqueue_deleted_option', $whitelist_option_handler ); 
  20. add_filter( 'jetpack_sync_before_enqueue_added_option', $whitelist_option_handler ); 
  21. add_filter( 'jetpack_sync_before_enqueue_updated_option', $whitelist_option_handler ); 
  22.  
  23. public function init_full_sync_listeners( $callable ) { 
  24. add_action( 'jetpack_full_sync_options', $callable ); 
  25.  
  26. public function init_before_send() { 
  27. // full sync 
  28. add_filter( 'jetpack_sync_before_send_jetpack_full_sync_options', array( $this, 'expand_options' ) ); 
  29.  
  30. public function set_defaults() { 
  31. $this->update_options_whitelist(); 
  32.  
  33. public function set_late_default() { 
  34.  
  35. /** This filter is already documented in json-endpoints/jetpack/class.wpcom-json-api-get-option-endpoint.php */ 
  36. $late_options = apply_filters( 'jetpack_options_whitelist', array() ); 
  37. if ( ! empty( $late_options ) && is_array( $late_options ) ) { 
  38. $this->options_whitelist = array_merge( $this->options_whitelist, $late_options ); 
  39.  
  40. function enqueue_full_sync_actions( $config, $max_items_to_enqueue, $state ) { 
  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_options', true ); 
  47.  
  48. // The number of actions enqueued, and next module state (true == done) 
  49. return array( 1, true ); 
  50.  
  51. public function estimate_full_sync_actions( $config ) { 
  52. return 1; 
  53.  
  54. function get_full_sync_actions() { 
  55. return array( 'jetpack_full_sync_options' ); 
  56.  
  57. // Is public so that we don't have to store so much data all the options twice. 
  58. function get_all_options() { 
  59. $options = array(); 
  60. foreach ( $this->options_whitelist as $option ) { 
  61. $options[ $option ] = get_option( $option ); 
  62.  
  63. // add theme mods 
  64. $theme_mods_option = 'theme_mods_'.get_option( 'stylesheet' ); 
  65. $theme_mods_value = get_option( $theme_mods_option ); 
  66. $this->filter_theme_mods( $theme_mods_value ); 
  67. $options[ $theme_mods_option ] = $theme_mods_value; 
  68.  
  69. return $options; 
  70.  
  71. function update_options_whitelist() { 
  72. $this->options_whitelist = Jetpack_Sync_Defaults::get_options_whitelist(); 
  73.  
  74. function set_options_whitelist( $options ) { 
  75. $this->options_whitelist = $options; 
  76.  
  77. function get_options_whitelist() { 
  78. return $this->options_whitelist; 
  79.  
  80. // reject non-whitelisted options 
  81. function whitelist_options( $args ) { 
  82. if ( ! $this->is_whitelisted_option( $args[0] ) ) { 
  83. return false; 
  84.  
  85. // filter our weird array( false ) value for theme_mods_* 
  86. if ( 'theme_mods_' === substr( $args[0], 0, 11 ) ) { 
  87. $this->filter_theme_mods( $args[1] ); 
  88. if ( isset( $args[2] ) ) {  
  89. $this->filter_theme_mods( $args[2] ); 
  90.  
  91. return $args; 
  92.  
  93. function is_whitelisted_option( $option ) { 
  94. return in_array( $option, $this->options_whitelist ) || 'theme_mods_' === substr( $option, 0, 11 ); 
  95.  
  96. private function filter_theme_mods( &$value ) { 
  97. if ( is_array( $value ) && isset( $value[0] ) ) { 
  98. unset( $value[0] );  
  99.  
  100. function jetpack_sync_core_icon() { 
  101. if ( function_exists( 'get_site_icon_url' ) ) { 
  102. $url = get_site_icon_url(); 
  103. } else { 
  104. return; 
  105.  
  106. require_once( JETPACK__PLUGIN_DIR . 'modules/site-icon/site-icon-functions.php' ); 
  107. // If there's a core icon, maybe update the option. If not, fall back to Jetpack's. 
  108. if ( ! empty( $url ) && $url !== jetpack_site_icon_url() ) { 
  109. // This is the option that is synced with dotcom 
  110. Jetpack_Options::update_option( 'site_icon_url', $url ); 
  111. } else if ( empty( $url ) ) { 
  112. Jetpack_Options::delete_option( 'site_icon_url' ); 
  113.  
  114. public function expand_options( $args ) { 
  115. if ( $args[0] ) { 
  116. return $this->get_all_options(); 
  117.  
  118. return $args;