Abstract_Jetpack_Site

The WordPress Core Abstract Jetpack Site class.

Defined (1)

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

/sal/class.json-api-site-jetpack-base.php  
  1. abstract class Abstract_Jetpack_Site extends SAL_Site { 
  2. abstract protected function get_constant( $name ); 
  3.  
  4. abstract protected function current_theme_supports( $feature_name ); 
  5.  
  6. abstract protected function get_theme_support( $feature_name ); 
  7.  
  8. abstract protected function get_jetpack_version(); 
  9.  
  10. abstract protected function get_updates(); 
  11.  
  12. abstract protected function main_network_site(); 
  13.  
  14. abstract protected function wp_version(); 
  15.  
  16. abstract protected function max_upload_size(); 
  17.  
  18. abstract protected function is_main_network(); 
  19.  
  20. abstract protected function is_multi_site(); 
  21.  
  22. abstract protected function is_version_controlled(); 
  23.  
  24. abstract protected function file_system_write_access(); 
  25.  
  26. function before_render() { 
  27.  
  28. function after_render( &$response ) { 
  29. // Add the updates only make them visible if the user has manage options permission and the site is the main site of the network 
  30. if ( current_user_can( 'manage_options' ) && $this->is_main_site( $response ) ) { 
  31. $jetpack_update = $this->get_updates(); 
  32. if ( ! empty( $jetpack_update ) ) { 
  33. // In previous version of Jetpack 3.4, 3.5, 3.6 we synced the wp_version into to jetpack_updates 
  34. unset( $jetpack_update['wp_version'] ); 
  35. // In previous version of Jetpack 3.4, 3.5, 3.6 we synced the site_is_version_controlled into to jetpack_updates 
  36. unset( $jetpack_update['site_is_version_controlled'] ); 
  37.  
  38. $response['updates'] = $jetpack_update; 
  39.  
  40. function after_render_options( &$options ) { 
  41.  
  42. $options['jetpack_version'] = $this->get_jetpack_version(); 
  43.  
  44. if ( $main_network_site = $this->main_network_site() ) { 
  45. $options['main_network_site'] = (string) rtrim( $main_network_site, '/' ); 
  46.  
  47. if ( is_array( $active_modules = Jetpack_Options::get_option( 'active_modules' ) ) ) { 
  48. $options['active_modules'] = (array) array_values( $active_modules ); 
  49.  
  50. $options['software_version'] = (string) $this->wp_version(); 
  51. $options['max_upload_size'] = $this->max_upload_size(); 
  52.  
  53. // Sites have to prove that they are not main_network site. 
  54. // If the sync happends right then we should be able to see that we are not dealing with a network site 
  55. $options['is_multi_network'] = (bool) $this->is_main_network(); 
  56. $options['is_multi_site'] = (bool) $this->is_multi_site(); 
  57.  
  58. $file_mod_disabled_reasons = array_keys( array_filter( array( 
  59. 'automatic_updater_disabled' => (bool) $this->get_constant( 'AUTOMATIC_UPDATER_DISABLED' ),  
  60. // WP AUTO UPDATE CORE defaults to minor, '1' if true and '0' if set to false. 
  61. 'wp_auto_update_core_disabled' => ! ( (bool) $this->get_constant( 'WP_AUTO_UPDATE_CORE' ) ),  
  62. 'is_version_controlled' => (bool) $this->is_version_controlled(),  
  63. // By default we assume that site does have system write access if the value is not set yet. 
  64. 'has_no_file_system_write_access' => ! (bool) $this->file_system_write_access(),  
  65. 'disallow_file_mods' => (bool) $this->get_constant( 'DISALLOW_FILE_MODS' ),  
  66. ) ) ); 
  67.  
  68. $options['file_mod_disabled'] = empty( $file_mod_disabled_reasons ) ? false : $file_mod_disabled_reasons; 
  69.  
  70. function get_jetpack_modules() { 
  71. if ( is_user_member_of_blog() ) { 
  72. return array_values( Jetpack_Options::get_option( 'active_modules', array() ) ); 
  73.  
  74. return null; 
  75.  
  76. function is_vip() { 
  77. return false; // this may change for VIP Go sites, which sync using Jetpack 
  78.  
  79. function is_multisite() { 
  80. return (bool) is_multisite(); 
  81.  
  82. function is_single_user_site() { 
  83. return (bool) Jetpack::is_single_user_site(); 
  84.  
  85. function featured_images_enabled() { 
  86. return $this->current_theme_supports( 'post-thumbnails' ); 
  87.  
  88. function get_post_formats() { 
  89. // deprecated - see separate endpoint. get a list of supported post formats 
  90. $all_formats = get_post_format_strings(); 
  91. $supported = $this->get_theme_support( 'post-formats' ); 
  92.  
  93. $supported_formats = array(); 
  94.  
  95. if ( isset( $supported[0] ) ) { 
  96. foreach ( $supported[0] as $format ) { 
  97. $supported_formats[ $format ] = $all_formats[ $format ]; 
  98.  
  99. return $supported_formats; 
  100.  
  101. function get_icon() { 
  102. $icon_id = get_option( 'site_icon' ); 
  103. if ( empty( $icon_id ) ) { 
  104. $icon_id = Jetpack_Options::get_option( 'site_icon_id' ); 
  105.  
  106. if ( empty( $icon_id ) ) { 
  107. return null; 
  108.  
  109. $icon = array_filter( array( 
  110. 'img' => wp_get_attachment_image_url( $icon_id, 'full' ),  
  111. 'ico' => wp_get_attachment_image_url( $icon_id, array( 16, 16 ) ) 
  112. ) ); 
  113.  
  114. if ( empty( $icon ) ) { 
  115. return null; 
  116.  
  117. if ( current_user_can( 'edit_posts', $icon_id ) ) { 
  118. $icon['media_id'] = (int) $icon_id; 
  119.  
  120. return $icon; 
  121.  
  122. /** 
  123. * Private methods 
  124. **/ 
  125.  
  126. private function is_main_site( $response ) { 
  127. if ( isset( $response['options']->main_network_site, $response['options']->unmapped_url ) ) { 
  128. $main_network_site_url = set_url_scheme( $response['options']->main_network_site, 'http' ); 
  129. $unmapped_url = set_url_scheme( $response['options']->unmapped_url, 'http' ); 
  130. if ( $unmapped_url === $main_network_site_url ) { 
  131. return true; 
  132.  
  133. return false;