Jetpack_Sync_Functions

Utility functions to generate data synced to wpcom.

Defined (1)

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

/sync/class.jetpack-sync-functions.php  
  1. class Jetpack_Sync_Functions { 
  2. const HTTPS_CHECK_OPTION_PREFIX = 'jetpack_sync_https_history_'; 
  3. const HTTPS_CHECK_HISTORY = 5; 
  4.  
  5. public static function get_modules() { 
  6. require_once( JETPACK__PLUGIN_DIR . 'class.jetpack-admin.php' ); 
  7.  
  8. return Jetpack_Admin::init()->get_modules(); 
  9.  
  10. public static function get_taxonomies() { 
  11. global $wp_taxonomies; 
  12. $wp_taxonomies_without_callbacks = array(); 
  13. foreach ( $wp_taxonomies as $taxonomy_name => $taxonomy ) { 
  14. $sanitized_taxonomy = self::sanitize_taxonomy( $taxonomy ); 
  15. if ( ! empty( $sanitized_taxonomy ) ) { 
  16. $wp_taxonomies_without_callbacks[ $taxonomy_name ] = $sanitized_taxonomy; 
  17. } else { 
  18. error_log( 'Jetpack: Encountered a recusive taxonomy:' . $taxonomy_name ); 
  19. return $wp_taxonomies_without_callbacks; 
  20.  
  21. public static function get_shortcodes() { 
  22. global $shortcode_tags; 
  23. return array_keys( $shortcode_tags ); 
  24.  
  25. /** 
  26. * Removes any callback data since we will not be able to process it on our side anyways. 
  27. */ 
  28. public static function sanitize_taxonomy( $taxonomy ) { 
  29.  
  30. // Lets clone the taxonomy object instead of modifing the global one. 
  31. $cloned_taxonomy = json_decode( wp_json_encode( $taxonomy ) ); 
  32.  
  33. // recursive taxonomies are no fun. 
  34. if ( is_null( $cloned_taxonomy ) ) { 
  35. return null; 
  36. // Remove any meta_box_cb if they are not the default wp ones. 
  37. if ( isset( $cloned_taxonomy->meta_box_cb ) && 
  38. ! in_array( $cloned_taxonomy->meta_box_cb, array( 'post_tags_meta_box', 'post_categories_meta_box' ) ) ) { 
  39. $cloned_taxonomy->meta_box_cb = null; 
  40. // Remove update call back 
  41. if ( isset( $cloned_taxonomy->update_count_callback ) && 
  42. ! is_null( $cloned_taxonomy->update_count_callback ) ) { 
  43. $cloned_taxonomy->update_count_callback = null; 
  44. // Remove rest_controller_class if it something other then the default. 
  45. if ( isset( $cloned_taxonomy->rest_controller_class ) && 
  46. 'WP_REST_Terms_Controller' !== $cloned_taxonomy->rest_controller_class ) { 
  47. $cloned_taxonomy->rest_controller_class = null; 
  48. return $cloned_taxonomy; 
  49.  
  50. public static function get_post_types() { 
  51. global $wp_post_types; 
  52.  
  53. return $wp_post_types; 
  54.  
  55. public static function get_post_type_features() { 
  56. global $_wp_post_type_features; 
  57.  
  58. return $_wp_post_type_features; 
  59.  
  60. public static function get_hosting_provider() { 
  61. if ( defined( 'GD_SYSTEM_PLUGIN_DIR' ) || class_exists( '\\WPaaS\\Plugin' ) ) { 
  62. return 'gd-managed-wp'; 
  63. if ( defined( 'MM_BASE_DIR' ) ) { 
  64. return 'bh'; 
  65. }  
  66. if ( defined( 'IS_PRESSABLE' ) ) { 
  67. return 'pressable'; 
  68. }  
  69. if ( function_exists( 'is_wpe' ) || function_exists( 'is_wpe_snapshot' ) ) { 
  70. return 'wpe'; 
  71. if ( defined( 'VIP_GO_ENV' ) && false !== VIP_GO_ENV ) { 
  72. return 'vip-go'; 
  73. return 'unknown'; 
  74.  
  75. public static function rest_api_allowed_post_types() { 
  76. /** This filter is already documented in class.json-api-endpoints.php */ 
  77. return apply_filters( 'rest_api_allowed_post_types', array( 'post', 'page', 'revision' ) ); 
  78.  
  79. public static function rest_api_allowed_public_metadata() { 
  80. /** This filter is documented in json-endpoints/class.wpcom-json-api-post-endpoint.php */ 
  81. return apply_filters( 'rest_api_allowed_public_metadata', array() ); 
  82.  
  83. /** 
  84. * Finds out if a site is using a version control system. 
  85. * @return bool 
  86. **/ 
  87. public static function is_version_controlled() { 
  88.  
  89. if ( ! class_exists( 'WP_Automatic_Updater' ) ) { 
  90. require_once( ABSPATH . 'wp-admin/includes/class-wp-upgrader.php' ); 
  91. $updater = new WP_Automatic_Updater(); 
  92.  
  93. return (bool) strval( $updater->is_vcs_checkout( $context = ABSPATH ) ); 
  94.  
  95. /** 
  96. * Returns true if the site has file write access false otherwise. 
  97. * @return bool 
  98. **/ 
  99. public static function file_system_write_access() { 
  100. if ( ! function_exists( 'get_filesystem_method' ) ) { 
  101. require_once( ABSPATH . 'wp-admin/includes/file.php' ); 
  102.  
  103. require_once( ABSPATH . 'wp-admin/includes/template.php' ); 
  104.  
  105. $filesystem_method = get_filesystem_method(); 
  106. if ( 'direct' === $filesystem_method ) { 
  107. return true; 
  108.  
  109. ob_start(); 
  110. $filesystem_credentials_are_stored = request_filesystem_credentials( self_admin_url() ); 
  111. ob_end_clean(); 
  112. if ( $filesystem_credentials_are_stored ) { 
  113. return true; 
  114.  
  115. return false; 
  116.  
  117. public static function home_url() { 
  118. return self::get_protocol_normalized_url( 
  119. 'home_url',  
  120. self::normalize_www_in_url( 'home', 'home_url' ) 
  121. ); 
  122.  
  123. public static function site_url() { 
  124. return self::get_protocol_normalized_url( 
  125. 'site_url',  
  126. self::normalize_www_in_url( 'siteurl', 'site_url' ) 
  127. ); 
  128.  
  129. public static function main_network_site_url() { 
  130. return self::get_protocol_normalized_url( 'main_network_site_url', network_site_url() ); 
  131.  
  132. public static function get_protocol_normalized_url( $callable, $new_value ) { 
  133. $option_key = self::HTTPS_CHECK_OPTION_PREFIX . $callable; 
  134.  
  135. $parsed_url = wp_parse_url( $new_value ); 
  136. if ( ! $parsed_url ) { 
  137. return $new_value; 
  138.  
  139. $scheme = $parsed_url['scheme']; 
  140. $scheme_history = get_option( $option_key, array() ); 
  141. $scheme_history[] = $scheme; 
  142.  
  143. // Limit length to self::HTTPS_CHECK_HISTORY 
  144. $scheme_history = array_slice( $scheme_history, ( self::HTTPS_CHECK_HISTORY * -1 ) ); 
  145.  
  146. update_option( $option_key, $scheme_history ); 
  147.  
  148. $forced_scheme = in_array( 'https', $scheme_history ) ? 'https' : 'http'; 
  149.  
  150. return set_url_scheme( $new_value, $forced_scheme ); 
  151.  
  152. public static function normalize_www_in_url( $option, $url_function ) { 
  153. $url = wp_parse_url( call_user_func( $url_function ) ); 
  154. $option_url = wp_parse_url( get_option( $option ) ); 
  155.  
  156. if ( ! $option_url || ! $url ) { 
  157. return $url; 
  158.  
  159. if ( $url[ 'host' ] === "www.{$option_url[ 'host' ]}" ) { 
  160. // remove www if not present in option URL 
  161. $url[ 'host' ] = $option_url[ 'host' ]; 
  162. if ( $option_url[ 'host' ] === "www.{$url[ 'host' ]}" ) { 
  163. // add www if present in option URL 
  164. $url[ 'host' ] = $option_url[ 'host' ]; 
  165.  
  166. $normalized_url = "{$url['scheme']}://{$url['host']}"; 
  167. if ( isset( $url['path'] ) ) { 
  168. $normalized_url .= "{$url['path']}"; 
  169.  
  170. if ( isset( $url['query'] ) ) { 
  171. $normalized_url .= "?{$url['query']}"; 
  172.  
  173. return $normalized_url; 
  174.  
  175. public static function get_plugins() { 
  176. if ( ! function_exists( 'get_plugins' ) ) { 
  177. require_once ABSPATH . 'wp-admin/includes/plugin.php'; 
  178.  
  179. /** This filter is documented in wp-admin/includes/class-wp-plugins-list-table.php */ 
  180. return apply_filters( 'all_plugins', get_plugins() ); 
  181.  
  182. public static function wp_version() { 
  183. global $wp_version; 
  184.  
  185. return $wp_version; 
  186.  
  187. public static function site_icon_url() { 
  188. if ( ! function_exists( 'get_site_icon_url' ) || ! has_site_icon() ) { 
  189. return get_option( 'jetpack_site_icon_url' ); 
  190.  
  191. return get_site_icon_url();