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