- Timestamp:
- 10/27/2016 04:07:06 PM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-settings-controller.php
r38954 r38982 96 96 */ 97 97 protected function prepare_value( $value, $schema ) { 98 // If the value is not a scalar, it's not possible to cast it to 99 // anything. 100 if ( ! is_scalar( $value ) ) { 101 return null; 102 } 103 98 104 switch ( $schema['type'] ) { 99 105 case 'string': … … 142 148 } 143 149 144 // A null value means reset the option, which is essentially deleting it 145 // from the database and then relying on the default value. 150 /** 151 * A `null` value for an option would have the same effect as 152 * deleting the option from the database, and relying on the 153 * default value. 154 */ 146 155 if ( is_null( $request[ $name ] ) ) { 156 /** 157 * A `null` value is returned in the response for any option 158 * that has a non-scalar value. 159 * 160 * To protect clients from accidentally including the `null` 161 * values from a response object in a request, we do not allow 162 * options with non-scalar values to be updated to `null`. 163 * Without this added protection a client could mistakenly 164 * delete all options that have non-scalar values from the 165 * database. 166 */ 167 if ( ! is_scalar( get_option( $args['option_name'], false ) ) ) { 168 return new WP_Error( 169 'rest_invalid_stored_value', sprintf( __( 'The %s property has an invalid stored value, and cannot be updated to null.' ), $name ), array( 'status' => 500 ) 170 ); 171 } 172 147 173 delete_option( $args['option_name'] ); 148 174 } else {
Note: See TracChangeset
for help on using the changeset viewer.