Changeset 55365 for trunk/src/wp-admin/includes/post.php
- Timestamp:
- 02/19/2023 03:03:50 PM (3 years ago)
- File:
-
- 1 edited
-
trunk/src/wp-admin/includes/post.php (modified) (27 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-admin/includes/post.php
r55265 r55365 253 253 unset( $post_data['filter'] ); 254 254 255 $post_ ID= (int) $post_data['post_ID'];256 $post = get_post( $post_ ID);255 $post_id = (int) $post_data['post_ID']; 256 $post = get_post( $post_id ); 257 257 258 258 $post_data['post_type'] = $post->post_type; … … 268 268 269 269 $ptype = get_post_type_object( $post_data['post_type'] ); 270 if ( ! current_user_can( 'edit_post', $post_ ID) ) {270 if ( ! current_user_can( 'edit_post', $post_id ) ) { 271 271 if ( 'page' === $post_data['post_type'] ) { 272 272 wp_die( __( 'Sorry, you are not allowed to edit this page.' ) ); … … 278 278 if ( post_type_supports( $ptype->name, 'revisions' ) ) { 279 279 $revisions = wp_get_post_revisions( 280 $post_ ID,280 $post_id, 281 281 array( 282 282 'order' => 'ASC', … … 288 288 // Check if the revisions have been upgraded. 289 289 if ( $revisions && _wp_get_post_revision_version( $revision ) < 1 ) { 290 _wp_upgrade_revisions_of_post( $post, wp_get_post_revisions( $post_ ID) );290 _wp_upgrade_revisions_of_post( $post, wp_get_post_revisions( $post_id ) ); 291 291 } 292 292 } … … 316 316 // Post formats. 317 317 if ( isset( $post_data['post_format'] ) ) { 318 set_post_format( $post_ ID, $post_data['post_format'] );318 set_post_format( $post_id, $post_data['post_format'] ); 319 319 } 320 320 … … 323 323 $keyed = '_format_' . $format_meta_url; 324 324 if ( isset( $post_data[ $keyed ] ) ) { 325 update_post_meta( $post_ ID, $keyed, wp_slash( sanitize_url( wp_unslash( $post_data[ $keyed ] ) ) ) );325 update_post_meta( $post_id, $keyed, wp_slash( sanitize_url( wp_unslash( $post_data[ $keyed ] ) ) ) ); 326 326 } 327 327 } … … 333 333 if ( isset( $post_data[ $keyed ] ) ) { 334 334 if ( current_user_can( 'unfiltered_html' ) ) { 335 update_post_meta( $post_ ID, $keyed, $post_data[ $keyed ] );335 update_post_meta( $post_id, $keyed, $post_data[ $keyed ] ); 336 336 } else { 337 update_post_meta( $post_ ID, $keyed, wp_filter_post_kses( $post_data[ $keyed ] ) );337 update_post_meta( $post_id, $keyed, wp_filter_post_kses( $post_data[ $keyed ] ) ); 338 338 } 339 339 } … … 341 341 342 342 if ( 'attachment' === $post_data['post_type'] && preg_match( '#^(audio|video)/#', $post_data['post_mime_type'] ) ) { 343 $id3data = wp_get_attachment_metadata( $post_ ID);343 $id3data = wp_get_attachment_metadata( $post_id ); 344 344 if ( ! is_array( $id3data ) ) { 345 345 $id3data = array(); … … 351 351 } 352 352 } 353 wp_update_attachment_metadata( $post_ ID, $id3data );353 wp_update_attachment_metadata( $post_id, $id3data ); 354 354 } 355 355 … … 361 361 continue; 362 362 } 363 if ( $meta->post_id != $post_ID ) { 363 364 if ( $meta->post_id != $post_id ) { 364 365 continue; 365 366 } 366 if ( is_protected_meta( $meta->meta_key, 'post' ) || ! current_user_can( 'edit_post_meta', $post_ID, $meta->meta_key ) ) { 367 368 if ( is_protected_meta( $meta->meta_key, 'post' ) 369 || ! current_user_can( 'edit_post_meta', $post_id, $meta->meta_key ) 370 ) { 367 371 continue; 368 372 } 369 if ( is_protected_meta( $value['key'], 'post' ) || ! current_user_can( 'edit_post_meta', $post_ID, $value['key'] ) ) { 373 374 if ( is_protected_meta( $value['key'], 'post' ) 375 || ! current_user_can( 'edit_post_meta', $post_id, $value['key'] ) 376 ) { 370 377 continue; 371 378 } 379 372 380 update_meta( $key, $value['key'], $value['value'] ); 373 381 } … … 380 388 continue; 381 389 } 382 if ( $meta->post_id != $post_ID ) { 390 391 if ( $meta->post_id != $post_id ) { 383 392 continue; 384 393 } 385 if ( is_protected_meta( $meta->meta_key, 'post' ) || ! current_user_can( 'delete_post_meta', $post_ID, $meta->meta_key ) ) { 394 395 if ( is_protected_meta( $meta->meta_key, 'post' ) 396 || ! current_user_can( 'delete_post_meta', $post_id, $meta->meta_key ) 397 ) { 386 398 continue; 387 399 } 400 388 401 delete_meta( $key ); 389 402 } … … 395 408 $image_alt = wp_unslash( $post_data['_wp_attachment_image_alt'] ); 396 409 397 if ( get_post_meta( $post_ ID, '_wp_attachment_image_alt', true ) !== $image_alt ) {410 if ( get_post_meta( $post_id, '_wp_attachment_image_alt', true ) !== $image_alt ) { 398 411 $image_alt = wp_strip_all_tags( $image_alt, true ); 399 412 400 413 // update_post_meta() expects slashed. 401 update_post_meta( $post_ ID, '_wp_attachment_image_alt', wp_slash( $image_alt ) );402 } 403 } 404 405 $attachment_data = isset( $post_data['attachments'][ $post_ ID ] ) ? $post_data['attachments'][ $post_ID] : array();414 update_post_meta( $post_id, '_wp_attachment_image_alt', wp_slash( $image_alt ) ); 415 } 416 } 417 418 $attachment_data = isset( $post_data['attachments'][ $post_id ] ) ? $post_data['attachments'][ $post_id ] : array(); 406 419 407 420 /** This filter is documented in wp-admin/includes/media.php */ … … 420 433 } 421 434 422 add_meta( $post_ ID);423 424 update_post_meta( $post_ ID, '_edit_last', get_current_user_id() );435 add_meta( $post_id ); 436 437 update_post_meta( $post_id, '_edit_last', get_current_user_id() ); 425 438 426 439 $success = wp_update_post( $translated ); … … 440 453 441 454 // Now that we have an ID we can fix any attachment anchor hrefs. 442 _fix_attachment_links( $post_ ID);443 444 wp_set_post_lock( $post_ ID);455 _fix_attachment_links( $post_id ); 456 457 wp_set_post_lock( $post_id ); 445 458 446 459 if ( current_user_can( $ptype->cap->edit_others_posts ) && current_user_can( $ptype->cap->publish_posts ) ) { 447 460 if ( ! empty( $post_data['sticky'] ) ) { 448 stick_post( $post_ ID);461 stick_post( $post_id ); 449 462 } else { 450 unstick_post( $post_ ID);451 } 452 } 453 454 return $post_ ID;463 unstick_post( $post_id ); 464 } 465 } 466 467 return $post_id; 455 468 } 456 469 … … 506 519 } 507 520 508 $post_ IDs = array_map( 'intval', (array) $post_data['post'] );521 $post_ids = array_map( 'intval', (array) $post_data['post'] ); 509 522 510 523 $reset = array( … … 543 556 continue; 544 557 } 558 545 559 if ( is_taxonomy_hierarchical( $tax_name ) ) { 546 560 $tax_input[ $tax_name ] = array_map( 'absint', $terms ); … … 577 591 $shared_post_data = $post_data; 578 592 579 foreach ( $post_ IDs as $post_ID) {593 foreach ( $post_ids as $post_id ) { 580 594 // Start with fresh post data with each iteration. 581 595 $post_data = $shared_post_data; 582 596 583 $post_type_object = get_post_type_object( get_post_type( $post_ ID) );597 $post_type_object = get_post_type_object( get_post_type( $post_id ) ); 584 598 585 599 if ( ! isset( $post_type_object ) 586 || ( isset( $children ) && in_array( $post_ ID, $children, true ) )587 || ! current_user_can( 'edit_post', $post_ ID)600 || ( isset( $children ) && in_array( $post_id, $children, true ) ) 601 || ! current_user_can( 'edit_post', $post_id ) 588 602 ) { 589 $skipped[] = $post_ ID;603 $skipped[] = $post_id; 590 604 continue; 591 605 } 592 606 593 if ( wp_check_post_lock( $post_ ID) ) {594 $locked[] = $post_ ID;607 if ( wp_check_post_lock( $post_id ) ) { 608 $locked[] = $post_id; 595 609 continue; 596 610 } 597 611 598 $post = get_post( $post_ ID);612 $post = get_post( $post_id ); 599 613 $tax_names = get_object_taxonomies( $post ); 600 614 … … 613 627 614 628 if ( $taxonomy_obj->hierarchical ) { 615 $current_terms = (array) wp_get_object_terms( $post_ ID, $tax_name, array( 'fields' => 'ids' ) );629 $current_terms = (array) wp_get_object_terms( $post_id, $tax_name, array( 'fields' => 'ids' ) ); 616 630 } else { 617 $current_terms = (array) wp_get_object_terms( $post_ ID, $tax_name, array( 'fields' => 'names' ) );631 $current_terms = (array) wp_get_object_terms( $post_id, $tax_name, array( 'fields' => 'names' ) ); 618 632 } 619 633 … … 622 636 623 637 if ( isset( $new_cats ) && in_array( 'category', $tax_names, true ) ) { 624 $cats = (array) wp_get_post_categories( $post_ ID);638 $cats = (array) wp_get_post_categories( $post_id ); 625 639 $post_data['post_category'] = array_unique( array_merge( $cats, $new_cats ) ); 626 640 unset( $post_data['tax_input']['category'] ); 627 641 } 628 642 629 $post_data['post_ID'] = $post_ ID;643 $post_data['post_ID'] = $post_id; 630 644 $post_data['post_type'] = $post->post_type; 631 645 $post_data['post_mime_type'] = $post->post_mime_type; … … 639 653 $post_data = _wp_translate_postdata( true, $post_data ); 640 654 if ( is_wp_error( $post_data ) ) { 641 $skipped[] = $post_ ID;655 $skipped[] = $post_id; 642 656 continue; 643 657 } … … 645 659 646 660 if ( isset( $shared_post_data['post_format'] ) ) { 647 set_post_format( $post_ ID, $shared_post_data['post_format'] );661 set_post_format( $post_id, $shared_post_data['post_format'] ); 648 662 } 649 663 … … 657 671 if ( isset( $post_data['sticky'] ) && current_user_can( $ptype->cap->edit_others_posts ) ) { 658 672 if ( 'sticky' === $post_data['sticky'] ) { 659 stick_post( $post_ ID);673 stick_post( $post_id ); 660 674 } else { 661 unstick_post( $post_ ID);675 unstick_post( $post_id ); 662 676 } 663 677 } … … 888 902 889 903 // Create the post. 890 $post_ ID= wp_insert_post( $translated );891 if ( is_wp_error( $post_ ID) ) {892 return $post_ ID;893 } 894 895 if ( empty( $post_ ID) ) {904 $post_id = wp_insert_post( $translated ); 905 if ( is_wp_error( $post_id ) ) { 906 return $post_id; 907 } 908 909 if ( empty( $post_id ) ) { 896 910 return 0; 897 911 } 898 912 899 add_meta( $post_ ID);900 901 add_post_meta( $post_ ID, '_edit_last', $GLOBALS['current_user']->ID );913 add_meta( $post_id ); 914 915 add_post_meta( $post_id, '_edit_last', $GLOBALS['current_user']->ID ); 902 916 903 917 // Now that we have an ID we can fix any attachment anchor hrefs. 904 _fix_attachment_links( $post_ ID);905 906 wp_set_post_lock( $post_ ID);907 908 return $post_ ID;918 _fix_attachment_links( $post_id ); 919 920 wp_set_post_lock( $post_id ); 921 922 return $post_id; 909 923 } 910 924 … … 934 948 * @since 1.2.0 935 949 * 936 * @param int $post_ ID950 * @param int $post_id 937 951 * @return int|bool 938 952 */ 939 function add_meta( $post_ ID) {940 $post_ ID = (int) $post_ID;953 function add_meta( $post_id ) { 954 $post_id = (int) $post_id; 941 955 942 956 $metakeyselect = isset( $_POST['metakeyselect'] ) ? wp_unslash( trim( $_POST['metakeyselect'] ) ) : ''; … … 960 974 } 961 975 962 if ( is_protected_meta( $metakey, 'post' ) || ! current_user_can( 'add_post_meta', $post_ ID, $metakey ) ) {976 if ( is_protected_meta( $metakey, 'post' ) || ! current_user_can( 'add_post_meta', $post_id, $metakey ) ) { 963 977 return false; 964 978 } … … 966 980 $metakey = wp_slash( $metakey ); 967 981 968 return add_post_meta( $post_ ID, $metakey, $metavalue );982 return add_post_meta( $post_id, $metakey, $metavalue ); 969 983 } 970 984 … … 1942 1956 function post_preview() { 1943 1957 1944 $post_ ID= (int) $_POST['post_ID'];1945 $_POST['ID'] = $post_ ID;1946 1947 $post = get_post( $post_ ID);1958 $post_id = (int) $_POST['post_ID']; 1959 $_POST['ID'] = $post_id; 1960 1961 $post = get_post( $post_id ); 1948 1962 1949 1963 if ( ! $post ) {
Note: See TracChangeset
for help on using the changeset viewer.