Make WordPress Core

Ticket #40142: 40142.patch

File 40142.patch, 4.5 KB (added by sgarza, 7 years ago)

Patch for DELETE and PUT HTTP calls

  • wp-includes/class-http.php

     
    610610                $r = wp_parse_args( $args, $defaults );
    611611                return $this->request($url, $r);
    612612        }
     613 
     614  /**
     615         * Uses the PUT HTTP method.
     616         *
     617         * Used for sending data that is expected to be in the body.
     618         *
     619         * @access public
     620         * @since 2.7.0
     621         *
     622         * @param string $url The request URL.
     623         * @param string|array $args Optional. Override the defaults.
     624         * @return array|WP_Error Array containing 'headers', 'body', 'response', 'cookies', 'filename'. A WP_Error instance upon error
     625         */
     626        public function put($url, $args = array()) {
     627                $defaults = array('method' => 'PUT');
     628                $r = wp_parse_args( $args, $defaults );
     629                return $this->request($url, $r);
     630        }
     631 
     632  /**
     633         * Uses the DELETE HTTP method.
     634         *
     635         * Used for sending data that is expected to be in the body.
     636         *
     637         * @access public
     638         * @since 2.7.0
     639         *
     640         * @param string $url The request URL.
     641         * @param string|array $args Optional. Override the defaults.
     642         * @return array|WP_Error Array containing 'headers', 'body', 'response', 'cookies', 'filename'. A WP_Error instance upon error
     643         */
     644        public function delete($url, $args = array()) {
     645                $defaults = array('method' => 'DELETE');
     646                $r = wp_parse_args( $args, $defaults );
     647                return $this->request($url, $r);
     648        }
    613649
    614650        /**
    615651         * Parses the responses and splits the parts into headers and body.
  • wp-includes/http.php

     
    113113}
    114114
    115115/**
     116 * Retrieve the raw response from a safe HTTP request using the PUT method.
     117 *
     118 * This function is ideal when the HTTP request is being made to an arbitrary
     119 * URL. The URL is validated to avoid redirection and request forgery attacks.
     120 *
     121 * @since 3.6.0
     122 *
     123 * @see wp_remote_request() For more information on the response array format.
     124 * @see WP_Http::request() For default arguments information.
     125 *
     126 * @param string $url Site URL to retrieve.
     127 * @param array $args Optional. Request arguments. Default empty array.
     128 * @return WP_Error|array The response or WP_Error on failure.
     129 */
     130function wp_safe_remote_put( $url, $args = array() ) {
     131        $args['reject_unsafe_urls'] = true;
     132        $http = _wp_http_get_object();
     133        return $http->put( $url, $args );
     134}
     135
     136/**
     137 * Retrieve the raw response from a safe HTTP request using the PUT method.
     138 *
     139 * This function is ideal when the HTTP request is being made to an arbitrary
     140 * URL. The URL is validated to avoid redirection and request forgery attacks.
     141 *
     142 * @since 3.6.0
     143 *
     144 * @see wp_remote_request() For more information on the response array format.
     145 * @see WP_Http::request() For default arguments information.
     146 *
     147 * @param string $url Site URL to retrieve.
     148 * @param array $args Optional. Request arguments. Default empty array.
     149 * @return WP_Error|array The response or WP_Error on failure.
     150 */
     151function wp_safe_remote_delete( $url, $args = array() ) {
     152        $args['reject_unsafe_urls'] = true;
     153        $http = _wp_http_get_object();
     154        return $http->delete( $url, $args );
     155}
     156
     157/**
    116158 * Retrieve the raw response from the HTTP request.
    117159 *
    118160 * The array structure is a little complex:
     
    205247}
    206248
    207249/**
     250 * Retrieve the raw response from the HTTP request using the PUT method.
     251 *
     252 * @since 2.7.0
     253 *
     254 * @see wp_remote_request() For more information on the response array format.
     255 * @see WP_Http::request() For default arguments information.
     256 *
     257 * @param string $url  Site URL to retrieve.
     258 * @param array  $args Optional. Request arguments. Default empty array.
     259 * @return WP_Error|array The response or WP_Error on failure.
     260 */
     261function wp_remote_put($url, $args = array()) {
     262        $http = _wp_http_get_object();
     263        return $http->put( $url, $args );
     264}
     265
     266/**
     267 * Retrieve the raw response from the HTTP request using the PUT method.
     268 *
     269 * @since 2.7.0
     270 *
     271 * @see wp_remote_request() For more information on the response array format.
     272 * @see WP_Http::request() For default arguments information.
     273 *
     274 * @param string $url  Site URL to retrieve.
     275 * @param array  $args Optional. Request arguments. Default empty array.
     276 * @return WP_Error|array The response or WP_Error on failure.
     277 */
     278function wp_remote_delete($url, $args = array()) {
     279        $http = _wp_http_get_object();
     280        return $http->delete( $url, $args );
     281}
     282
     283/**
    208284 * Retrieve only the headers from the raw response.
    209285 *
    210286 * @since 2.7.0