summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/jetpack/json-endpoints/class.wpcom-json-api-get-site-endpoint.php')
-rw-r--r--plugins/jetpack/json-endpoints/class.wpcom-json-api-get-site-endpoint.php699
1 files changed, 339 insertions, 360 deletions
diff --git a/plugins/jetpack/json-endpoints/class.wpcom-json-api-get-site-endpoint.php b/plugins/jetpack/json-endpoints/class.wpcom-json-api-get-site-endpoint.php
index ecca8774..852b6e89 100644
--- a/plugins/jetpack/json-endpoints/class.wpcom-json-api-get-site-endpoint.php
+++ b/plugins/jetpack/json-endpoints/class.wpcom-json-api-get-site-endpoint.php
@@ -3,32 +3,96 @@
class WPCOM_JSON_API_GET_Site_Endpoint extends WPCOM_JSON_API_Endpoint {
public static $site_format = array(
- 'ID' => '(int) Site ID',
- 'name' => '(string) Title of site',
- 'description' => '(string) Tagline or description of site',
- 'URL' => '(string) Full URL to the site',
- 'jetpack' => '(bool) Whether the site is a Jetpack site or not',
- 'post_count' => '(int) The number of posts the site has',
+ 'ID' => '(int) Site ID',
+ 'name' => '(string) Title of site',
+ 'description' => '(string) Tagline or description of site',
+ 'URL' => '(string) Full URL to the site',
+ 'user_can_manage' => '(bool) The current user can manage this site', // deprecated
+ 'capabilities' => '(array) Array of capabilities for the current user on this site.',
+ 'jetpack' => '(bool) Whether the site is a Jetpack site or not',
+ 'is_multisite' => '(bool) Whether the site is a Multisite site or not. Always true for WP.com sites.',
+ 'post_count' => '(int) The number of posts the site has',
'subscribers_count' => '(int) The number of subscribers the site has',
'lang' => '(string) Primary language code of the site',
'icon' => '(array) An array of icon formats for the site',
'logo' => '(array) The site logo, set in the Customizer',
'visible' => '(bool) If this site is visible in the user\'s site list',
'is_private' => '(bool) If the site is a private site or not',
+ 'single_user_site' => '(bool) Whether the site is single user. Only returned for WP.com sites and for Jetpack sites with version 3.4 or higher.',
+ 'is_vip' => '(bool) If the site is a VIP site or not.',
'is_following' => '(bool) If the current user is subscribed to this site in the reader',
'options' => '(array) An array of options/settings for the blog. Only viewable by users with post editing rights to the site. Note: Post formats is deprecated, please see /sites/$id/post-formats/',
+ 'plan' => '(array) Details of the current plan for this site.',
'updates' => '(array) An array of available updates for plugins, themes, wordpress, and languages.',
'jetpack_modules' => '(array) A list of active Jetpack modules.',
'meta' => '(object) Meta data',
);
+ protected static $site_options_format = array(
+ 'timezone',
+ 'gmt_offset',
+ 'videopress_enabled',
+ 'upgraded_filetypes_enabled',
+ 'login_url',
+ 'admin_url',
+ 'is_mapped_domain',
+ 'is_redirect',
+ 'unmapped_url',
+ 'featured_images_enabled',
+ 'theme_slug',
+ 'header_image',
+ 'background_color',
+ 'image_default_link_type',
+ 'image_thumbnail_width',
+ 'image_thumbnail_height',
+ 'image_thumbnail_crop',
+ 'image_medium_width',
+ 'image_medium_height',
+ 'image_large_width',
+ 'image_large_height',
+ 'permalink_structure',
+ 'post_formats',
+ 'default_post_format',
+ 'default_category',
+ 'allowed_file_types',
+ 'show_on_front',
+ /** This filter is documented in modules/likes.php */
+ 'default_likes_enabled',
+ 'default_sharing_status',
+ 'default_comment_status',
+ 'default_ping_status',
+ 'software_version',
+ 'created_at',
+ 'wordads',
+ 'publicize_permanently_disabled',
+ 'frame_nonce',
+ 'page_on_front',
+ 'page_for_posts',
+ 'ak_vp_bundle_enabled'
+ );
+
+ protected static $jetpack_response_field_additions = array(
+ 'capabilities',
+ 'plan',
+ 'subscribers_count'
+ );
+
+ protected static $jetpack_response_option_additions = array(
+ 'publicize_permanently_disabled',
+ 'ak_vp_bundle_enabled'
+ );
+
+ private $site;
+ // protected $compact = null;
+ protected $fields_to_include = '_all';
+ protected $options_to_include = '_all';
+
// /sites/mine
// /sites/%s -> $blog_id
function callback( $path = '', $blog_id = 0 ) {
- global $wpdb;
if ( 'mine' === $blog_id ) {
$api = WPCOM_JSON_API::init();
- if ( !$api->token_details || empty( $api->token_details['blog_id'] ) ) {
+ if ( ! $api->token_details || empty( $api->token_details['blog_id'] ) ) {
return new WP_Error( 'authorization_required', 'An active access token must be used to query information about the current blog.', 403 );
}
$blog_id = $api->token_details['blog_id'];
@@ -47,14 +111,29 @@ class WPCOM_JSON_API_GET_Site_Endpoint extends WPCOM_JSON_API_Endpoint {
return $response;
}
+ public function filter_fields_and_options() {
+ $query_args = $this->query_args();
+
+ $this->fields_to_include = empty( $query_args['fields'] ) ? '_all' : array_map( 'trim', explode( ',', $query_args['fields'] ) );
+ $this->options_to_include = empty( $query_args['options'] ) ? '_all' : array_map( 'trim', explode( ',', $query_args['options'] ) );
+ }
+
+ protected function include_response_field( $field ) {
+ if ( is_array( $this->fields_to_include ) ) {
+ return in_array( $field, $this->fields_to_include );
+ }
+ return true;
+ }
+
/**
* Collects the necessary information to return for a site's response.
*
* @return (array)
*/
- public function build_current_site_response( ) {
+ public function build_current_site_response() {
+ $blog_id = (int) $this->api->get_blog_id_for_output();
- global $wpdb, $wp_version;
+ $this->site = wpcom_get_sal_site( $blog_id );
// Allow update in later versions
/**
@@ -67,417 +146,317 @@ class WPCOM_JSON_API_GET_Site_Endpoint extends WPCOM_JSON_API_Endpoint {
* @param array $site_format Data structure.
*/
$response_format = apply_filters( 'sites_site_format', self::$site_format );
+ $default_fields = array_keys( apply_filters( 'sites_site_format', self::$site_format ) );
- $is_user_logged_in = is_user_logged_in();
+ $response_keys = is_array( $this->fields_to_include ) ?
+ array_intersect( $default_fields, $this->fields_to_include ) :
+ $default_fields;
- $visible = array();
+ return $this->render_response_keys( $response_keys );
+ }
- if ( $is_user_logged_in ) {
- $current_user = wp_get_current_user();
- $visible = get_user_meta( $current_user->ID, 'blog_visibility', true );
+ private function render_response_keys( &$response_keys ) {
+ $response = array();
- if ( !is_array( $visible ) )
- $visible = array();
+ $is_user_logged_in = is_user_logged_in();
- }
+ $this->site->before_render();
- $blog_id = (int) $this->api->get_blog_id_for_output();
+ foreach ( $response_keys as $key ) {
+ $this->render_response_key( $key, $response, $is_user_logged_in );
+ }
- /** This filter is documented in class.json-api-endpoints.php */
- $is_jetpack = true === apply_filters( 'is_jetpack_site', false, $blog_id );
- $site_url = get_option( 'siteurl' );
+ $this->site->after_render( $response );
- if ( $is_jetpack ) {
- remove_filter( 'option_stylesheet', 'fix_theme_location' );
- if ( 'https' !== parse_url( $site_url, PHP_URL_SCHEME ) ) {
- add_filter( 'set_url_scheme', array( $this, 'force_http' ), 10, 3 );
- }
- }
- foreach ( array_keys( $response_format ) as $key ) {
+ return $response;
+ }
- // refactoring to change parameter to locale in 1.2
- if ( $lang_or_locale = $this->process_locale( $key, $is_user_logged_in ) ) {
- $response[$key] = $lang_or_locale;
- continue;
- }
+ protected function render_response_key( $key, &$response, $is_user_logged_in ) {
+ do_action( 'pre_render_site_response_key', $key );
- switch ( $key ) {
+ switch ( $key ) {
case 'ID' :
- $response[$key] = $blog_id;
+ $response[ $key ] = $this->site->blog_id;
break;
case 'name' :
- $response[$key] = (string) htmlspecialchars_decode( get_bloginfo( 'name' ), ENT_QUOTES );
+ $response[ $key ] = (string) htmlspecialchars_decode( get_bloginfo( 'name' ), ENT_QUOTES );
break;
case 'description' :
- $response[$key] = (string) htmlspecialchars_decode( get_bloginfo( 'description' ), ENT_QUOTES );
+ $response[ $key ] = (string) htmlspecialchars_decode( get_bloginfo( 'description' ), ENT_QUOTES );
break;
case 'URL' :
- $response[$key] = (string) home_url();
- break;
- case 'jetpack' :
- $response[$key] = $is_jetpack; // jetpack magic affects this value
+ $response[ $key ] = (string) home_url();
break;
+ case 'user_can_manage' :
+ $response[ $key ] = $this->site->user_can_manage();
case 'is_private' :
- if ( defined( 'IS_WPCOM' ) && IS_WPCOM ) {
- $public_setting = get_option( 'blog_public' );
- if ( -1 == $public_setting )
- $response[$key] = true;
- else
- $response[$key] = false;
- } else {
- $response[$key] = false; // magic
- }
+ $response[ $key ] = $this->site->is_private();
break;
case 'visible' :
- if ( $is_user_logged_in ){
- $is_visible = true;
- if ( isset( $visible[$blog_id] ) ) {
- $is_visible = (bool) $visible[$blog_id];
- }
- // null and true are visible
- $response[$key] = $is_visible;
- }
+ $response[ $key ] = $this->site->is_visible();
+ break;
+ case 'subscribers_count' :
+ $response[ $key ] = $this->site->get_subscribers_count();
break;
case 'post_count' :
- if ( $is_user_logged_in )
- $response[$key] = (int) $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->posts WHERE post_status = 'publish'");
+ if ( $is_user_logged_in ) {
+ $response[ $key ] = (int) wp_count_posts( 'post' )->publish;
+ }
break;
case 'icon' :
- if ( function_exists( 'blavatar_domain' ) && function_exists( 'blavatar_exists' ) && function_exists( 'blavatar_url' ) ) {
- $domain = blavatar_domain( home_url() );
- if ( blavatar_exists( $domain ) ) {
- $response[ $key ] = array(
- 'img' => (string) remove_query_arg( 's', blavatar_url( $domain, 'img' ) ),
- 'ico' => (string) remove_query_arg( 's', blavatar_url( $domain, 'ico' ) ),
- );
- } else {
- // This is done so that we can access the updated blavatar on .com via the /me/sites endpoint
- if( $is_jetpack ) {
-
- $site_icon_url = get_option( 'jetpack_site_icon_url' );
- if( $site_icon_url ) {
- $response[ $key ] = array(
- 'img' => (string) jetpack_photon_url( $site_icon_url, array() , 'https' ),
- 'ico' => (string) jetpack_photon_url( $site_icon_url, array( 'w' => 16 ), 'https' )
- );
- }
- }
- }
- } elseif ( function_exists( 'jetpack_site_icon_url' ) && function_exists( 'jetpack_photon_url' ) ) {
- $response[ $key ] = array(
- 'img' => (string) jetpack_photon_url( jetpack_site_icon_url( get_current_blog_id() , 80 ), array( 'w' => 80 ), 'https' ),
- 'ico' => (string) jetpack_photon_url( jetpack_site_icon_url( get_current_blog_id() , 16 ), array( 'w' => 16 ), 'https' ),
- );
+ $icon = $this->site->get_icon();
+
+ if ( ! is_null( $icon ) ) {
+ $response[ $key ] = $icon;
}
break;
case 'logo' :
- // Set an empty response array.
- $response[$key] = array(
- 'id' => (int) 0,
- 'sizes' => array(),
- 'url' => '',
- );
-
- // Get current site logo values.
- $logo = get_option( 'site_logo' );
-
- // Update the response array if there's a site logo currenty active.
- if ( $logo && 0 != $logo['id'] ) {
- $response[$key]['id'] = $logo['id'];
- $response[$key]['url'] = $logo['url'];
-
- foreach ( $logo['sizes'] as $size => $properties ) {
- $response[$key]['sizes'][$size] = $properties;
- }
- }
- break;
- case 'subscribers_count' :
-
- if ( function_exists( 'wpcom_subs_total_wpcom_subscribers' ) ) {
- $total_wpcom_subs = wpcom_subs_total_wpcom_subscribers(
- array(
- 'blog_id' => $blog_id,
- )
- );
- $response[$key] = $total_wpcom_subs;
- } else {
- $response[$key] = 0; // magic
- }
+ $response[ $key ] = $this->site->get_logo();
break;
case 'is_following':
- $response[$key] = (bool) $this->api->is_following( $blog_id );
+ $response[ $key ] = $this->site->is_following();
break;
case 'options':
- // Figure out if the blog supports VideoPress, have to do some extra checking for JP blogs
- $has_videopress = false;
- if ( get_option( 'video_upgrade' ) == '1' ) {
- $has_videopress = true;
- } else {
- if ( class_exists( 'Jetpack_Options' ) ) {
- $videopress = Jetpack_Options::get_option( 'videopress', array() );
- if ( isset( $videopress['blog_id'] ) && $videopress['blog_id'] > 0 ) {
- $has_videopress = true;
- }
- }
- }
+ // small optimisation - don't recalculate
+ $all_options = apply_filters( 'sites_site_options_format', self::$site_options_format );
- // deprecated - see separate endpoint. get a list of supported post formats
- $all_formats = get_post_format_strings();
- $supported = get_theme_support( 'post-formats' );
+ $options_response_keys = is_array( $this->options_to_include ) ?
+ array_intersect( $all_options, $this->options_to_include ) :
+ $all_options;
- $supported_formats = array();
+ $options = $this->render_option_keys( $options_response_keys );
- if ( isset( $supported[0] ) ) {
- foreach ( $supported[0] as $format ) {
- $supported_formats[ $format ] = $all_formats[ $format ];
- }
- }
+ $this->site->after_render_options( $options );
- // determine if sharing buttons should be visible by default
- $default_sharing_status = false;
- if ( class_exists( 'Sharing_Service' ) ) {
- $ss = new Sharing_Service();
- $blog_services = $ss->get_blog_services();
- $default_sharing_status = ! empty( $blog_services['visible'] );
+ $response[ $key ] = $options;
+ break;
+ case 'meta':
+ $this->build_meta_response( $response );
+ break;
+ case 'lang' :
+ $response[ $key ] = $is_user_logged_in ? $this->site->get_locale() : false;
+ break;
+ case 'locale' :
+ $response[ $key ] = $is_user_logged_in ? $this->site->get_locale() : false;
+ break;
+ case 'jetpack' :
+ $response[ $key ] = $this->site->is_jetpack();
+ break;
+ case 'single_user_site' :
+ $response[ $key ] = $this->site->is_single_user_site();
+ break;
+ case 'is_vip' :
+ $response[ $key ] = $this->site->is_vip();
+ break;
+ case 'is_multisite' :
+ $response[ $key ] = $this->site->is_multisite();
+ break;
+ case 'capabilities' :
+ $response[ $key ] = $this->site->get_capabilities();
+ break;
+ case 'jetpack_modules':
+ $jetpack_modules = $this->site->get_jetpack_modules();
+ if ( ! is_null( $jetpack_modules ) ) {
+ $response[ $key ] = $jetpack_modules;
}
+ break;
+ case 'plan' :
+ $response[ $key ] = $this->site->get_plan();
+ break;
+ }
- $is_mapped_domain = false;
+ do_action( 'post_render_site_response_key', $key );
+ }
- if ( function_exists( 'get_primary_redirect' ) ) {
- $primary_redirect = strtolower( get_primary_redirect() );
- if ( false === strpos( $primary_redirect, '.wordpress.com' ) ) {
- $is_mapped_domain = true;
- }
- }
+ protected function render_option_keys( &$options_response_keys ) {
+ if ( ! current_user_can( 'edit_posts' ) ) {
+ return;
+ }
- $is_redirect = false;
+ global $wp_version;
- if ( function_exists( 'get_primary_domain_mapping_record' ) ) {
- if ( get_primary_domain_mapping_record()->type == 1 ) {
- $is_redirect = true;
- }
- }
+ $options = array();
- if ( function_exists( 'get_mime_types' ) ) {
- $allowed_file_types = get_mime_types();
- } else {
- // http://codex.wordpress.org/Uploading_Files
- $mime_types = get_allowed_mime_types();
- foreach ( $mime_types as $type => $mime_type ) {
- $extras = explode( '|', $type );
- foreach ( $extras as $extra ) {
- $allowed_file_types[] = $extra;
- }
- }
- }
+ $custom_front_page = ( 'page' === get_option( 'show_on_front' ) );
- if ( function_exists( 'get_blog_details' ) ) {
- $blog_details = get_blog_details();
- if ( ! empty( $blog_details->registered ) ) {
- $registered_date = $blog_details->registered;
+ foreach ( $options_response_keys as $key ) {
+ switch ( $key ) {
+ case 'timezone' :
+ $options[ $key ] = (string) get_option( 'timezone_string' );
+ break;
+ case 'gmt_offset' :
+ $options[ $key ] = (float) get_option( 'gmt_offset' );
+ break;
+ case 'videopress_enabled' :
+ $options[ $key ] = $this->site->has_videopress();
+ break;
+ case 'upgraded_filetypes_enabled' :
+ $options[ $key ] = $this->site->upgraded_filetypes_enabled();
+ break;
+ case 'login_url' :
+ $options[ $key ] = wp_login_url();
+ break;
+ case 'admin_url' :
+ $options[ $key ] = get_admin_url();
+ break;
+ case 'is_mapped_domain' :
+ $options[ $key ] = $this->site->is_mapped_domain();
+ break;
+ case 'is_redirect' :
+ $options[ $key ] = $this->site->is_redirect();
+ break;
+ case 'unmapped_url' :
+ $options[ $key ] = get_site_url( $this->site->blog_id );
+ break;
+ case 'featured_images_enabled' :
+ $options[ $key ] = $this->site->featured_images_enabled();
+ break;
+ case 'theme_slug' :
+ $options[ $key ] = get_option( 'stylesheet' );
+ break;
+ case 'header_image' :
+ $options[ $key ] = get_theme_mod( 'header_image_data' );
+ break;
+ case 'background_color' :
+ $options[ $key ] = get_theme_mod( 'background_color' );
+ break;
+ case 'image_default_link_type' :
+ $options[ $key ] = get_option( 'image_default_link_type' );
+ break;
+ case 'image_thumbnail_width' :
+ $options[ $key ] = (int) get_option( 'thumbnail_size_w' );
+ break;
+ case 'image_thumbnail_height' :
+ $options[ $key ] = (int) get_option( 'thumbnail_size_h' );
+ break;
+ case 'image_thumbnail_crop' :
+ $options[ $key ] = get_option( 'thumbnail_crop' );
+ break;
+ case 'image_medium_width' :
+ $options[ $key ] = (int) get_option( 'medium_size_w' );
+ break;
+ case 'image_medium_height' :
+ $options[ $key ] = (int) get_option( 'medium_size_h' );
+ break;
+ case 'image_large_width' :
+ $options[ $key ] = (int) get_option( 'large_size_w' );
+ break;
+ case 'image_large_height' :
+ $options[ $key ] = (int) get_option( 'large_size_h' );
+ break;
+ case 'permalink_structure' :
+ $options[ $key ] = get_option( 'permalink_structure' );
+ break;
+ case 'post_formats' :
+ $options[ $key ] = $this->site->get_post_formats();
+ break;
+ case 'default_post_format' :
+ $options[ $key ] = get_option( 'default_post_format' );
+ break;
+ case 'default_category' :
+ $options[ $key ] = (int) get_option( 'default_category' );
+ break;
+ case 'allowed_file_types' :
+ $options[ $key ] = $this->site->allowed_file_types();
+ break;
+ case 'show_on_front' :
+ $options[ $key ] = get_option( 'show_on_front' );
+ break;
+ /** This filter is documented in modules/likes.php */
+ case 'default_likes_enabled' :
+ $options[ $key ] = (bool) apply_filters( 'wpl_is_enabled_sitewide', ! get_option( 'disabled_likes' ) );
+ break;
+ case 'default_sharing_status' :
+ $default_sharing_status = false;
+ if ( class_exists( 'Sharing_Service' ) ) {
+ $ss = new Sharing_Service();
+ $blog_services = $ss->get_blog_services();
+ $default_sharing_status = ! empty( $blog_services['visible'] );
}
- }
-
- $upgraded_filetypes_enabled = false;
- if ( $is_jetpack || get_option( 'use_upgraded_upload_filetypes' ) ) {
- $upgraded_filetypes_enabled = true;
- }
-
- $wordads = false;
- if ( function_exists( 'has_any_blog_stickers' ) ) {
- $wordads = has_any_blog_stickers( array( 'wordads-approved', 'wordads-approved-misfits' ), $blog_id );
- }
-
- $publicize_permanently_disabled = false;
- if ( function_exists( 'is_publicize_permanently_disabled' ) ) {
- $publicize_permanently_disabled = is_publicize_permanently_disabled( $blog_id );
- }
-
- $frame_nonce = false;
- if ( ! $is_jetpack ) {
- $frame_nonce = wpcom_get_frame_nonce();
- }
-
- $response[$key] = array(
- 'timezone' => (string) get_option( 'timezone_string' ),
- 'gmt_offset' => (float) get_option( 'gmt_offset' ),
- 'videopress_enabled' => $has_videopress,
- 'upgraded_filetypes_enabled' => $upgraded_filetypes_enabled,
- 'login_url' => wp_login_url(),
- 'admin_url' => get_admin_url(),
- 'is_mapped_domain' => $is_mapped_domain,
- 'is_redirect' => $is_redirect,
- 'unmapped_url' => get_site_url( $blog_id ),
- 'featured_images_enabled' => current_theme_supports( 'post-thumbnails' ),
- 'theme_slug' => get_option( 'stylesheet' ),
- 'header_image' => get_theme_mod( 'header_image_data' ),
- 'background_color' => get_theme_mod( 'background_color' ),
- 'image_default_link_type' => get_option( 'image_default_link_type' ),
- 'image_thumbnail_width' => (int) get_option( 'thumbnail_size_w' ),
- 'image_thumbnail_height' => (int) get_option( 'thumbnail_size_h' ),
- 'image_thumbnail_crop' => get_option( 'thumbnail_crop' ),
- 'image_medium_width' => (int) get_option( 'medium_size_w' ),
- 'image_medium_height' => (int) get_option( 'medium_size_h' ),
- 'image_large_width' => (int) get_option( 'large_size_w' ),
- 'image_large_height' => (int) get_option( 'large_size_h' ),
- 'permalink_structure' => get_option( 'permalink_structure' ),
- 'post_formats' => $supported_formats,
- 'default_post_format' => get_option( 'default_post_format' ),
- 'default_category' => (int) get_option( 'default_category' ),
- 'allowed_file_types' => $allowed_file_types,
- 'show_on_front' => get_option( 'show_on_front' ),
- /** This filter is documented in modules/likes.php */
- 'default_likes_enabled' => (bool) apply_filters( 'wpl_is_enabled_sitewide', ! get_option( 'disabled_likes' ) ),
- 'default_sharing_status' => (bool) $default_sharing_status,
- 'default_comment_status' => ( 'closed' == get_option( 'default_comment_status' ) ? false : true ),
- 'default_ping_status' => ( 'closed' == get_option( 'default_ping_status' ) ? false : true ),
- 'software_version' => $wp_version,
- 'created_at' => ! empty( $registered_date ) ? $this->format_date( $registered_date ) : '0000-00-00T00:00:00+00:00',
- 'wordads' => $wordads,
- 'publicize_permanently_disabled' => $publicize_permanently_disabled,
- 'frame_nonce' => $frame_nonce,
- );
-
- if ( 'page' === get_option( 'show_on_front' ) ) {
- $response['options']['page_on_front'] = (int) get_option( 'page_on_front' );
- $response['options']['page_for_posts'] = (int) get_option( 'page_for_posts' );
- }
-
- if ( $is_jetpack ) {
- $response['options']['jetpack_version'] = get_option( 'jetpack_version' );
-
- if ( get_option( 'jetpack_main_network_site' ) ) {
- $response['options']['main_network_site'] = (string) rtrim( get_option( 'jetpack_main_network_site' ), '/' );
+ $options[ $key ] = (bool) $default_sharing_status;
+ break;
+ case 'default_comment_status' :
+ $options[ $key ] = 'closed' !== get_option( 'default_comment_status' );
+ break;
+ case 'default_ping_status' :
+ $options[ $key ] = 'closed' !== get_option( 'default_ping_status' );
+ break;
+ case 'software_version' :
+ $options[ $key ] = $wp_version;
+ break;
+ case 'created_at' :
+ $options[ $key ] = $this->site->get_registered_date();
+ break;
+ case 'wordads' :
+ $options[ $key ] = $this->site->has_wordads();
+ break;
+ case 'publicize_permanently_disabled' :
+ $publicize_permanently_disabled = false;
+ if ( function_exists( 'is_publicize_permanently_disabled' ) ) {
+ $publicize_permanently_disabled = is_publicize_permanently_disabled( $this->site->blog_id );
}
-
- if ( is_array( Jetpack_Options::get_option( 'active_modules' ) ) ) {
- $response['options']['active_modules'] = (array) array_values( Jetpack_Options::get_option( 'active_modules' ) );
+ $options[ $key ] = $publicize_permanently_disabled;
+ break;
+ case 'frame_nonce' :
+ $options[ $key ] = $this->site->get_frame_nonce();
+ break;
+ case 'page_on_front' :
+ if ( $custom_front_page ) {
+ $options[ $key ] = (int) get_option( 'page_on_front' );
}
-
- if ( $jetpack_wp_version = get_option( 'jetpack_wp_version' ) ) {
- $response['options']['software_version'] = (string) $jetpack_wp_version;
- } else if ( $jetpack_update = get_option( 'jetpack_updates' ) ) {
- if ( is_array( $jetpack_update ) && isset( $jetpack_update['wp_version'] ) ) {
- $response['options']['software_version'] = (string) $jetpack_update['wp_version'];
- } else {
- $response[ 'options' ][ 'software_version' ] = null;
- }
- } else {
- $response['options']['software_version'] = null;
+ break;
+ case 'page_for_posts' :
+ if ( $custom_front_page ) {
+ $options[ $key ] = (int) get_option( 'page_for_posts' );
}
+ break;
+ case 'ak_vp_bundle_enabled' :
+ $options[ $key ] = $this->site->get_ak_vp_bundle_enabled();
+ }
+ }
- $response['options']['max_upload_size'] = get_option( 'jetpack_max_upload_size', false );
-
- // Sites have to prove that they are not main_network site.
- // If the sync happends right then we should be able to see that we are not dealing with a network site
- $response['options']['is_multi_network'] = (bool) get_option( 'jetpack_is_main_network', true );
- $response['options']['is_multi_site'] = (bool) get_option( 'jetpack_is_multi_site', true );
-
- $file_mod_denied_reason = array();
- $file_mod_denied_reason['automatic_updater_disabled'] = (bool) get_option( 'jetpack_constant_AUTOMATIC_UPDATER_DISABLED' );
-
- // WP AUTO UPDATE CORE defaults to minor, '1' if true and '0' if set to false.
- $file_mod_denied_reason['wp_auto_update_core_disabled'] = ! ( (bool) get_option( 'jetpack_constant_WP_AUTO_UPDATE_CORE', 'minor' ) );
- $file_mod_denied_reason['is_version_controlled'] = (bool) get_option( 'jetpack_is_version_controlled' );
+ return $options;
+ }
- // By default we assume that site does have system write access if the value is not set yet.
- $file_mod_denied_reason['has_no_file_system_write_access'] = ! (bool)( get_option( 'jetpack_has_file_system_write_access', true ) );
+ protected function build_meta_response( &$response ) {
+ $xmlrpc_scheme = apply_filters( 'wpcom_json_api_xmlrpc_scheme', parse_url( get_option( 'home' ), PHP_URL_SCHEME ) );
+ $xmlrpc_url = site_url( 'xmlrpc.php', $xmlrpc_scheme );
+ $response['meta'] = (object) array(
+ 'links' => (object) array(
+ 'self' => (string) $this->get_site_link( $this->site->blog_id ),
+ 'help' => (string) $this->get_site_link( $this->site->blog_id, 'help' ),
+ 'posts' => (string) $this->get_site_link( $this->site->blog_id, 'posts/' ),
+ 'comments' => (string) $this->get_site_link( $this->site->blog_id, 'comments/' ),
+ 'xmlrpc' => (string) $xmlrpc_url,
+ ),
+ );
+ }
- $file_mod_denied_reason['disallow_file_mods'] = (bool) get_option( 'jetpack_constant_DISALLOW_FILE_MODS' );
+ // apply any WPCOM-only response components to a Jetpack site response
+ public function decorate_jetpack_response( &$response ) {
+ $this->site = wpcom_get_sal_site( $blog_id );
- $file_mod_disabled_reasons = array();
- foreach( $file_mod_denied_reason as $reason => $set ) {
- if ( $set ) {
- $file_mod_disabled_reasons[] = $reason;
- }
- }
- $response['options']['file_mod_disabled'] = empty( $file_mod_disabled_reasons ) ? false : $file_mod_disabled_reasons;
- }
+ // ensure the response is marked as being from Jetpack
+ $response->jetpack = true;
- if ( ! current_user_can( 'edit_posts' ) )
- unset( $response[$key] );
- break;
- case 'jetpack_modules':
- if ( ! $is_jetpack || ! is_user_member_of_blog() ) {
- break;
- }
- $response[$key] = array_values( Jetpack_Options::get_option( 'active_modules', array() ) );
- break;
- case 'meta':
- /**
- * Filters the URL scheme used when querying your site's REST API endpoint.
- *
- * @module json-api
- *
- * @since 3.2.0
- *
- * @param string parse_url( get_option( 'home' ), PHP_URL_SCHEME ) URL scheme parsed from home URL.
- */
- $xmlrpc_scheme = apply_filters( 'wpcom_json_api_xmlrpc_scheme', parse_url( get_option( 'home' ), PHP_URL_SCHEME ) );
- $xmlrpc_url = site_url( 'xmlrpc.php', $xmlrpc_scheme );
- $response[$key] = (object) array(
- 'links' => (object) array(
- 'self' => (string) $this->get_site_link( $blog_id ),
- 'help' => (string) $this->get_site_link( $blog_id, 'help' ),
- 'posts' => (string) $this->get_site_link( $blog_id, 'posts/' ),
- 'comments' => (string) $this->get_site_link( $blog_id, 'comments/' ),
- 'xmlrpc' => (string) $xmlrpc_url,
- ),
- );
- break;
- }
- }
+ $wpcom_response = $this->render_response_keys( self::$jetpack_response_field_additions );
- if ( $is_jetpack ) {
- // Add the updates only make them visible if the user has manage options permission and the site is the main site of the network
- if ( current_user_can( 'manage_options' ) ) {
- if ( isset( $response['options']['main_network_site'], $response['options']['unmapped_url'] ) ) {
- $main_network_site_url = set_url_scheme( $response['options']['main_network_site'], 'http' );
- $unmapped_url = set_url_scheme( $response['options']['unmapped_url'], 'http' );
- if ( $unmapped_url === $main_network_site_url ) {
- $jetpack_update = (array) get_option( 'jetpack_updates' );
- if ( ! empty( $jetpack_update ) ) {
- if ( isset( $jetpack_update['wp_version'] ) ) {
- // In previous version of Jetpack 3.4, 3.5, 3.6 we synced the wp_version into to jetpack_updates
- unset( $jetpack_update['wp_version'] );
- }
- if ( isset( $jetpack_update['site_is_version_controlled'] ) ) {
- // In previous version of Jetpack 3.4, 3.5, 3.6 we synced the site_is_version_controlled into to jetpack_updates
- unset( $jetpack_update['site_is_version_controlled'] );
- }
- $response['updates'] = (array) $jetpack_update;
- }
- }
- }
- }
- if ( defined( 'IS_WPCOM' ) && IS_WPCOM ) {
- add_filter( 'option_stylesheet', 'fix_theme_location' );
- }
- if ( 'https' !== parse_url( $site_url, PHP_URL_SCHEME ) ) {
- remove_filter( 'set_url_scheme', array( $this, 'force_http' ), 10, 3 );
- }
+ foreach( $wpcom_response as $key => $value ) {
+ $response->{ $key } = $value;
}
- return $response;
+ // render additional options
+ if ( $response->options ) {
+ $wpcom_options_response = $this->render_option_keys( self::$jetpack_response_option_additions );
- }
-
- protected function process_locale( $key, $is_user_logged_in ) {
- if ( $is_user_logged_in && 'lang' == $key ) {
- if ( defined( 'IS_WPCOM' ) && IS_WPCOM ) {
- if ( ! is_jetpack_site() ) {
- return (string) get_blog_lang_code();
- }
+ foreach( $wpcom_options_response as $key => $value ) {
+ $response->options[ $key ] = $value;
}
return (string) get_bloginfo( 'language' );
}
- return false;
- }
- function force_http( $url, $scheme, $orig_scheme ) {
- return preg_replace('/^https:\/\//', 'http://', $url, 1 );
+ return $response; // possibly no need since it's modified in place
}
-
}
class WPCOM_JSON_API_List_Post_Formats_Endpoint extends WPCOM_JSON_API_Endpoint {