wp/wp-admin/includes/class-wp-community-events.php
changeset 9 177826044cd9
parent 7 cf61fcea0001
child 16 a86126ab1dd4
equal deleted inserted replaced
8:c7c34916027a 9:177826044cd9
    93 		}
    93 		}
    94 
    94 
    95 		// include an unmodified $wp_version
    95 		// include an unmodified $wp_version
    96 		include( ABSPATH . WPINC . '/version.php' );
    96 		include( ABSPATH . WPINC . '/version.php' );
    97 
    97 
    98 		$api_url      = 'http://api.wordpress.org/events/1.0/';
    98 		$api_url                    = 'http://api.wordpress.org/events/1.0/';
    99 		$request_args = $this->get_request_args( $location_search, $timezone );
    99 		$request_args               = $this->get_request_args( $location_search, $timezone );
   100 		$request_args['user-agent'] = 'WordPress/' . $wp_version . '; ' . home_url( '/' );
   100 		$request_args['user-agent'] = 'WordPress/' . $wp_version . '; ' . home_url( '/' );
   101 
   101 
   102 		if ( wp_http_supports( array( 'ssl' ) ) ) {
   102 		if ( wp_http_supports( array( 'ssl' ) ) ) {
   103 			$api_url = set_url_scheme( $api_url, 'https' );
   103 			$api_url = set_url_scheme( $api_url, 'https' );
   104 		}
   104 		}
   201 			}
   201 			}
   202 		}
   202 		}
   203 
   203 
   204 		// Wrap the args in an array compatible with the second parameter of `wp_remote_get()`.
   204 		// Wrap the args in an array compatible with the second parameter of `wp_remote_get()`.
   205 		return array(
   205 		return array(
   206 			'body' => $args
   206 			'body' => $args,
   207 		);
   207 		);
   208 	}
   208 	}
   209 
   209 
   210 	/**
   210 	/**
   211 	 * Determines the user's actual IP address and attempts to partially
   211 	 * Determines the user's actual IP address and attempts to partially
   231 	 *
   231 	 *
   232 	 * @return false|string The anonymized address on success; the given address
   232 	 * @return false|string The anonymized address on success; the given address
   233 	 *                      or false on failure.
   233 	 *                      or false on failure.
   234 	 */
   234 	 */
   235 	public static function get_unsafe_client_ip() {
   235 	public static function get_unsafe_client_ip() {
   236 		$client_ip = $netmask = false;
   236 		$client_ip = false;
   237 
   237 
   238 		// In order of preference, with the best ones for this purpose first.
   238 		// In order of preference, with the best ones for this purpose first.
   239 		$address_headers = array(
   239 		$address_headers = array(
   240 			'HTTP_CLIENT_IP',
   240 			'HTTP_CLIENT_IP',
   241 			'HTTP_X_FORWARDED_FOR',
   241 			'HTTP_X_FORWARDED_FOR',
   306 	protected function get_events_transient_key( $location ) {
   306 	protected function get_events_transient_key( $location ) {
   307 		$key = false;
   307 		$key = false;
   308 
   308 
   309 		if ( isset( $location['ip'] ) ) {
   309 		if ( isset( $location['ip'] ) ) {
   310 			$key = 'community-events-' . md5( $location['ip'] );
   310 			$key = 'community-events-' . md5( $location['ip'] );
   311 		} else if ( isset( $location['latitude'], $location['longitude'] ) ) {
   311 		} elseif ( isset( $location['latitude'], $location['longitude'] ) ) {
   312 			$key = 'community-events-' . md5( $location['latitude'] . $location['longitude'] );
   312 			$key = 'community-events-' . md5( $location['latitude'] . $location['longitude'] );
   313 		}
   313 		}
   314 
   314 
   315 		return $key;
   315 		return $key;
   316 	}
   316 	}
   423 			}
   423 			}
   424 
   424 
   425 			$response_body['events'] = array_slice( $response_body['events'], 0, 3 );
   425 			$response_body['events'] = array_slice( $response_body['events'], 0, 3 );
   426 			$trimmed_event_types     = wp_list_pluck( $response_body['events'], 'type' );
   426 			$trimmed_event_types     = wp_list_pluck( $response_body['events'], 'type' );
   427 
   427 
   428 			// Make sure the soonest upcoming WordCamps is pinned in the list.
   428 			// Make sure the soonest upcoming WordCamp is pinned in the list.
   429 			if ( ! in_array( 'wordcamp', $trimmed_event_types ) && $wordcamps ) {
   429 			if ( ! in_array( 'wordcamp', $trimmed_event_types ) && $wordcamps ) {
   430 				array_pop( $response_body['events'] );
   430 				array_pop( $response_body['events'] );
   431 				array_push( $response_body['events'], $wordcamps[0] );
   431 				array_push( $response_body['events'], $wordcamps[0] );
   432 			}
   432 			}
   433 		}
   433 		}
   450 
   450 
   451 		if ( ! WP_DEBUG_LOG ) {
   451 		if ( ! WP_DEBUG_LOG ) {
   452 			return;
   452 			return;
   453 		}
   453 		}
   454 
   454 
   455 		error_log( sprintf(
   455 		error_log(
   456 			'%s: %s. Details: %s',
   456 			sprintf(
   457 			__METHOD__,
   457 				'%s: %s. Details: %s',
   458 			trim( $message, '.' ),
   458 				__METHOD__,
   459 			wp_json_encode( $details )
   459 				trim( $message, '.' ),
   460 		) );
   460 				wp_json_encode( $details )
       
   461 			)
       
   462 		);
   461 	}
   463 	}
   462 }
   464 }