Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 35 |
|
0.00% |
0 / 2 |
CRAP | |
0.00% |
0 / 1 |
| WPCOM_JSON_API_GET_Site_V1_2_Endpoint | |
0.00% |
0 / 10 |
|
0.00% |
0 / 2 |
56 | |
0.00% |
0 / 1 |
| callback | |
0.00% |
0 / 9 |
|
0.00% |
0 / 1 |
42 | |||
| site_format | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| 1 | <?php // phpcs:ignore WordPress.Files.FileName.InvalidClassFileName |
| 2 | |
| 3 | if ( ! defined( 'ABSPATH' ) ) { |
| 4 | exit( 0 ); |
| 5 | } |
| 6 | |
| 7 | new WPCOM_JSON_API_GET_Site_V1_2_Endpoint( |
| 8 | array( |
| 9 | 'description' => 'Get information about a site.', |
| 10 | 'group' => 'sites', |
| 11 | 'stat' => 'sites:X', |
| 12 | 'allowed_if_flagged' => true, |
| 13 | 'method' => 'GET', |
| 14 | 'min_version' => '1.2', |
| 15 | 'path' => '/sites/%s', |
| 16 | 'path_labels' => array( |
| 17 | '$site' => '(int|string) Site ID or domain', |
| 18 | ), |
| 19 | 'rest_route' => '/site', |
| 20 | 'rest_min_jp_version' => '14.5-a.2', |
| 21 | |
| 22 | 'allow_fallback_to_jetpack_blog_token' => true, |
| 23 | |
| 24 | 'query_parameters' => array( |
| 25 | 'context' => false, |
| 26 | 'filters' => '(string) Optional. Returns sites that satisfy the given filters only. Example: filters=jetpack,atomic,wpcom', |
| 27 | ), |
| 28 | |
| 29 | 'response_format' => WPCOM_JSON_API_GET_Site_V1_2_Endpoint::$site_format, |
| 30 | |
| 31 | 'example_request' => 'https://public-api.wordpress.com/rest/v1.2/sites/en.blog.wordpress.com/', |
| 32 | ) |
| 33 | ); |
| 34 | |
| 35 | /** |
| 36 | * GET Site v1_2 endpoint. |
| 37 | * |
| 38 | * @phan-constructor-used-for-side-effects |
| 39 | */ |
| 40 | class WPCOM_JSON_API_GET_Site_V1_2_Endpoint extends WPCOM_JSON_API_GET_Site_Endpoint { |
| 41 | |
| 42 | /** |
| 43 | * Site format array. |
| 44 | * |
| 45 | * @var array $site_format |
| 46 | */ |
| 47 | public static $site_format = array( |
| 48 | 'ID' => '(int) Site ID', |
| 49 | 'name' => '(string) Title of site', |
| 50 | 'description' => '(string) Tagline or description of site', |
| 51 | 'URL' => '(string) Full URL to the site', |
| 52 | 'capabilities' => '(array) Array of capabilities for the current user on this site.', |
| 53 | 'jetpack' => '(bool) Whether the site is a Jetpack site or not', |
| 54 | 'jetpack_connection' => '(bool) Whether the site is connected to WP.com via `jetpack-connection`', |
| 55 | 'is_multisite' => '(bool) Whether the site is a Multisite site or not. Always true for WP.com sites.', |
| 56 | 'site_owner' => '(int) User ID of the site owner', |
| 57 | 'post_count' => '(int) The number of posts the site has', |
| 58 | 'subscribers_count' => '(int) The number of subscribers the site has', |
| 59 | 'locale' => '(string) Primary locale code of the site', |
| 60 | 'icon' => '(array) An array of icon formats for the site', |
| 61 | 'logo' => '(array) The site logo, set in the Customizer', |
| 62 | 'visible' => '(bool) If this site is visible in the user\'s site list', |
| 63 | 'is_private' => '(bool) If the site is a private site or not', |
| 64 | 'is_coming_soon' => '(bool) If the site is a "coming soon" site or not', |
| 65 | '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.', |
| 66 | 'is_vip' => '(bool) If the site is a VIP site or not.', |
| 67 | 'is_following' => '(bool) If the current user is subscribed to this site in the reader', |
| 68 | 'organization_id' => '(int) P2 Organization identifier.', |
| 69 | '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/', |
| 70 | 'plan' => '(array) Details of the current plan for this site.', |
| 71 | 'products' => '(array) Details of the current products for this site.', |
| 72 | 'zendesk_site_meta' => '(array) Site meta data for Zendesk.', |
| 73 | 'updates' => '(array) An array of available updates for plugins, themes, wordpress, and languages.', |
| 74 | 'jetpack_modules' => '(array) A list of active Jetpack modules.', |
| 75 | 'meta' => '(object) Meta data', |
| 76 | 'quota' => '(array) An array describing how much space a user has left for uploads', |
| 77 | 'launch_status' => '(string) A string describing the launch status of a site', |
| 78 | 'site_migration' => '(array) Data about any migration into the site.', |
| 79 | 'is_fse_active' => '(bool) If the site has Full Site Editing active or not.', |
| 80 | 'is_fse_eligible' => '(bool) If the site is capable of Full Site Editing or not', |
| 81 | 'is_core_site_editor_enabled' => '(bool) If the site has the core site editor enabled.', |
| 82 | 'is_wpcom_atomic' => '(bool) If the site is a WP.com Atomic one.', |
| 83 | 'is_wpcom_staging_site' => '(bool) If the site is a WP.com staging site.', |
| 84 | 'was_ecommerce_trial' => '(bool) If the site ever used an eCommerce trial.', |
| 85 | 'was_upgraded_from_trial' => '(bool) If the site ever upgraded to a paid plan from a trial.', |
| 86 | 'was_migration_trial' => '(bool) If the site ever used a migration trial.', |
| 87 | 'was_hosting_trial' => '(bool) If the site ever used a hosting trial.', |
| 88 | 'is_deleted' => '(bool) If the site flagged as deleted.', |
| 89 | 'is_a4a_client' => '(bool) If the site is an A4A client site.', |
| 90 | 'is_a4a_dev_site' => '(bool) If the site is an A4A dev site.', |
| 91 | ); |
| 92 | |
| 93 | /** |
| 94 | * |
| 95 | * API callback. |
| 96 | * |
| 97 | * @param string $path - the path. |
| 98 | * @param int $blog_id - the blog ID. |
| 99 | */ |
| 100 | public function callback( $path = '', $blog_id = 0 ) { |
| 101 | add_filter( 'sites_site_format', array( $this, 'site_format' ) ); |
| 102 | |
| 103 | // Site filtering is a WPCOM concept, once a request gets anywhere else it should just be returned |
| 104 | if ( defined( 'IS_WPCOM' ) && IS_WPCOM ) { |
| 105 | // Apply filter here, return same error as switch_to_blog_and_validate_user if blog is not found. |
| 106 | require_lib( 'site-filter' ); |
| 107 | $filters = Site_Filter::process_query_arg( $this->query_args() ); |
| 108 | if ( is_wp_error( $filters ) ) { |
| 109 | return $filters; |
| 110 | } |
| 111 | if ( ! empty( $filters ) && ! Site_Filter::filter_blog( $this->api->get_blog_id( $blog_id ), $filters ) ) { |
| 112 | return new WP_Error( 'unknown_blog', 'Unknown blog', 404 ); |
| 113 | } |
| 114 | } |
| 115 | |
| 116 | return parent::callback( $path, $blog_id ); |
| 117 | } |
| 118 | |
| 119 | /** |
| 120 | * Site format. |
| 121 | * |
| 122 | * @param string $format - the format. |
| 123 | */ |
| 124 | public function site_format( $format ) { // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable |
| 125 | return self::$site_format; |
| 126 | } |
| 127 | } |