class.wpcom-json-api-site-settings-v1-2-endpoint.php 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. <?php
  2. new WPCOM_JSON_API_Site_Settings_V1_2_Endpoint( array(
  3. 'description' => 'Get detailed settings information about a site.',
  4. 'group' => '__do_not_document',
  5. 'stat' => 'sites:X',
  6. 'min_version' => '1.2',
  7. 'method' => 'GET',
  8. 'path' => '/sites/%s/settings',
  9. 'path_labels' => array(
  10. '$site' => '(int|string) Site ID or domain',
  11. ),
  12. 'query_parameters' => array(
  13. 'context' => false,
  14. ),
  15. 'response_format' => WPCOM_JSON_API_Site_Settings_Endpoint::$site_format,
  16. 'example_request' => 'https://public-api.wordpress.com/rest/v1.2/sites/en.blog.wordpress.com/settings?pretty=1',
  17. ) );
  18. new WPCOM_JSON_API_Site_Settings_V1_2_Endpoint( array(
  19. 'description' => 'Update settings for a site.',
  20. 'group' => '__do_not_document',
  21. 'stat' => 'sites:X',
  22. 'min_version' => '1.2',
  23. 'method' => 'POST',
  24. 'path' => '/sites/%s/settings',
  25. 'path_labels' => array(
  26. '$site' => '(int|string) Site ID or domain',
  27. ),
  28. 'request_format' => array(
  29. 'blogname' => '(string) Blog name',
  30. 'blogdescription' => '(string) Blog description',
  31. 'default_pingback_flag' => '(bool) Notify blogs linked from article?',
  32. 'default_ping_status' => '(bool) Allow link notifications from other blogs?',
  33. 'default_comment_status' => '(bool) Allow comments on new articles?',
  34. 'blog_public' => '(string) Site visibility; -1: private, 0: discourage search engines, 1: allow search engines',
  35. 'jetpack_sync_non_public_post_stati' => '(bool) allow sync of post and pages with non-public posts stati',
  36. 'jetpack_relatedposts_enabled' => '(bool) Enable related posts?',
  37. 'jetpack_relatedposts_show_headline' => '(bool) Show headline in related posts?',
  38. 'jetpack_relatedposts_show_thumbnails' => '(bool) Show thumbnails in related posts?',
  39. 'jetpack_protect_whitelist' => '(array) List of IP addresses to whitelist',
  40. 'infinite_scroll' => '(bool) Support infinite scroll of posts?',
  41. 'default_category' => '(int) Default post category',
  42. 'default_post_format' => '(string) Default post format',
  43. 'require_name_email' => '(bool) Require comment authors to fill out name and email?',
  44. 'comment_registration' => '(bool) Require users to be registered and logged in to comment?',
  45. 'close_comments_for_old_posts' => '(bool) Automatically close comments on old posts?',
  46. 'close_comments_days_old' => '(int) Age at which to close comments',
  47. 'thread_comments' => '(bool) Enable threaded comments?',
  48. 'thread_comments_depth' => '(int) Depth to thread comments',
  49. 'page_comments' => '(bool) Break comments into pages?',
  50. 'comments_per_page' => '(int) Number of comments to display per page',
  51. 'default_comments_page' => '(string) newest|oldest Which page of comments to display first',
  52. 'comment_order' => '(string) asc|desc Order to display comments within page',
  53. 'comments_notify' => '(bool) Email me when someone comments?',
  54. 'moderation_notify' => '(bool) Email me when a comment is helf for moderation?',
  55. 'social_notifications_like' => '(bool) Email me when someone likes my post?',
  56. 'social_notifications_reblog' => '(bool) Email me when someone reblogs my post?',
  57. 'social_notifications_subscribe' => '(bool) Email me when someone follows my blog?',
  58. 'comment_moderation' => '(bool) Moderate comments for manual approval?',
  59. 'comment_whitelist' => '(bool) Moderate comments unless author has a previously-approved comment?',
  60. 'comment_max_links' => '(int) Moderate comments that contain X or more links',
  61. 'moderation_keys' => '(string) Words or phrases that trigger comment moderation, one per line',
  62. 'blacklist_keys' => '(string) Words or phrases that mark comment spam, one per line',
  63. 'lang_id' => '(int) ID for language blog is written in',
  64. 'locale' => '(string) locale code for language blog is written in',
  65. 'wga' => '(array) Google Analytics Settings',
  66. 'disabled_likes' => '(bool) Are likes globally disabled (they can still be turned on per post)?',
  67. 'disabled_reblogs' => '(bool) Are reblogs disabled on posts?',
  68. 'jetpack_comment_likes_enabled' => '(bool) Are comment likes enabled for all comments?',
  69. 'sharing_button_style' => '(string) Style to use for sharing buttons (icon-text, icon, text, or official)',
  70. 'sharing_label' => '(string) Label to use for sharing buttons, e.g. "Share this:"',
  71. 'sharing_show' => '(string|array:string) Post type or array of types where sharing buttons are to be displayed',
  72. 'sharing_open_links' => '(string) Link target for sharing buttons (same or new)',
  73. 'twitter_via' => '(string) Twitter username to include in tweets when people share using the Twitter button',
  74. 'jetpack-twitter-cards-site-tag' => '(string) The Twitter username of the owner of the site\'s domain.',
  75. 'eventbrite_api_token' => '(int) The Keyring token ID for an Eventbrite token to associate with the site',
  76. 'timezone_string' => '(string) PHP-compatible timezone string like \'UTC-5\'',
  77. 'gmt_offset' => '(int) Site offset from UTC in hours',
  78. 'date_format' => '(string) PHP Date-compatible date format',
  79. 'time_format' => '(string) PHP Date-compatible time format',
  80. 'start_of_week' => '(int) Starting day of week (0 = Sunday, 6 = Saturday)',
  81. 'jetpack_testimonial' => '(bool) Whether testimonial custom post type is enabled for the site',
  82. 'jetpack_testimonial_posts_per_page' => '(int) Number of testimonials to show per page',
  83. 'jetpack_portfolio' => '(bool) Whether portfolio custom post type is enabled for the site',
  84. 'jetpack_portfolio_posts_per_page' => '(int) Number of portfolio projects to show per page',
  85. Jetpack_SEO_Utils::FRONT_PAGE_META_OPTION => '(string) The SEO meta description for the site.',
  86. Jetpack_SEO_Titles::TITLE_FORMATS_OPTION => '(array) SEO meta title formats. Allowed keys: front_page, posts, pages, groups, archives',
  87. 'verification_services_codes' => '(array) Website verification codes. Allowed keys: google, pinterest, bing, yandex',
  88. 'amp_is_enabled' => '(bool) Whether AMP is enabled for this site',
  89. 'podcasting_archive' => '(string) The post category, if any, used for publishing podcasts',
  90. 'site_icon' => '(int) Media attachment ID to use as site icon. Set to zero or an otherwise empty value to clear',
  91. 'api_cache' => '(bool) Turn on/off the Jetpack JSON API cache',
  92. 'posts_per_page' => '(int) Number of posts to show on blog pages',
  93. 'net_neutrality' => '(bool) Whether the net neutrality modal is enabled for this site',
  94. 'posts_per_rss' => '(int) Number of posts to show in the RSS feed',
  95. 'rss_use_excerpt' => '(bool) Whether the RSS feed will use post excerpts',
  96. ),
  97. 'response_format' => array(
  98. 'updated' => '(array)'
  99. ),
  100. 'example_request' => 'https://public-api.wordpress.com/rest/v1/sites/en.blog.wordpress.com/settings?pretty=1',
  101. ) );
  102. class WPCOM_JSON_API_Site_Settings_V1_2_Endpoint extends WPCOM_JSON_API_Site_Settings_Endpoint {
  103. public static $site_format = array(
  104. 'ID' => '(int) Site ID',
  105. 'name' => '(string) Title of site',
  106. 'description' => '(string) Tagline or description of site',
  107. 'URL' => '(string) Full URL to the site',
  108. 'locale' => '(string) Locale code of the site',
  109. 'locale_variant' => '(string) Locale variant code for the site, if set',
  110. 'settings' => '(array) An array of options/settings for the blog. Only viewable by users with post editing rights to the site.',
  111. );
  112. function callback( $path = '', $blog_id = 0 ) {
  113. add_filter( 'site_settings_endpoint_update_locale', array( $this, 'update_locale' ) );
  114. add_filter( 'site_settings_endpoint_get', array( $this, 'return_locale' ) );
  115. add_filter( 'site_settings_site_format', array( $this, 'site_format' ) );
  116. return parent::callback( $path, $blog_id );
  117. }
  118. protected function get_locale( $key ) {
  119. if ( 'locale' == $key ) {
  120. if ( defined( 'IS_WPCOM' ) && IS_WPCOM ) {
  121. return (string) get_blog_lang_code();
  122. } else {
  123. return get_locale();
  124. }
  125. }
  126. return false;
  127. }
  128. public function return_locale( $settings ) {
  129. return $settings + array( 'locale' => $this->get_locale( 'locale' ) );
  130. }
  131. public function update_locale( $value ) {
  132. if ( defined( 'IS_WPCOM' ) && IS_WPCOM ) {
  133. $lang_id = get_lang_id_by_code( $value );
  134. if ( ! empty( $lang_id ) ) {
  135. if ( update_option( 'lang_id', $lang_id ) ) {
  136. return true;
  137. }
  138. }
  139. }
  140. return false;
  141. }
  142. public function site_format( $format ) {
  143. return self::$site_format;
  144. }
  145. }