Changeset 56714
- Timestamp:
- 09/26/2023 03:30:34 PM (10 months ago)
- Location:
- trunk
- Files:
-
- 1 added
- 13 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-admin/includes/post.php
r56712 r56714 1971 1971 * 1972 1972 * @since 4.1.0 1973 1973 1974 * 1974 1975 * @param array $new_autosave Post array - the autosave that is about to be saved. 1976 1975 1977 */ 1976 do_action( 'wp_creating_autosave', $new_autosave ); 1977 1978 do_action( 'wp_creating_autosave', $new_autosave, true ); 1978 1979 return wp_update_post( $new_autosave ); 1979 1980 } … … 1983 1984 1984 1985 // Otherwise create the new autosave as a special post revision. 1985 return _wp_put_post_revision( $post_data, true ); 1986 $revision = _wp_put_post_revision( $post_data, true ); 1987 1988 if ( ! is_wp_error( $revision ) && 0 !== $revision ) { 1989 1990 /** This action is documented in wp-admin/includes/post.php */ 1991 do_action( 'wp_creating_autosave', get_post( $revision, ARRAY_A ), false ); 1992 } 1993 1994 return $revision; 1995 } 1996 1997 /** 1998 * Autosave the revisioned meta fields. 1999 * 2000 * Iterates through the revisioned meta fields and checks each to see if they are set, 2001 * and have a changed value. If so, the meta value is saved and attached to the autosave. 2002 * 2003 * @since 6.4.0 2004 * 2005 * @param array $new_autosave The new post data being autosaved. 2006 */ 2007 function wp_autosave_post_revisioned_meta_fields( $new_autosave ) { 2008 /* 2009 * The post data arrives as either $_POST['data']['wp_autosave'] or the $_POST 2010 * itself. This sets $posted_data to the correct variable. 2011 * 2012 * Ignoring sanitization to avoid altering meta. Ignoring the nonce check because 2013 * this is hooked on inner core hooks where a valid nonce was already checked. 2014 * 2015 * @phpcs:disable WordPress.Security 2016 */ 2017 $posted_data = isset( $_POST['data']['wp_autosave'] ) ? $_POST['data']['wp_autosave'] : $_POST; 2018 // phpcs:enable 2019 2020 $post_type = get_post_type( $new_autosave['post_parent'] ); 2021 2022 /* 2023 * Go thru the revisioned meta keys and save them as part of the autosave, if 2024 * the meta key is part of the posted data, the meta value is not blank and 2025 * the the meta value has changes from the last autosaved value. 2026 */ 2027 foreach ( wp_post_revision_meta_keys( $post_type ) as $meta_key ) { 2028 2029 if ( 2030 isset( $posted_data[ $meta_key ] ) && 2031 get_post_meta( $new_autosave['ID'], $meta_key, true ) !== wp_unslash( $posted_data[ $meta_key ] ) 2032 ) { 2033 /* 2034 * Use the underlying delete_metadata() and add_metadata() functions 2035 * vs delete_post_meta() and add_post_meta() to make sure we're working 2036 * with the actual revision meta. 2037 */ 2038 delete_metadata( 'post', $new_autosave['ID'], $meta_key ); 2039 2040 /* 2041 * One last check to ensure meta value not empty(). 2042 */ 2043 if ( ! empty( $posted_data[ $meta_key ] ) ) { 2044 /* 2045 * Add the revisions meta data to the autosave. 2046 */ 2047 add_metadata( 'post', $new_autosave['ID'], $meta_key, $posted_data[ $meta_key ] ); 2048 } 2049 } 2050 } 1986 2051 } 1987 2052 -
trunk/src/wp-includes/default-filters.php
r56693 r56714 412 412 add_action( 'shutdown', 'wp_ob_end_flush_all', 1 ); 413 413 // Create a revision whenever a post is updated. 414 414 415 add_action( 'post_updated', 'wp_save_post_revision', 10, 1 ); 415 416 add_action( 'publish_post', '_publish_post_hook', 5, 1 ); … … 720 721 add_action( 'init', 'wp_create_initial_post_meta' ); 721 722 723 724 725 726 727 728 729 730 731 732 733 734 722 735 // Font management. 723 736 add_action( 'wp_head', 'wp_print_font_faces', 50 ); -
trunk/src/wp-includes/meta.php
r56191 r56714 1368 1368 * @since 5.3.0 Valid meta types expanded to include "array" and "object". 1369 1369 * @since 5.5.0 The `$default` argument was added to the arguments array. 1370 1370 1371 * 1371 1372 * @param string $object_type Type of object metadata is for. Accepts 'post', 'comment', 'term', 'user', … … 1393 1394 * When registering complex meta values this argument may optionally be an 1394 1395 * array with 'schema' or 'prepare_callback' keys instead of a boolean. 1396 1397 1395 1398 * } 1396 1399 * @param string|array $deprecated Deprecated. Use `$args` instead. … … 1415 1418 'auth_callback' => null, 1416 1419 'show_in_rest' => false, 1420 1417 1421 ); 1418 1422 … … 1461 1465 1462 1466 $object_subtype = ! empty( $args['object_subtype'] ) ? $args['object_subtype'] : ''; 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1463 1478 1464 1479 // If `auth_callback` is not provided, fall back to `is_protected_meta()`. -
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. 238 $autosave_id = $this->create_post_autosave( (array) $prepared_post ); 239 239 } 240 240 … … 349 349 * 350 350 * @since 5.0.0 351 351 352 * 352 353 * @param array $post_data Associative array containing the post data. 354 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 ) { 356 358 357 359 $post_id = (int) $post_data['ID']; … … 373 375 } 374 376 377 378 379 380 381 382 383 384 385 386 387 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 -
trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-revisions-controller.php
r56586 r56714 26 26 27 27 /** 28 29 30 31 32 33 34 35 28 36 * Parent controller. 29 37 * … … 61 69 $this->parent_base = ! empty( $post_type_object->rest_base ) ? $post_type_object->rest_base : $post_type_object->name; 62 70 $this->namespace = ! empty( $post_type_object->rest_namespace ) ? $post_type_object->rest_namespace : 'wp/v2'; 71 63 72 } 64 73 … … 620 629 } 621 630 631 632 633 634 622 635 $context = ! empty( $request['context'] ) ? $request['context'] : 'view'; 623 636 $data = $this->add_additional_fields_to_object( $data, $request ); … … 752 765 $schema['properties']['guid'] = $parent_schema['properties']['guid']; 753 766 } 767 768 754 769 755 770 $this->schema = $schema; -
trunk/src/wp-includes/revision.php
r56359 r56714 97 97 98 98 /** 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 99 120 * Creates a revision for the current version of a post. 100 121 * … … 109 130 function wp_save_post_revision( $post_id ) { 110 131 if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) { 132 133 134 135 136 111 137 return; 112 138 } … … 362 388 * 363 389 * @since 2.6.0 390 364 391 * 365 392 * @param int $revision_id Post revision ID. 393 366 394 */ 367 do_action( '_wp_put_post_revision', $revision_id );395 do_action( '_wp_put_post_revision', $revision_id ); 368 396 } 369 397 370 398 return $revision_id; 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 371 421 } 372 422 … … 451 501 update_post_meta( $post_id, '_edit_last', get_current_user_id() ); 452 502 503 504 505 453 506 /** 454 507 * Fires after a post revision has been restored. … … 462 515 463 516 return $post_id; 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 464 616 } 465 617 … … 729 881 add_filter( 'get_the_terms', '_wp_preview_terms_filter', 10, 3 ); 730 882 add_filter( 'get_post_metadata', '_wp_preview_post_thumbnail_filter', 10, 3 ); 883 731 884 732 885 return $post; … … 947 1100 return true; 948 1101 } 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 -
trunk/tests/phpunit/tests/meta/registerMeta.php
r56548 r56714 98 98 'auth_callback' => '__return_true', 99 99 'show_in_rest' => false, 100 100 101 ), 101 102 ), … … 122 123 'auth_callback' => '__return_true', 123 124 'show_in_rest' => false, 125 124 126 ), 125 127 ), … … 176 178 'auth_callback' => '__return_true', 177 179 'show_in_rest' => false, 180 178 181 ), 179 182 ), … … 343 346 'auth_callback' => '__return_true', 344 347 'show_in_rest' => false, 348 345 349 ), 346 350 ), … … 396 400 'auth_callback' => '__return_true', 397 401 'show_in_rest' => false, 402 398 403 ), 399 404 ), … … 1082 1087 ); 1083 1088 } 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1084 1120 } -
trunk/tests/phpunit/tests/rest-api/rest-autosaves-controller.php
r56548 r56714 216 216 'date', 217 217 'date_gmt', 218 219 218 220 'modified', 219 221 'modified_gmt', 220 'guid',221 'id',222 222 'parent', 223 223 'slug', 224 224 225 'title', 225 226 'excerpt', … … 289 290 $data = $response->get_data(); 290 291 $properties = $data['schema']['properties']; 291 $this->assertCount( 1 3, $properties );292 $this->assertCount( 1, $properties ); 292 293 $this->assertArrayHasKey( 'author', $properties ); 293 294 $this->assertArrayHasKey( 'content', $properties ); … … 303 304 $this->assertArrayHasKey( 'title', $properties ); 304 305 $this->assertArrayHasKey( 'preview_link', $properties ); 306 305 307 } 306 308 -
trunk/tests/phpunit/tests/rest-api/rest-global-styles-revisions-controller.php
r56105 r56714 133 133 ); 134 134 135 wp_update_post( $new_styles_post, true , false);135 wp_update_post( $new_styles_post, true ); 136 136 137 137 $new_styles_post = array( … … 163 163 ); 164 164 165 wp_update_post( $new_styles_post, true , false);165 wp_update_post( $new_styles_post, true ); 166 166 167 167 $new_styles_post = array( … … 193 193 ); 194 194 195 wp_update_post( $new_styles_post, true , false);195 wp_update_post( $new_styles_post, true ); 196 196 wp_set_current_user( 0 ); 197 197 } … … 327 327 ); 328 328 329 wp_update_post( $updated_styles_post, true , false);329 wp_update_post( $updated_styles_post, true ); 330 330 331 331 $request = new WP_REST_Request( 'GET', '/wp/v2/global-styles/' . self::$global_styles_id . '/revisions' ); -
trunk/tests/phpunit/tests/rest-api/rest-post-meta-fields.php
r56559 r56714 18 18 array( 19 19 'show_in_rest' => true, 20 'supports' => array( 'custom-fields' ),20 'supports' => array( 'custom-fields' ), 21 21 ) 22 22 ); … … 158 158 array( 159 159 'show_in_rest' => true, 160 'supports' => array( 'custom-fields' ),160 'supports' => array( 'custom-fields' ), 161 161 ) 162 162 ); … … 1377 1377 */ 1378 1378 public function test_update_value_return_success_with_same_value( $meta_key, $meta_value ) { 1379 add_post_meta( self::$post_id, $meta_key, $meta_value );1380 1381 1379 $this->grant_write_permission(); 1382 1380 … … 1393 1391 1394 1392 $this->assertSame( 200, $response->get_status() ); 1393 1394 1395 1396 1397 1398 1395 1399 } 1396 1400 … … 3113 3117 return $query; 3114 3118 } 3119 3120 3121 3122 3123 3124 3125 3126 3127 3128 3129 3130 3131 3132 3133 3134 3135 3136 3137 3138 3139 3140 3141 3142 3143 3144 3145 3146 3147 3148 3149 3150 3151 3152 3153 3154 3155 3156 3157 3158 3159 3160 3161 3162 3163 3164 3165 3166 3167 3168 3169 3170 3171 3172 3173 3174 3175 3176 3177 3178 3179 3180 3181 3182 3183 3184 3185 3186 3187 3188 3189 3190 3191 3192 3193 3194 3195 3196 3197 3198 3199 3200 3201 3202 3203 3204 3205 3206 3207 3208 3209 3210 3211 3212 3213 3214 3215 3216 3217 3218 3219 3220 3221 3222 3223 3224 3225 3226 3227 3228 3229 3230 3231 3232 3233 3234 3235 3236 3237 3238 3239 3240 3241 3242 3243 3244 3245 3246 3247 3248 3249 3250 3251 3252 3253 3254 3255 3256 3257 3258 3259 3260 3261 3262 3263 3264 3265 3266 3267 3268 3269 3270 3271 3272 3273 3274 3275 3276 3277 3278 3279 3280 3281 3282 3283 3284 3285 3286 3287 3288 3289 3290 3291 3292 3293 3294 3295 3296 3297 3298 3299 3300 3301 3302 3303 3304 3305 3306 3307 3308 3309 3310 3311 3312 3313 3314 3315 3316 3317 3318 3319 3320 3321 3322 3323 3324 3325 3326 3327 3328 3329 3330 3331 3332 3333 3334 3335 3336 3337 3338 3339 3340 3341 3342 3343 3344 3345 3346 3347 3348 3349 3350 3351 3352 3353 3354 3355 3356 3357 3358 3359 3360 3361 3362 3363 3364 3365 3366 3367 3368 3369 3370 3371 3372 3373 3374 3375 3376 3377 3378 3379 3380 3381 3382 3383 3384 3385 3386 3387 3388 3389 3390 3391 3392 3393 3394 3395 3396 3397 3398 3399 3400 3401 3402 3403 3404 3405 3406 3407 3408 3409 3410 3411 3412 3413 3414 3415 3416 3417 3418 3419 3420 3421 3422 3423 3424 3425 3426 3427 3428 3429 3430 3431 3432 3433 3434 3435 3436 3437 3438 3439 3440 3441 3442 3443 3444 3445 3446 3447 3448 3449 3450 3451 3452 3453 3454 3455 3456 3457 3458 3459 3460 3461 3462 3463 3464 3465 3466 3467 3468 3469 3470 3471 3472 3473 3115 3474 } -
trunk/tests/phpunit/tests/rest-api/rest-revisions-controller.php
r55457 r56714 180 180 'guid', 181 181 'id', 182 182 183 'parent', 183 184 'slug', … … 336 337 $data = $response->get_data(); 337 338 $properties = $data['schema']['properties']; 338 $this->assertCount( 1 2, $properties );339 $this->assertCount( 1, $properties ); 339 340 $this->assertArrayHasKey( 'author', $properties ); 340 341 $this->assertArrayHasKey( 'content', $properties ); … … 349 350 $this->assertArrayHasKey( 'slug', $properties ); 350 351 $this->assertArrayHasKey( 'title', $properties ); 352 351 353 } 352 354 -
trunk/tests/phpunit/tests/user/wpRegisterPersistedPreferencesMeta.php
r56547 r56714 53 53 ), 54 54 ), 55 55 56 ), 56 57 $wp_meta_keys['user'][''][ $meta_key ], -
trunk/tests/qunit/fixtures/wp-api-generated.js
r56642 r56714 11783 11783 "rendered": "" 11784 11784 }, 11785 11786 11787 11785 11788 "_links": { 11786 11789 "parent": [ … … 11811 11814 "excerpt": { 11812 11815 "rendered": "<p>REST API Client Fixture: Post</p>\n" 11816 11817 11818 11813 11819 }, 11814 11820 "_links": { … … 11842 11848 "excerpt": { 11843 11849 "rendered": "<p>REST API Client Fixture: Post</p>\n" 11850 11851 11852 11844 11853 } 11845 11854 }; … … 11866 11875 "excerpt": { 11867 11876 "rendered": "" 11877 11878 11879 11868 11880 }, 11869 11881 "_links": { … … 11897 11909 "excerpt": { 11898 11910 "rendered": "" 11911 11912 11913 11899 11914 } 11900 11915 }; … … 12043 12058 "rendered": "" 12044 12059 }, 12060 12061 12062 12045 12063 "_links": { 12046 12064 "parent": [ … … 12071 12089 "excerpt": { 12072 12090 "rendered": "<p>REST API Client Fixture: Page</p>\n" 12091 12092 12093 12073 12094 }, 12074 12095 "_links": { … … 12102 12123 "excerpt": { 12103 12124 "rendered": "<p>REST API Client Fixture: Page</p>\n" 12125 12126 12127 12104 12128 } 12105 12129 }; … … 12126 12150 "excerpt": { 12127 12151 "rendered": "" 12152 12153 12154 12128 12155 }, 12129 12156 "_links": { … … 12157 12184 "excerpt": { 12158 12185 "rendered": "" 12186 12187 12188 12159 12189 } 12160 12190 };
Note: See TracChangeset
for help on using the changeset viewer.