← All changes
|
json-endpoints/class.wpcom-json-api-site-settings-v1-2-endpoint.php
+220
-0
16.2-beta
→
16.3-beta
View file →
| @@ -1,0 +1,220 @@ | ||
| 1 | +<?php // phpcs:ignore WordPress.Files.FileName.InvalidClassFileName | |
| 2 | + | |
| 3 | +if ( ! defined( 'ABSPATH' ) ) { | |
| 4 | + exit( 0 ); | |
| 5 | +} | |
| 6 | + | |
| 7 | +new WPCOM_JSON_API_Site_Settings_V1_2_Endpoint( | |
| 8 | + array( | |
| 9 | + 'description' => 'Get detailed settings information about a site.', | |
| 10 | + 'group' => '__do_not_document', | |
| 11 | + 'stat' => 'sites:X', | |
| 12 | + 'min_version' => '1.2', | |
| 13 | + 'method' => 'GET', | |
| 14 | + 'path' => '/sites/%s/settings', | |
| 15 | + 'path_labels' => array( | |
| 16 | + '$site' => '(int|string) Site ID or domain', | |
| 17 | + ), | |
| 18 | + | |
| 19 | + 'query_parameters' => array( | |
| 20 | + 'context' => false, | |
| 21 | + ), | |
| 22 | + | |
| 23 | + 'response_format' => WPCOM_JSON_API_Site_Settings_Endpoint::$site_format, | |
| 24 | + | |
| 25 | + 'example_request' => 'https://public-api.wordpress.com/rest/v1.2/sites/en.blog.wordpress.com/settings?pretty=1', | |
| 26 | + ) | |
| 27 | +); | |
| 28 | + | |
| 29 | +new WPCOM_JSON_API_Site_Settings_V1_2_Endpoint( | |
| 30 | + array( | |
| 31 | + 'description' => 'Update settings for a site.', | |
| 32 | + 'group' => '__do_not_document', | |
| 33 | + 'stat' => 'sites:X', | |
| 34 | + 'min_version' => '1.2', | |
| 35 | + 'method' => 'POST', | |
| 36 | + 'path' => '/sites/%s/settings', | |
| 37 | + 'path_labels' => array( | |
| 38 | + '$site' => '(int|string) Site ID or domain', | |
| 39 | + ), | |
| 40 | + | |
| 41 | + 'request_format' => array( | |
| 42 | + 'blogname' => '(string) Blog name', | |
| 43 | + 'blogdescription' => '(string) Blog description', | |
| 44 | + 'default_pingback_flag' => '(bool) Notify blogs linked from article?', | |
| 45 | + 'default_ping_status' => '(bool) Allow link notifications from other blogs?', | |
| 46 | + 'default_comment_status' => '(bool) Allow comments on new articles?', | |
| 47 | + 'blog_public' => '(string) Site visibility; -1: private, 0: discourage search engines, 1: allow search engines', | |
| 48 | + 'jetpack_sync_non_public_post_stati' => '(bool) allow sync of post and pages with non-public posts stati', | |
| 49 | + 'jetpack_relatedposts_enabled' => '(bool) Enable related posts?', | |
| 50 | + 'jetpack_relatedposts_show_context' => '(bool) Show post\'s tags and category in related posts?', | |
| 51 | + 'jetpack_relatedposts_show_date' => '(bool) Show date in related posts?', | |
| 52 | + 'jetpack_relatedposts_show_headline' => '(bool) Show headline in related posts?', | |
| 53 | + 'jetpack_relatedposts_show_thumbnails' => '(bool) Show thumbnails in related posts?', | |
| 54 | + 'instant_search_enabled' => '(bool) Enable the new Jetpack Instant Search interface', | |
| 55 | + 'jetpack_search_enabled' => '(bool) Enable Jetpack Search', | |
| 56 | + 'jetpack_search_supported' => '(bool) Jetpack Search supported', | |
| 57 | + 'jetpack_protect_whitelist' => '(array) List of IP addresses to always allow', | |
| 58 | + 'infinite_scroll' => '(bool) Support infinite scroll of posts?', | |
| 59 | + 'default_category' => '(int) Default post category', | |
| 60 | + 'default_post_format' => '(string) Default post format', | |
| 61 | + 'require_name_email' => '(bool) Require comment authors to fill out name and email?', | |
| 62 | + 'comment_registration' => '(bool) Require users to be registered and logged in to comment?', | |
| 63 | + 'close_comments_for_old_posts' => '(bool) Automatically close comments on old posts?', | |
| 64 | + 'close_comments_days_old' => '(int) Age at which to close comments', | |
| 65 | + 'thread_comments' => '(bool) Enable threaded comments?', | |
| 66 | + 'thread_comments_depth' => '(int) Depth to thread comments', | |
| 67 | + 'page_comments' => '(bool) Break comments into pages?', | |
| 68 | + 'comments_per_page' => '(int) Number of comments to display per page', | |
| 69 | + 'default_comments_page' => '(string) newest|oldest Which page of comments to display first', | |
| 70 | + 'comment_order' => '(string) asc|desc Order to display comments within page', | |
| 71 | + 'comments_notify' => '(bool) Email me when someone comments?', | |
| 72 | + 'moderation_notify' => '(bool) Email me when a comment is helf for moderation?', | |
| 73 | + 'social_notifications_like' => '(bool) Email me when someone likes my post?', | |
| 74 | + 'social_notifications_reblog' => '(bool) Email me when someone reblogs my post?', | |
| 75 | + 'social_notifications_subscribe' => '(bool) Email me when someone subscribes to my blog?', | |
| 76 | + 'comment_moderation' => '(bool) Moderate comments for manual approval?', | |
| 77 | + 'comment_previously_approved' => '(bool) Moderate comments unless author has a previously-approved comment?', | |
| 78 | + 'comment_max_links' => '(int) Moderate comments that contain X or more links', | |
| 79 | + 'moderation_keys' => '(string) Words or phrases that trigger comment moderation, one per line', | |
| 80 | + 'disallowed_keys' => '(string) Words or phrases that mark comment spam, one per line', | |
| 81 | + 'lang_id' => '(int) ID for language blog is written in', | |
| 82 | + 'locale' => '(string) locale code for language blog is written in', | |
| 83 | + 'wga' => '(array) Google Analytics Settings', | |
| 84 | + 'disabled_likes' => '(bool) Are likes globally disabled (they can still be turned on per post)?', | |
| 85 | + 'disabled_reblogs' => '(bool) Are reblogs disabled on posts?', | |
| 86 | + 'jetpack_comment_likes_enabled' => '(bool) Are comment likes enabled for all comments?', | |
| 87 | + 'sharing_button_style' => '(string) Style to use for sharing buttons (icon-text, icon, text, or official)', | |
| 88 | + 'sharing_label' => '(string) Label to use for sharing buttons, e.g. "Share this:"', | |
| 89 | + 'sharing_show' => '(string|array:string) Post type or array of types where sharing buttons are to be displayed', | |
| 90 | + 'sharing_open_links' => '(string) Link target for sharing buttons (same or new)', | |
| 91 | + 'twitter_via' => '(string) Twitter username to include in tweets when people share using the Twitter button', | |
| 92 | + 'jetpack-twitter-cards-site-tag' => '(string) The Twitter username of the owner of the site\'s domain.', | |
| 93 | + 'eventbrite_api_token' => '(int) The Keyring token ID for an Eventbrite token to associate with the site', | |
| 94 | + 'timezone_string' => '(string) PHP-compatible timezone string like \'UTC-5\'', | |
| 95 | + 'gmt_offset' => '(int) Site offset from UTC in hours', | |
| 96 | + 'date_format' => '(string) PHP Date-compatible date format', | |
| 97 | + 'time_format' => '(string) PHP Date-compatible time format', | |
| 98 | + 'start_of_week' => '(int) Starting day of week (0 = Sunday, 6 = Saturday)', | |
| 99 | + 'jetpack_testimonial' => '(bool) Whether testimonial custom post type is enabled for the site', | |
| 100 | + 'jetpack_testimonial_posts_per_page' => '(int) Number of testimonials to show per page', | |
| 101 | + 'jetpack_portfolio' => '(bool) Whether portfolio custom post type is enabled for the site', | |
| 102 | + 'jetpack_portfolio_posts_per_page' => '(int) Number of portfolio projects to show per page', | |
| 103 | + Jetpack_SEO_Utils::FRONT_PAGE_META_OPTION => '(string) The SEO meta description for the site.', | |
| 104 | + Jetpack_SEO_Titles::TITLE_FORMATS_OPTION => '(array) SEO meta title formats. Allowed keys: front_page, posts, pages, groups, archives', | |
| 105 | + 'verification_services_codes' => '(array) Website verification codes. Allowed keys: google, pinterest, bing, yandex, facebook', | |
| 106 | + 'podcasting_archive' => '(string) The post category, if any, used for publishing podcasts', | |
| 107 | + 'site_icon' => '(int) Media attachment ID to use as site icon. Set to zero or an otherwise empty value to clear', | |
| 108 | + 'api_cache' => '(bool) Turn on/off the Jetpack JSON API cache', | |
| 109 | + 'posts_per_page' => '(int) Number of posts to show on blog pages', | |
| 110 | + 'posts_per_rss' => '(int) Number of posts to show in the RSS feed', | |
| 111 | + 'rss_use_excerpt' => '(bool) Whether the RSS feed will use post excerpts', | |
| 112 | + 'wpcom_publish_posts_with_markdown' => '(bool) Whether markdown is enabled for posts', | |
| 113 | + 'wpcom_publish_comments_with_markdown' => '(bool) Whether markdown is enabled for comments', | |
| 114 | + ), | |
| 115 | + | |
| 116 | + 'response_format' => array( | |
| 117 | + 'updated' => '(array)', | |
| 118 | + ), | |
| 119 | + | |
| 120 | + 'example_request' => 'https://public-api.wordpress.com/rest/v1/sites/en.blog.wordpress.com/settings?pretty=1', | |
| 121 | + ) | |
| 122 | +); | |
| 123 | + | |
| 124 | +/** | |
| 125 | + * Site settings v1_2 endpoint. | |
| 126 | + * | |
| 127 | + * @phan-constructor-used-for-side-effects | |
| 128 | + */ | |
| 129 | +class WPCOM_JSON_API_Site_Settings_V1_2_Endpoint extends WPCOM_JSON_API_Site_Settings_Endpoint { | |
| 130 | + | |
| 131 | + /** | |
| 132 | + * Site format. | |
| 133 | + * | |
| 134 | + * @var array | |
| 135 | + */ | |
| 136 | + public static $site_format = array( | |
| 137 | + 'ID' => '(int) Site ID', | |
| 138 | + 'name' => '(string) Title of site', | |
| 139 | + 'description' => '(string) Tagline or description of site', | |
| 140 | + 'URL' => '(string) Full URL to the site', | |
| 141 | + 'locale' => '(string) Locale code of the site', | |
| 142 | + 'locale_variant' => '(string) Locale variant code for the site, if set', | |
| 143 | + 'settings' => '(array) An array of options/settings for the blog. Only viewable by users with post editing rights to the site.', | |
| 144 | + ); | |
| 145 | + | |
| 146 | + /** | |
| 147 | + * API Callback. | |
| 148 | + * | |
| 149 | + * @param string $path - the path. | |
| 150 | + * @param int $blog_id - the blog ID. | |
| 151 | + * | |
| 152 | + * @return array|WP_Error | |
| 153 | + */ | |
| 154 | + public function callback( $path = '', $blog_id = 0 ) { | |
| 155 | + add_filter( 'site_settings_endpoint_update_locale', array( $this, 'update_locale' ) ); | |
| 156 | + add_filter( 'site_settings_endpoint_get', array( $this, 'return_locale' ) ); | |
| 157 | + add_filter( 'site_settings_site_format', array( $this, 'site_format' ) ); | |
| 158 | + return parent::callback( $path, $blog_id ); | |
| 159 | + } | |
| 160 | + | |
| 161 | + /** | |
| 162 | + * Get the locale. | |
| 163 | + * | |
| 164 | + * @param string $key - the key. | |
| 165 | + * | |
| 166 | + * @return string|false | |
| 167 | + */ | |
| 168 | + protected function get_locale( $key ) { | |
| 169 | + if ( 'locale' === $key ) { | |
| 170 | + if ( defined( 'IS_WPCOM' ) && IS_WPCOM ) { | |
| 171 | + return (string) get_blog_lang_code(); | |
| 172 | + } else { | |
| 173 | + return get_locale(); | |
| 174 | + } | |
| 175 | + } | |
| 176 | + | |
| 177 | + return false; | |
| 178 | + } | |
| 179 | + | |
| 180 | + /** | |
| 181 | + * Return the locale. | |
| 182 | + * | |
| 183 | + * @param array $settings - the site settings. | |
| 184 | + * | |
| 185 | + * @return array `$settings` with a locale key added. | |
| 186 | + */ | |
| 187 | + public function return_locale( $settings ) { | |
| 188 | + return $settings + array( 'locale' => $this->get_locale( 'locale' ) ); | |
| 189 | + } | |
| 190 | + | |
| 191 | + /** | |
| 192 | + * Update the locale. | |
| 193 | + * | |
| 194 | + * @param string $value - the locale code. | |
| 195 | + * | |
| 196 | + * @return bool | |
| 197 | + */ | |
| 198 | + public function update_locale( $value ) { | |
| 199 | + if ( defined( 'IS_WPCOM' ) && IS_WPCOM ) { | |
| 200 | + $lang_id = get_lang_id_by_code( $value ); | |
| 201 | + if ( ! empty( $lang_id ) ) { | |
| 202 | + if ( update_option( 'lang_id', $lang_id ) ) { | |
| 203 | + return true; | |
| 204 | + } | |
| 205 | + } | |
| 206 | + } | |
| 207 | + return false; | |
| 208 | + } | |
| 209 | + | |
| 210 | + /** | |
| 211 | + * Format the site. | |
| 212 | + * | |
| 213 | + * @param string $format - the format. | |
| 214 | + * | |
| 215 | + * @return array | |
| 216 | + */ | |
| 217 | + public function site_format( $format ) { // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable | |
| 218 | + return self::$site_format; | |
| 219 | + } | |
| 220 | +} | |