wp/wp-includes/rest-api/class-wp-rest-request.php
changeset 22 8c2e4d02f4ef
parent 21 48c4eec2b7e6
equal deleted inserted replaced
21:48c4eec2b7e6 22:8c2e4d02f4ef
   160 	public function get_headers() {
   160 	public function get_headers() {
   161 		return $this->headers;
   161 		return $this->headers;
   162 	}
   162 	}
   163 
   163 
   164 	/**
   164 	/**
       
   165 	 * Determines if the request is the given method.
       
   166 	 *
       
   167 	 * @since 6.8.0
       
   168 	 *
       
   169 	 * @param string $method HTTP method.
       
   170 	 * @return bool Whether the request is of the given method.
       
   171 	 */
       
   172 	public function is_method( $method ) {
       
   173 		return $this->get_method() === strtoupper( $method );
       
   174 	}
       
   175 
       
   176 	/**
   165 	 * Canonicalizes the header name.
   177 	 * Canonicalizes the header name.
   166 	 *
   178 	 *
   167 	 * Ensures that header names are always treated the same regardless of
   179 	 * Ensures that header names are always treated the same regardless of
   168 	 * source. Header names are always case insensitive.
   180 	 * source. Header names are always case-insensitive.
   169 	 *
   181 	 *
   170 	 * Note that we treat `-` (dashes) and `_` (underscores) as the same
   182 	 * Note that we treat `-` (dashes) and `_` (underscores) as the same
   171 	 * character, as per header parsing rules in both Apache and nginx.
   183 	 * character, as per header parsing rules in both Apache and nginx.
   172 	 *
   184 	 *
   173 	 * @link https://stackoverflow.com/q/18185366
   185 	 * @link https://stackoverflow.com/q/18185366
   480 			foreach ( (array) $this->params[ $type ] as $key => $value ) {
   492 			foreach ( (array) $this->params[ $type ] as $key => $value ) {
   481 				$params[ $key ] = $value;
   493 				$params[ $key ] = $value;
   482 			}
   494 			}
   483 		}
   495 		}
   484 
   496 
       
   497 		// Exclude rest_route if pretty permalinks are not enabled.
       
   498 		if ( ! get_option( 'permalink_structure' ) ) {
       
   499 			unset( $params['rest_route'] );
       
   500 		}
       
   501 
   485 		return $params;
   502 		return $params;
   486 	}
   503 	}
   487 
   504 
   488 	/**
   505 	/**
   489 	 * Retrieves parameters from the route itself.
   506 	 * Retrieves parameters from the route itself.
   707 
   724 
   708 	/**
   725 	/**
   709 	 * Parses the request body parameters.
   726 	 * Parses the request body parameters.
   710 	 *
   727 	 *
   711 	 * Parses out URL-encoded bodies for request methods that aren't supported
   728 	 * Parses out URL-encoded bodies for request methods that aren't supported
   712 	 * natively by PHP. In PHP 5.x, only POST has these parsed automatically.
   729 	 * natively by PHP.
   713 	 *
   730 	 *
   714 	 * @since 4.4.0
   731 	 * @since 4.4.0
   715 	 */
   732 	 */
   716 	protected function parse_body_params() {
   733 	protected function parse_body_params() {
   717 		if ( $this->parsed_body ) {
   734 		if ( $this->parsed_body ) {