- Timestamp:
- 09/14/2016 03:49:37 PM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/rest-api/class-wp-rest-request.php
r37674 r38601 781 781 * @access public 782 782 * 783 * @return true| null True if there are no parameters to sanitize, null otherwise.783 * @return true|WP_Error True if parameters were sanitized, WP_Error if an error occurred during sanitization. 784 784 */ 785 785 public function sanitize_params() { 786 787 786 $attributes = $this->get_attributes(); 788 787 … … 793 792 794 793 $order = $this->get_parameter_order(); 794 795 $invalid_params = array(); 795 796 796 797 foreach ( $order as $type ) { … … 800 801 foreach ( $this->params[ $type ] as $key => $value ) { 801 802 // Check if this param has a sanitize_callback added. 802 if ( isset( $attributes['args'][ $key ] ) && ! empty( $attributes['args'][ $key ]['sanitize_callback'] ) ) { 803 $this->params[ $type ][ $key ] = call_user_func( $attributes['args'][ $key ]['sanitize_callback'], $value, $this, $key ); 803 if ( ! isset( $attributes['args'][ $key ] ) || empty( $attributes['args'][ $key ]['sanitize_callback'] ) ) { 804 continue; 805 } 806 807 $sanitized_value = call_user_func( $attributes['args'][ $key ]['sanitize_callback'], $value, $this, $key ); 808 809 if ( is_wp_error( $sanitized_value ) ) { 810 $invalid_params[ $key ] = $sanitized_value->get_error_message(); 811 } else { 812 $this->params[ $type ][ $key ] = $sanitized_value; 804 813 } 805 814 } 806 815 } 807 return null; 816 817 if ( $invalid_params ) { 818 return new WP_Error( 'rest_invalid_param', sprintf( __( 'Invalid parameter(s): %s' ), implode( ', ', array_keys( $invalid_params ) ) ), array( 'status' => 400, 'params' => $invalid_params ) ); 819 } 820 821 return true; 808 822 } 809 823 … … 818 832 */ 819 833 public function has_valid_params() { 820 821 834 $attributes = $this->get_attributes(); 822 835 $required = array();
Note: See TracChangeset
for help on using the changeset viewer.