Changeset 11815
- Timestamp:
- 05/04/2022 11:01:43 PM (2 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sites/trunk/wordpress.org/public_html/wp-content/mu-plugins/pub/profile-helpers.php
r11791 r11815 1 1 <?php 2 2 3 namespace WordPressdotorg\Profiles; 4 use WP_Error; 3 5 4 6 /** … … 57 59 * 58 60 * `$request_args` should match what the handler expects for a particular request. 59 * See `wporg-profiles-activity-handler.php` and `wporg-profiles-association-handler.php`. 61 * See `wporg-profiles-activity-handler.php` and `wporg-profiles-association-handler.php` 62 * 63 * @return array|WP_Error 60 64 */ 61 65 function api( array $args ) { … … 63 67 $headers = []; 64 68 $sslverify = true; 69 $error = ''; 65 70 66 71 // Requests to w.org sandbox should also use profiles.w.org sandbox, for testing end to end. 67 72 if ( 'staging' === wp_get_environment_type() ) { 68 $url = str_replace( 'profiles.wordpress.org', '127.0.0.1', $url ); 69 $sslverify = false; // wp_remote_get() cannot verify SSL if the hostname is 127.0.0.1. 73 $url = str_replace( 'profiles.wordpress.org', '127.0.0.1', $url ); 74 $sslverify = false; // wp_remote_get() cannot verify SSL if the hostname is 127.0.0.1. 75 $headers['host'] = 'profiles.wordpress.org'; 70 76 } 71 77 72 // Note: Authentication is handled elsewhere transparently.73 returnwp_remote_post(78 // Note: Authentication is handled transparently by `enable_wporg_profiles_ajax_handler()` on Profiles. 79 $response = wp_remote_post( 74 80 $url, 75 81 [ 76 82 'body' => $args, 77 'headers' => [ 78 'host' => 'profiles.wordpress.org', 79 ], 83 'timeout' => 10, 84 'headers' => $headers, 80 85 'sslverify' => $sslverify, 81 86 ] 82 87 ); 88 89 if ( is_wp_error( $response ) ) { 90 $error = $response->get_error_message(); 91 92 } elseif ( 200 != wp_remote_retrieve_response_code( $response ) || 1 !== (int) wp_remote_retrieve_body( $response ) ) { 93 $error = sprintf( 94 'Error %s %s', 95 $response['response']['code'], 96 $response['body'] 97 ); 98 } 99 100 if ( $error ) { 101 trigger_error( wp_kses_post( $error ), E_USER_WARNING ); 102 } 103 104 return $response; 83 105 }
Note: See TracChangeset
for help on using the changeset viewer.