Ticket #40702: 40702-request-args.diff
File 40702-request-args.diff, 2.4 KB (added by , 7 years ago) |
---|
-
src/wp-admin/includes/class-wp-community-events.php
94 94 return $cached_events; 95 95 } 96 96 97 $request_url = $this->get_request_url( $location_search, $timezone ); 98 $response = wp_remote_get( $request_url ); 97 $api_url = 'https://api.wordpress.org/events/1.0/'; 98 $request_args = $this->get_request_args( $location_search, $timezone ); 99 $response = wp_remote_get( $api_url, $request_args ); 99 100 $response_code = wp_remote_retrieve_response_code( $response ); 100 101 $response_body = json_decode( wp_remote_retrieve_body( $response ), true ); 101 102 $response_error = null; 102 $debugging_info = compact( ' request_url', 'response_code', 'response_body' );103 $debugging_info = compact( 'api_url', 'request_args', 'response_code', 'response_body' ); 103 104 104 105 if ( is_wp_error( $response ) ) { 105 106 $response_error = $response; … … 143 144 } 144 145 145 146 /** 146 * Builds a URL for requeststo the w.org Events API.147 * Builds an array of args to use in an http request to the w.org Events API. 147 148 * 148 149 * @access protected 149 150 * @since 4.8.0 … … 150 151 * 151 152 * @param string $search Optional. City search string. Default empty string. 152 153 * @param string $timezone Optional. Timezone string. Default empty string. 153 * @return string The request URL.154 * @return array The request args. 154 155 */ 155 protected function get_request_url( $search = '', $timezone = '' ) { 156 $api_url = 'https://api.wordpress.org/events/1.0/'; 157 $args = array( 156 protected function get_request_args( $search = '', $timezone = '' ) { 157 $args = array( 158 158 'number' => 5, // Get more than three in case some get trimmed out. 159 159 'ip' => $this->get_client_ip(), 160 160 ); 161 161 162 162 /* 163 * Sendthe minimal set of necessary arguments, in order to increase the163 * Include the minimal set of necessary arguments, in order to increase the 164 164 * chances of a cache-hit on the API side. 165 165 */ 166 166 if ( empty( $search ) && isset( $this->user_location['latitude'], $this->user_location['longitude'] ) ) { … … 178 178 } 179 179 } 180 180 181 return add_query_arg( $args, $api_url ); 181 // Wrap the args in an array compatible with the second parameter of `wp_remote_get()`. 182 return array( 183 'body' => $args 184 ); 182 185 } 183 186 184 187 /**