- Timestamp:
- 09/26/2023 03:30:34 PM (17 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-autosaves-controller.php
r56586 r56714 235 235 $autosave_id = wp_update_post( wp_slash( (array) $prepared_post ), true ); 236 236 } else { 237 // Non-draft posts: create or update the post autosave. 238 $autosave_id = $this->create_post_autosave( (array) $prepared_post );237 // Non-draft posts: create or update the post autosave. Pass the meta data. 238 $autosave_id = $this->create_post_autosave( (array) $prepared_post, (array) $request->get_param( 'meta' ) ); 239 239 } 240 240 … … 349 349 * 350 350 * @since 5.0.0 351 * @since 6.4.0 The `$meta` parameter was added. 351 352 * 352 353 * @param array $post_data Associative array containing the post data. 354 * @param array $meta Associative array containing the post meta data. 353 355 * @return mixed The autosave revision ID or WP_Error. 354 356 */ 355 public function create_post_autosave( $post_data ) {357 public function create_post_autosave( $post_data, array $meta = array() ) { 356 358 357 359 $post_id = (int) $post_data['ID']; … … 373 375 } 374 376 377 // Check if meta values have changed. 378 if ( ! empty( $meta ) ) { 379 $revisioned_meta_keys = wp_post_revision_meta_keys( $post->post_type ); 380 foreach ( $revisioned_meta_keys as $meta_key ) { 381 // get_metadata_raw is used to avoid retrieving the default value. 382 $old_meta = get_metadata_raw( 'post', $post_id, $meta_key, true ); 383 $new_meta = isset( $meta[ $meta_key ] ) ? $meta[ $meta_key ] : ''; 384 385 if ( $new_meta !== $old_meta ) { 386 $autosave_is_different = true; 387 break; 388 } 389 } 390 } 391 375 392 $user_id = get_current_user_id(); 376 393 … … 391 408 392 409 // wp_update_post() expects escaped array. 393 return wp_update_post( wp_slash( $new_autosave ) ); 394 } 395 396 // Create the new autosave as a special post revision. 397 return _wp_put_post_revision( $post_data, true ); 410 $revision_id = wp_update_post( wp_slash( $new_autosave ) ); 411 } else { 412 // Create the new autosave as a special post revision. 413 $revision_id = _wp_put_post_revision( $post_data, true ); 414 } 415 416 if ( is_wp_error( $revision_id ) || 0 === $revision_id ) { 417 return $revision_id; 418 } 419 420 // Attached any passed meta values that have revisions enabled. 421 if ( ! empty( $meta ) ) { 422 foreach ( $revisioned_meta_keys as $meta_key ) { 423 if ( isset( $meta[ $meta_key ] ) ) { 424 update_metadata( 'post', $revision_id, $meta_key, $meta[ $meta_key ] ); 425 } 426 } 427 } 428 429 return $revision_id; 398 430 } 399 431
Note: See TracChangeset
for help on using the changeset viewer.