- Timestamp:
- 10/24/2020 04:02:34 PM (4 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php
r49301 r49302 1053 1053 */ 1054 1054 protected function prepare_item_for_database( $request ) { 1055 $prepared_post = new stdClass(); 1055 $prepared_post = new stdClass(); 1056 $current_status = ''; 1056 1057 1057 1058 // Post ID. … … 1063 1064 1064 1065 $prepared_post->ID = $existing_post->ID; 1066 $current_status = $existing_post->post_status; 1065 1067 } 1066 1068 … … 1106 1108 1107 1109 // Post status. 1108 if ( ! empty( $schema['properties']['status'] ) && isset( $request['status'] ) ) { 1110 if ( 1111 ! empty( $schema['properties']['status'] ) && 1112 isset( $request['status'] ) && 1113 ( ! $current_status || $current_status !== $request['status'] ) 1114 ) { 1109 1115 $status = $this->handle_status_param( $request['status'], $post_type ); 1110 1116 … … 1254 1260 return apply_filters( "rest_pre_insert_{$this->post_type}", $prepared_post, $request ); 1255 1261 1262 } 1263 1264 /** 1265 * Checks whether the status is valid for the given post. 1266 * 1267 * Allows for sending an update request with the current status, even if that status would not be acceptable. 1268 * 1269 * @since 5.6.0 1270 * 1271 * @param string $status The provided status. 1272 * @param WP_REST_Request $request The request object. 1273 * @param string $param The parameter name. 1274 * @return true|WP_Error True if the status is valid, or WP_Error if not. 1275 */ 1276 public function check_status( $status, $request, $param ) { 1277 if ( $request['id'] ) { 1278 $post = $this->get_post( $request['id'] ); 1279 1280 if ( ! is_wp_error( $post ) && $post->post_status === $status ) { 1281 return true; 1282 } 1283 } 1284 1285 $args = $request->get_attributes()['args'][ $param ]; 1286 1287 return rest_validate_value_from_schema( $status, $args, $param ); 1256 1288 } 1257 1289 … … 2116 2148 'enum' => array_keys( get_post_stati( array( 'internal' => false ) ) ), 2117 2149 'context' => array( 'view', 'edit' ), 2150 'arg_options' => array( 2151 'validate_callback' => array( $this, 'check_status' ), 2152 ), 2118 2153 ), 2119 2154 'type' => array(
Note: See TracChangeset
for help on using the changeset viewer.