← All changes
|
json-endpoints/class.wpcom-json-api-site-settings-v1-3-endpoint.php
+6
-53
13.2.4
→
16.3-a.7
View file →
| @@ -1,6 +1,10 @@ | ||
| 1 | 1 | <?php // phpcs:ignore WordPress.Files.FileName.InvalidClassFileName |
| 2 | 2 | |
| 3 | +if ( ! defined( 'ABSPATH' ) ) { | |
| 4 | + exit( 0 ); | |
| 5 | +} | |
| 6 | + | |
| 3 | 7 | new WPCOM_JSON_API_Site_Settings_V1_3_Endpoint( |
| 4 | 8 | array( |
| 5 | 9 | 'description' => 'Get detailed settings information about a site.', |
| 6 | 10 | 'group' => '__do_not_document', |
| @@ -118,8 +122,10 @@ | ||
| 118 | 122 | ); |
| 119 | 123 | |
| 120 | 124 | /** |
| 121 | 125 | * Site settings v1_3 endpoint class. |
| 126 | + * | |
| 127 | + * @phan-constructor-used-for-side-effects | |
| 122 | 128 | */ |
| 123 | 129 | class WPCOM_JSON_API_Site_Settings_V1_3_Endpoint extends WPCOM_JSON_API_Site_Settings_V1_2_Endpoint { |
| 124 | 130 | |
| 125 | 131 | /** |
| @@ -133,59 +139,6 @@ | ||
| 133 | 139 | 'anonymize_ip' => false, |
| 134 | 140 | 'ec_track_purchases' => false, |
| 135 | 141 | 'ec_track_add_to_cart' => false, |
| 136 | 142 | ); |
| 137 | - } | |
| 138 | - | |
| 139 | - /** | |
| 140 | - * API Callback | |
| 141 | - * | |
| 142 | - * @param string $path - the path. | |
| 143 | - * @param int $blog_id - the blog ID. | |
| 144 | - * | |
| 145 | - * @return array|WP_Error | |
| 146 | - */ | |
| 147 | - public function callback( $path = '', $blog_id = 0 ) { | |
| 148 | - add_filter( 'site_settings_endpoint_get', array( $this, 'filter_site_settings_endpoint_get' ) ); | |
| 149 | - add_filter( 'site_settings_update_wga', array( $this, 'filter_update_google_analytics' ), 10, 2 ); | |
| 150 | - return parent::callback( $path, $blog_id ); | |
| 151 | - } | |
| 152 | - | |
| 153 | - /** | |
| 154 | - * Filter the parent's response to include the fields | |
| 155 | - * added to 1.3 (and their defaults) | |
| 156 | - * | |
| 157 | - * @param array $settings - the settings array. | |
| 158 | - * | |
| 159 | - * @return array | |
| 160 | - */ | |
| 161 | - public function filter_site_settings_endpoint_get( $settings ) { | |
| 162 | - $option_name = $this->get_google_analytics_option_name(); | |
| 163 | - $option = get_option( $option_name, array() ); | |
| 164 | - $settings['wga'] = wp_parse_args( $option, $this->get_defaults() ); | |
| 165 | - return $settings; | |
| 166 | - } | |
| 167 | - | |
| 168 | - /** | |
| 169 | - * Filter the parent's response to consume our new fields | |
| 170 | - * | |
| 171 | - * @param array $wga - Array of existing Google Analytics settings. | |
| 172 | - * @param array $new_values - the new values we're adding. | |
| 173 | - * | |
| 174 | - * @return array | |
| 175 | - */ | |
| 176 | - public function filter_update_google_analytics( $wga, $new_values ) { | |
| 177 | - $wga_keys = array_keys( $this->get_defaults() ); | |
| 178 | - foreach ( $wga_keys as $wga_key ) { | |
| 179 | - // Skip code since the parent class has handled it | |
| 180 | - if ( 'code' === $wga_key ) { | |
| 181 | - continue; | |
| 182 | - } | |
| 183 | - // All our new keys are booleans, so let's coerce each key's value | |
| 184 | - // before updating the value in settings | |
| 185 | - if ( array_key_exists( $wga_key, $new_values ) ) { | |
| 186 | - $wga[ $wga_key ] = WPCOM_JSON_API::is_truthy( $new_values[ $wga_key ] ); | |
| 187 | - } | |
| 188 | - } | |
| 189 | - return $wga; | |
| 190 | 143 | } |
| 191 | 144 | } |