Ticket #44416: 44416-wp_insert_post-rework.diff
File 44416-wp_insert_post-rework.diff, 31.4 KB (added by , 7 years ago) |
---|
-
src/wp-includes/class-wp-comment-query.php
635 635 $number = absint( $this->query_vars['number'] ); 636 636 $offset = absint( $this->query_vars['offset'] ); 637 637 $paged = absint( $this->query_vars['paged'] ); 638 $limits = ''; 638 639 639 640 if ( ! empty( $number ) ) { 640 641 if ( $offset ) { … … 819 820 $this->sql_clauses['where']['post_author__not_in'] = 'post_author NOT IN ( ' . implode( ',', wp_parse_id_list( $this->query_vars['post_author__not_in'] ) ) . ' )'; 820 821 } 821 822 822 $join = ''; 823 $join = ''; 824 $groupby = ''; 823 825 824 826 if ( $join_posts_table ) { 825 827 $join .= "JOIN $wpdb->posts ON $wpdb->posts.ID = $wpdb->comments.comment_post_ID"; -
src/wp-includes/class-wp-xmlrpc-server.php
3700 3700 /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ 3701 3701 do_action( 'xmlrpc_call', 'wp.editComment' ); 3702 3702 3703 $comment = array( 3704 'comment_ID' => $comment_ID, 3705 ); 3706 3703 3707 if ( isset( $content_struct['status'] ) ) { 3704 3708 $statuses = get_comment_statuses(); 3705 3709 $statuses = array_keys( $statuses ); … … 3707 3711 if ( ! in_array( $content_struct['status'], $statuses ) ) { 3708 3712 return new IXR_Error( 401, __( 'Invalid comment status.' ) ); 3709 3713 } 3710 $comment _approved= $content_struct['status'];3714 $comment['comment_approved'] = $content_struct['status']; 3711 3715 } 3712 3716 3713 3717 // Do some timestamp voodoo 3714 3718 if ( ! empty( $content_struct['date_created_gmt'] ) ) { 3715 3719 // We know this is supposed to be GMT, so we're going to slap that Z on there by force 3716 $dateCreated = rtrim( $content_struct['date_created_gmt']->getIso(), 'Z' ) . 'Z';3717 $comment _date= get_date_from_gmt( iso8601_to_datetime( $dateCreated ) );3718 $comment _date_gmt= iso8601_to_datetime( $dateCreated, 'GMT' );3720 $dateCreated = rtrim( $content_struct['date_created_gmt']->getIso(), 'Z' ) . 'Z'; 3721 $comment['comment_date'] = get_date_from_gmt( iso8601_to_datetime( $dateCreated ) ); 3722 $comment['comment_date_gmt'] = iso8601_to_datetime( $dateCreated, 'GMT' ); 3719 3723 } 3720 3724 3721 3725 if ( isset( $content_struct['content'] ) ) { 3722 $comment _content= $content_struct['content'];3726 $comment['comment_content'] = $content_struct['content']; 3723 3727 } 3724 3728 3725 3729 if ( isset( $content_struct['author'] ) ) { 3726 $comment _author= $content_struct['author'];3730 $comment['comment_author'] = $content_struct['author']; 3727 3731 } 3728 3732 3729 3733 if ( isset( $content_struct['author_url'] ) ) { 3730 $comment _author_url= $content_struct['author_url'];3734 $comment['comment_author_url'] = $content_struct['author_url']; 3731 3735 } 3732 3736 3733 3737 if ( isset( $content_struct['author_email'] ) ) { 3734 $comment _author_email= $content_struct['author_email'];3738 $comment['comment_author_email'] = $content_struct['author_email']; 3735 3739 } 3736 3740 3737 // We've got all the data -- post it:3738 $comment = compact( 'comment_ID', 'comment_content', 'comment_approved', 'comment_date', 'comment_date_gmt', 'comment_author', 'comment_author_email', 'comment_author_url' );3739 3740 3741 $result = wp_update_comment( $comment ); 3741 3742 if ( is_wp_error( $result ) ) { 3742 3743 return new IXR_Error( 500, $result->get_error_message() ); … … 5261 5262 // Only use a password if one was given. 5262 5263 if ( isset( $content_struct['wp_password'] ) ) { 5263 5264 $post_password = $content_struct['wp_password']; 5265 } else { 5266 $post_password = ''; 5264 5267 } 5265 5268 5266 5269 // Only set a post parent if one was provided. 5267 5270 if ( isset( $content_struct['wp_page_parent_id'] ) ) { 5268 5271 $post_parent = $content_struct['wp_page_parent_id']; 5272 } else { 5273 $post_parent = 0; 5269 5274 } 5270 5275 5271 5276 // Only set the menu_order if it was provided. 5272 5277 if ( isset( $content_struct['wp_page_order'] ) ) { 5273 5278 $menu_order = $content_struct['wp_page_order']; 5279 } else { 5280 $menu_order = 0; 5274 5281 } 5275 5282 5276 5283 $post_author = $user->ID; … … 5599 5606 5600 5607 $this->escape( $postdata ); 5601 5608 5602 $ID = $postdata['ID']; 5603 $post_content = $postdata['post_content']; 5604 $post_title = $postdata['post_title']; 5605 $post_excerpt = $postdata['post_excerpt']; 5606 $post_password = $postdata['post_password']; 5607 $post_parent = $postdata['post_parent']; 5608 $post_type = $postdata['post_type']; 5609 $menu_order = $postdata['menu_order']; 5609 $ID = $postdata['ID']; 5610 $post_content = $postdata['post_content']; 5611 $post_title = $postdata['post_title']; 5612 $post_excerpt = $postdata['post_excerpt']; 5613 $post_password = $postdata['post_password']; 5614 $post_parent = $postdata['post_parent']; 5615 $post_type = $postdata['post_type']; 5616 $menu_order = $postdata['menu_order']; 5617 $ping_status = $postdata['ping_status']; 5618 $comment_status = $postdata['comment_status']; 5610 5619 5611 5620 // Let WordPress manage slug if none was provided. 5612 5621 $post_name = $postdata['post_name']; -
src/wp-includes/comment.php
3094 3094 */ 3095 3095 function wp_handle_comment_submission( $comment_data ) { 3096 3096 3097 $comment_post_ID = $comment_parent = 0;3097 $comment_post_ID = $comment_parent = $user_ID = 0; 3098 3098 $comment_author = $comment_author_email = $comment_author_url = $comment_content = null; 3099 3099 3100 3100 if ( isset( $comment_data['comment_post_ID'] ) ) { -
src/wp-includes/post.php
3345 3345 3346 3346 unset( $postarr['filter'] ); 3347 3347 3348 $postarr = sanitize_post( $postarr, 'db' ); 3348 $postarr = sanitize_post( $postarr, 'db' ); 3349 $sanitized_postarr = $postarr; 3349 3350 3350 3351 // Are we updating or creating? 3351 $post_ID = 0; 3352 $update = false; 3353 $guid = $postarr['guid']; 3352 $update = false; 3354 3353 3355 3354 if ( ! empty( $postarr['ID'] ) ) { 3356 3355 $update = true; 3357 3356 3358 3357 // Get the post ID and GUID. 3359 $post_ID = $postarr['ID']; 3360 $post_before = get_post( $post_ID ); 3358 $post_before = get_post( $postarr['ID'] ); 3361 3359 if ( is_null( $post_before ) ) { 3362 3360 if ( $wp_error ) { 3363 3361 return new WP_Error( 'invalid_post', __( 'Invalid post ID.' ) ); … … 3365 3363 return 0; 3366 3364 } 3367 3365 3368 $ guid = get_post_field( 'guid', $post_ID);3369 $previous_status = get_post_field( 'post_status', $post _ID);3366 $postarr['guid'] = get_post_field( 'guid', $postarr['ID'] ); 3367 $previous_status = get_post_field( 'post_status', $postarr['ID'] ); 3370 3368 } else { 3371 3369 $previous_status = 'new'; 3372 3370 } 3373 3371 3374 $post_type = empty( $postarr['post_type'] ) ? 'post' : $postarr['post_type']; 3372 if ( empty( $postarr['post_type'] ) ) { 3373 $postarr['post_type'] = 'post'; 3374 } 3375 3375 3376 $post_title = $postarr['post_title']; 3377 $post_content = $postarr['post_content']; 3378 $post_excerpt = $postarr['post_excerpt']; 3379 if ( isset( $postarr['post_name'] ) ) { 3380 $post_name = $postarr['post_name']; 3381 } elseif ( $update ) { 3376 if ( ! isset( $postarr['post_name'] ) && $update ) { 3382 3377 // For an update, don't modify the post_name if it wasn't supplied as an argument. 3383 $post _name= $post_before->post_name;3378 $postarr['post_name'] = $post_before->post_name; 3384 3379 } 3385 3380 3386 $maybe_empty = 'attachment' !== $post _type3387 && ! $post _content && ! $post_title && ! $post_excerpt3388 && post_type_supports( $post _type, 'editor' )3389 && post_type_supports( $post _type, 'title' )3390 && post_type_supports( $post _type, 'excerpt' );3381 $maybe_empty = 'attachment' !== $postarr['post_type'] 3382 && ! $postarr['post_content'] && ! $postarr['post_title'] && ! $postarr['post_excerpt'] 3383 && post_type_supports( $postarr['post_type'], 'editor' ) 3384 && post_type_supports( $postarr['post_type'], 'title' ) 3385 && post_type_supports( $postarr['post_type'], 'excerpt' ); 3391 3386 3392 3387 /** 3393 3388 * Filters whether the post should be considered "empty". … … 3413 3408 } 3414 3409 } 3415 3410 3416 $post_status = empty( $postarr['post_status'] ) ? 'draft' : $postarr['post_status']; 3417 if ( 'attachment' === $post_type && ! in_array( $post_status, array( 'inherit', 'private', 'trash', 'auto-draft' ), true ) ) { 3418 $post_status = 'inherit'; 3411 if ( empty( $postarr['post_status'] ) ) { 3412 $postarr['post_status'] = 'draft'; 3419 3413 } 3420 3414 3415 if ( 'attachment' === $postarr['post_type'] && ! in_array( $postarr['post_status'], array( 'inherit', 'private', 'trash', 'auto-draft' ), true ) ) { 3416 $postarr['post_status'] = 'inherit'; 3417 } 3418 3421 3419 if ( ! empty( $postarr['post_category'] ) ) { 3422 3420 // Filter out empty terms. 3423 $post _category= array_filter( $postarr['post_category'] );3421 $postarr['post_category'] = array_filter( $postarr['post_category'] ); 3424 3422 } 3425 3423 3426 3424 // Make sure we set a valid category. 3427 if ( empty( $post _category ) || 0 == count( $post_category ) || ! is_array( $post_category) ) {3425 if ( empty( $postarr['post_category'] ) || 0 == count( $postarr['post_category'] ) || ! is_array( $postarr['post_category'] ) ) { 3428 3426 // 'post' requires at least one category. 3429 if ( 'post' == $post _type && 'auto-draft' != $post_status) {3430 $post _category= array( get_option( 'default_category' ) );3427 if ( 'post' == $postarr['post_type'] && 'auto-draft' != $postarr['post_status'] ) { 3428 $postarr['post_category'] = array( get_option( 'default_category' ) ); 3431 3429 } else { 3432 $post _category= array();3430 $postarr['post_category'] = array(); 3433 3431 } 3434 3432 } 3435 3433 … … 3438 3436 * 3439 3437 * For new posts check the primitive capability, for updates check the meta capability. 3440 3438 */ 3441 $post_type_object = get_post_type_object( $post _type);3439 $post_type_object = get_post_type_object( $postarr['post_type'] ); 3442 3440 3443 if ( ! $update && 'pending' === $post _status&& ! current_user_can( $post_type_object->cap->publish_posts ) ) {3444 $post _name= '';3445 } elseif ( $update && 'pending' === $post _status && ! current_user_can( 'publish_post', $post_ID) ) {3446 $post _name= '';3441 if ( ! $update && 'pending' === $postarr['post_status'] && ! current_user_can( $post_type_object->cap->publish_posts ) ) { 3442 $postarr['post_name'] = ''; 3443 } elseif ( $update && 'pending' === $postarr['post_status'] && ! current_user_can( 'publish_post', $postarr['ID'] ) ) { 3444 $postarr['post_name'] = ''; 3447 3445 } 3448 3446 3449 3447 /* … … 3450 3448 * Create a valid post name. Drafts and pending posts are allowed to have 3451 3449 * an empty post name. 3452 3450 */ 3453 if ( empty( $post _name) ) {3454 if ( ! in_array( $post _status, array( 'draft', 'pending', 'auto-draft' ) ) ) {3455 $post _name = sanitize_title( $post_title);3451 if ( empty( $postarr['post_name'] ) ) { 3452 if ( ! in_array( $postarr['post_status'], array( 'draft', 'pending', 'auto-draft' ) ) ) { 3453 $postarr['post_name'] = sanitize_title( $postarr['post_title'] ); 3456 3454 } else { 3457 $post _name= '';3455 $postarr['post_name'] = ''; 3458 3456 } 3459 3457 } else { 3460 3458 // On updates, we need to check to see if it's using the old, fixed sanitization context. 3461 $check_name = sanitize_title( $post _name, '', 'old-save' );3462 if ( $update && strtolower( urlencode( $post _name ) ) == $check_name && get_post_field( 'post_name', $post_ID) == $check_name ) {3463 $post _name= $check_name;3459 $check_name = sanitize_title( $postarr['post_name'], '', 'old-save' ); 3460 if ( $update && strtolower( urlencode( $postarr['post_name'] ) ) == $check_name && get_post_field( 'post_name', $postarr['ID'] ) == $check_name ) { 3461 $postarr['post_name'] = $check_name; 3464 3462 } else { // new post, or slug has changed. 3465 $post _name = sanitize_title( $post_name);3463 $postarr['post_name'] = sanitize_title( $postarr['post_name'] ); 3466 3464 } 3467 3465 } 3468 3466 … … 3472 3470 */ 3473 3471 if ( empty( $postarr['post_date'] ) || '0000-00-00 00:00:00' == $postarr['post_date'] ) { 3474 3472 if ( empty( $postarr['post_date_gmt'] ) || '0000-00-00 00:00:00' == $postarr['post_date_gmt'] ) { 3475 $post _date= current_time( 'mysql' );3473 $postarr['post_date'] = current_time( 'mysql' ); 3476 3474 } else { 3477 $post _date= get_date_from_gmt( $postarr['post_date_gmt'] );3475 $postarr['post_date'] = get_date_from_gmt( $postarr['post_date_gmt'] ); 3478 3476 } 3479 } else {3480 $post_date = $postarr['post_date'];3481 3477 } 3482 3478 3483 3479 // Validate the date. 3484 $mm = substr( $post _date, 5, 2 );3485 $jj = substr( $post _date, 8, 2 );3486 $aa = substr( $post _date, 0, 4 );3487 $valid_date = wp_checkdate( $mm, $jj, $aa, $post _date);3480 $mm = substr( $postarr['post_date'], 5, 2 ); 3481 $jj = substr( $postarr['post_date'], 8, 2 ); 3482 $aa = substr( $postarr['post_date'], 0, 4 ); 3483 $valid_date = wp_checkdate( $mm, $jj, $aa, $postarr['post_date'] ); 3488 3484 if ( ! $valid_date ) { 3489 3485 if ( $wp_error ) { 3490 3486 return new WP_Error( 'invalid_date', __( 'Invalid date.' ) ); … … 3494 3490 } 3495 3491 3496 3492 if ( empty( $postarr['post_date_gmt'] ) || '0000-00-00 00:00:00' == $postarr['post_date_gmt'] ) { 3497 if ( ! in_array( $post _status, array( 'draft', 'pending', 'auto-draft' ) ) ) {3498 $post _date_gmt = get_gmt_from_date( $post_date);3493 if ( ! in_array( $postarr['post_status'], array( 'draft', 'pending', 'auto-draft' ) ) ) { 3494 $postarr['post_date_gmt'] = get_gmt_from_date( $postarr['post_date'] ); 3499 3495 } else { 3500 $post _date_gmt= '0000-00-00 00:00:00';3496 $postarr['post_date_gmt'] = '0000-00-00 00:00:00'; 3501 3497 } 3502 } else {3503 $post_date_gmt = $postarr['post_date_gmt'];3504 3498 } 3505 3499 3506 if ( $update || '0000-00-00 00:00:00' == $post _date) {3507 $post _modified= current_time( 'mysql' );3508 $post _modified_gmt= current_time( 'mysql', 1 );3500 if ( $update || '0000-00-00 00:00:00' == $postarr['post_date'] ) { 3501 $postarr['post_modified'] = current_time( 'mysql' ); 3502 $postarr['post_modified_gmt'] = current_time( 'mysql', 1 ); 3509 3503 } else { 3510 $post _modified = $post_date;3511 $post _modified_gmt = $post_date_gmt;3504 $postarr['post_modified'] = $postarr['post_date']; 3505 $postarr['post_modified_gmt'] = $postarr['post_date_gmt']; 3512 3506 } 3513 3507 3514 if ( 'attachment' !== $post _type) {3515 if ( 'publish' == $post _status) {3508 if ( 'attachment' !== $postarr['post_type'] ) { 3509 if ( 'publish' == $postarr['post_status'] ) { 3516 3510 $now = gmdate( 'Y-m-d H:i:59' ); 3517 if ( mysql2date( 'U', $post _date_gmt, false ) > mysql2date( 'U', $now, false ) ) {3518 $post _status= 'future';3511 if ( mysql2date( 'U', $postarr['post_date_gmt'], false ) > mysql2date( 'U', $now, false ) ) { 3512 $postarr['post_status'] = 'future'; 3519 3513 } 3520 } elseif ( 'future' == $post _status) {3514 } elseif ( 'future' == $postarr['post_status'] ) { 3521 3515 $now = gmdate( 'Y-m-d H:i:59' ); 3522 if ( mysql2date( 'U', $post _date_gmt, false ) <= mysql2date( 'U', $now, false ) ) {3523 $post _status= 'publish';3516 if ( mysql2date( 'U', $postarr['post_date_gmt'], false ) <= mysql2date( 'U', $now, false ) ) { 3517 $postarr['post_status'] = 'publish'; 3524 3518 } 3525 3519 } 3526 3520 } … … 3528 3522 // Comment status. 3529 3523 if ( empty( $postarr['comment_status'] ) ) { 3530 3524 if ( $update ) { 3531 $ comment_status= 'closed';3525 $postarr['comment_status'] = 'closed'; 3532 3526 } else { 3533 $ comment_status = get_default_comment_status( $post_type);3527 $postarr['comment_status'] = get_default_comment_status( $postarr['post_type'] ); 3534 3528 } 3529 } 3530 3531 if ( ! isset( $postarr['post_author'] ) ) { 3532 $postarr['post_author'] = $user_id; 3533 } 3534 3535 if ( empty( $postarr['ping_status'] ) ) { 3536 $postarr['ping_status'] = get_default_comment_status( $postarr['post_type'], 'pingback' ); 3537 } 3538 3539 if ( isset( $postarr['to_ping'] ) ) { 3540 $postarr['to_ping'] = sanitize_trackback_urls( $postarr['to_ping'] ); 3535 3541 } else { 3536 $ comment_status = $postarr['comment_status'];3542 $postarr['to_ping']; 3537 3543 } 3538 3544 3539 // These variables are needed by compact() later.3540 $post_content_filtered = $postarr['post_content_filtered'];3541 $post_author = isset( $postarr['post_author'] ) ? $postarr['post_author'] : $user_id;3542 $ping_status = empty( $postarr['ping_status'] ) ? get_default_comment_status( $post_type, 'pingback' ) : $postarr['ping_status'];3543 $to_ping = isset( $postarr['to_ping'] ) ? sanitize_trackback_urls( $postarr['to_ping'] ) : '';3544 $pinged = isset( $postarr['pinged'] ) ? $postarr['pinged'] : '';3545 $import_id = isset( $postarr['import_id'] ) ? $postarr['import_id'] : 0;3546 3547 3545 /* 3548 3546 * The 'wp_insert_post_parent' filter expects all variables to be present. 3549 3547 * Previously, these variables would have already been extracted 3550 3548 */ 3551 3549 if ( isset( $postarr['menu_order'] ) ) { 3552 $ menu_order= (int) $postarr['menu_order'];3550 $postarr['menu_order'] = (int) $postarr['menu_order']; 3553 3551 } else { 3554 $ menu_order= 0;3552 $postarr['menu_order'] = 0; 3555 3553 } 3556 3554 3557 $post_password = isset( $postarr['post_password'] ) ? $postarr['post_password'] : ''; 3558 if ( 'private' == $post_status ) { 3559 $post_password = ''; 3555 if ( 'private' == $postarr['post_status'] ) { 3556 $postarr['post_password'] = ''; 3560 3557 } 3561 3558 3562 3559 if ( isset( $postarr['post_parent'] ) ) { 3563 $post _parent= (int) $postarr['post_parent'];3560 $postarr['post_parent'] = (int) $postarr['post_parent']; 3564 3561 } else { 3565 $post _parent= 0;3562 $postarr['post_parent'] = 0; 3566 3563 } 3567 3564 3568 3565 /** … … 3570 3567 * 3571 3568 * @since 3.1.0 3572 3569 * 3573 * @param int $post_parent Post parent ID.3574 * @param int $post_ID Post ID.3575 * @param array $ new_postarrArray of parsed post data.3576 * @param array $ postarrArray of sanitized, but otherwise unmodified post data.3570 * @param int $post_parent Post parent ID. 3571 * @param int $post_ID Post ID. 3572 * @param array $postarr Array of parsed post data. 3573 * @param array $sanitized_postarr Array of sanitized, but otherwise unmodified post data. 3577 3574 */ 3578 $post _parent = apply_filters( 'wp_insert_post_parent', $post_parent, $post_ID, compact( array_keys( $postarr ) ), $postarr );3575 $postarr['post_parent'] = apply_filters( 'wp_insert_post_parent', $postarr['post_parent'], $postarr['ID'], $postarr, $sanitized_postarr ); 3579 3576 3580 3577 /* 3581 3578 * If the post is being untrashed and it has a desired slug stored in post meta, 3582 3579 * reassign it. 3583 3580 */ 3584 if ( 'trash' === $previous_status && 'trash' !== $post _status) {3585 $desired_post_slug = get_post_meta( $post _ID, '_wp_desired_post_slug', true );3581 if ( 'trash' === $previous_status && 'trash' !== $postarr['post_status'] ) { 3582 $desired_post_slug = get_post_meta( $postarr['ID'], '_wp_desired_post_slug', true ); 3586 3583 if ( $desired_post_slug ) { 3587 delete_post_meta( $post _ID, '_wp_desired_post_slug' );3588 $post _name= $desired_post_slug;3584 delete_post_meta( $postarr['ID'], '_wp_desired_post_slug' ); 3585 $postarr['post_name'] = $desired_post_slug; 3589 3586 } 3590 3587 } 3591 3588 3592 3589 // If a trashed post has the desired slug, change it and let this post have it. 3593 if ( 'trash' !== $post _status && $post_name) {3594 wp_add_trashed_suffix_to_post_name_for_trashed_posts( $post _name, $post_ID);3590 if ( 'trash' !== $postarr['post_status'] && $postarr['post_name'] ) { 3591 wp_add_trashed_suffix_to_post_name_for_trashed_posts( $postarr['post_name'], $postarr['ID'] ); 3595 3592 } 3596 3593 3597 3594 // When trashing an existing post, change its slug to allow non-trashed posts to use it. 3598 if ( 'trash' === $post _status&& 'trash' !== $previous_status && 'new' !== $previous_status ) {3599 $post _name = wp_add_trashed_suffix_to_post_name_for_post( $post_ID);3595 if ( 'trash' === $postarr['post_status'] && 'trash' !== $previous_status && 'new' !== $previous_status ) { 3596 $postarr['post_name'] = wp_add_trashed_suffix_to_post_name_for_post( $postarr['ID'] ); 3600 3597 } 3601 3598 3602 $post _name = wp_unique_post_slug( $post_name, $post_ID, $post_status, $post_type, $post_parent);3599 $postarr['post_name'] = wp_unique_post_slug( $postarr['post_name'], $postarr['ID'], $postarr['post_status'], $postarr['post_type'], $postarr['post_parent'] ); 3603 3600 3604 3601 // Don't unslash. 3605 $post_mime_type = isset( $postarr['post_mime_type'] ) ? $postarr['post_mime_type'] : ''; 3602 if ( ! isset( $postarr['post_mime_type'] ) ) { 3603 $postarr['post_mime_type'] = ''; 3604 } 3606 3605 3607 3606 // Expected_slashed (everything!). 3608 $data = compact( 'post_author', 'post_date', 'post_date_gmt', 'post_content', 'post_content_filtered', 'post_title', 'post_excerpt', 'post_status', 'post_type', 'comment_status', 'ping_status', 'post_password', 'post_name', 'to_ping', 'pinged', 'post_modified', 'post_modified_gmt', 'post_parent', 'menu_order', 'post_mime_type', 'guid' ); 3607 $data = wp_array_slice_assoc( 3608 $postarr, 3609 array( 3610 'post_author', 3611 'post_date', 3612 'post_date_gmt', 3613 'post_content', 3614 'post_content_filtered', 3615 'post_title', 3616 'post_excerpt', 3617 'post_status', 3618 'post_type', 3619 'comment_status', 3620 'ping_status', 3621 'post_password', 3622 'post_name', 3623 'to_ping', 3624 'pinged', 3625 'post_modified', 3626 'post_modified_gmt', 3627 'post_parent', 3628 'menu_order', 3629 'post_mime_type', 3630 'guid', 3631 ) 3632 ); 3609 3633 3610 3634 $emoji_fields = array( 'post_title', 'post_content', 'post_excerpt' ); 3611 3635 … … 3618 3642 } 3619 3643 } 3620 3644 3621 if ( 'attachment' === $post _type) {3645 if ( 'attachment' === $postarr['post_type'] ) { 3622 3646 /** 3623 3647 * Filters attachment post data before it is updated in or added to the database. 3624 3648 * 3625 3649 * @since 3.9.0 3626 3650 * 3627 * @param array $data An array of sanitized attachment post data.3628 * @param array $ postarr An array of unsanitized attachment post data.3651 * @param array $data An array of sanitized attachment post data. 3652 * @param array $sanitized_postarr An array of unsanitized attachment post data. 3629 3653 */ 3630 $data = apply_filters( 'wp_insert_attachment_data', $data, $ postarr );3654 $data = apply_filters( 'wp_insert_attachment_data', $data, $sanitized_postarr ); 3631 3655 } else { 3632 3656 /** 3633 3657 * Filters slashed post data just before it is inserted into the database. … … 3634 3658 * 3635 3659 * @since 2.7.0 3636 3660 * 3637 * @param array $data An array of slashed post data.3638 * @param array $ postarr An array of sanitized, but otherwise unmodified post data.3661 * @param array $data An array of slashed post data. 3662 * @param array $sanitized_postarr An array of sanitized, but otherwise unmodified post data. 3639 3663 */ 3640 $data = apply_filters( 'wp_insert_post_data', $data, $ postarr );3664 $data = apply_filters( 'wp_insert_post_data', $data, $sanitized_postarr ); 3641 3665 } 3642 3666 $data = wp_unslash( $data ); 3643 $where = array( 'ID' => $post _ID);3667 $where = array( 'ID' => $postarr['ID'] ); 3644 3668 3645 3669 if ( $update ) { 3646 3670 /** … … 3651 3675 * @param int $post_ID Post ID. 3652 3676 * @param array $data Array of unslashed post data. 3653 3677 */ 3654 do_action( 'pre_post_update', $post _ID, $data );3678 do_action( 'pre_post_update', $postarr['ID'], $data ); 3655 3679 if ( false === $wpdb->update( $wpdb->posts, $data, $where ) ) { 3656 3680 if ( $wp_error ) { 3657 3681 return new WP_Error( 'db_update_error', __( 'Could not update post in the database' ), $wpdb->last_error ); … … 3661 3685 } 3662 3686 } else { 3663 3687 // If there is a suggested ID, use it if not already present. 3664 if ( ! empty( $ import_id) ) {3665 $ import_id = (int) $import_id;3666 if ( ! $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE ID = %d", $ import_id) ) ) {3667 $data['ID'] = $ import_id;3688 if ( ! empty( $postarr['import_id'] ) ) { 3689 $postarr['import_id'] = (int) $postarr['import_id']; 3690 if ( ! $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE ID = %d", $postarr['import_id'] ) ) ) { 3691 $data['ID'] = $postarr['import_id']; 3668 3692 } 3669 3693 } 3670 3694 if ( false === $wpdb->insert( $wpdb->posts, $data ) ) { … … 3674 3698 return 0; 3675 3699 } 3676 3700 } 3677 $post _ID= (int) $wpdb->insert_id;3701 $postarr['ID'] = (int) $wpdb->insert_id; 3678 3702 3679 // Use the newly generated $post _ID.3680 $where = array( 'ID' => $post _ID);3703 // Use the newly generated $postarr['ID']. 3704 $where = array( 'ID' => $postarr['ID'] ); 3681 3705 } 3682 3706 3683 3707 if ( empty( $data['post_name'] ) && ! in_array( $data['post_status'], array( 'draft', 'pending', 'auto-draft' ) ) ) { 3684 $data['post_name'] = wp_unique_post_slug( sanitize_title( $data['post_title'], $post _ID ), $post_ID, $data['post_status'], $post_type, $post_parent);3708 $data['post_name'] = wp_unique_post_slug( sanitize_title( $data['post_title'], $postarr['ID'] ), $postarr['ID'], $data['post_status'], $postarr['post_type'], $postarr['post_parent'] ); 3685 3709 $wpdb->update( $wpdb->posts, array( 'post_name' => $data['post_name'] ), $where ); 3686 clean_post_cache( $post _ID);3710 clean_post_cache( $postarr['ID'] ); 3687 3711 } 3688 3712 3689 if ( is_object_in_taxonomy( $post _type, 'category' ) ) {3690 wp_set_post_categories( $post _ID, $post_category);3713 if ( is_object_in_taxonomy( $postarr['post_type'], 'category' ) ) { 3714 wp_set_post_categories( $postarr['ID'], $postarr['post_category'] ); 3691 3715 } 3692 3716 3693 if ( isset( $postarr['tags_input'] ) && is_object_in_taxonomy( $post _type, 'post_tag' ) ) {3694 wp_set_post_tags( $post _ID, $postarr['tags_input'] );3717 if ( isset( $postarr['tags_input'] ) && is_object_in_taxonomy( $postarr['post_type'], 'post_tag' ) ) { 3718 wp_set_post_tags( $postarr['ID'], $postarr['tags_input'] ); 3695 3719 } 3696 3720 3697 3721 // New-style support for all custom taxonomies. … … 3709 3733 $tags = array_filter( $tags ); 3710 3734 } 3711 3735 if ( current_user_can( $taxonomy_obj->cap->assign_terms ) ) { 3712 wp_set_post_terms( $post _ID, $tags, $taxonomy );3736 wp_set_post_terms( $postarr['ID'], $tags, $taxonomy ); 3713 3737 } 3714 3738 } 3715 3739 } … … 3716 3740 3717 3741 if ( ! empty( $postarr['meta_input'] ) ) { 3718 3742 foreach ( $postarr['meta_input'] as $field => $value ) { 3719 update_post_meta( $post _ID, $field, $value );3743 update_post_meta( $postarr['ID'], $field, $value ); 3720 3744 } 3721 3745 } 3722 3746 3723 $current_guid = get_post_field( 'guid', $post _ID);3747 $current_guid = get_post_field( 'guid', $postarr['ID'] ); 3724 3748 3725 3749 // Set GUID. 3726 3750 if ( ! $update && '' == $current_guid ) { 3727 $wpdb->update( $wpdb->posts, array( 'guid' => get_permalink( $post _ID) ), $where );3751 $wpdb->update( $wpdb->posts, array( 'guid' => get_permalink( $postarr['ID'] ) ), $where ); 3728 3752 } 3729 3753 3730 3754 if ( 'attachment' === $postarr['post_type'] ) { 3731 3755 if ( ! empty( $postarr['file'] ) ) { 3732 update_attached_file( $post _ID, $postarr['file'] );3756 update_attached_file( $postarr['ID'], $postarr['file'] ); 3733 3757 } 3734 3758 3735 3759 if ( ! empty( $postarr['context'] ) ) { 3736 add_post_meta( $post _ID, '_wp_attachment_context', $postarr['context'], true );3760 add_post_meta( $postarr['ID'], '_wp_attachment_context', $postarr['context'], true ); 3737 3761 } 3738 3762 } 3739 3763 3740 3764 // Set or remove featured image. 3741 3765 if ( isset( $postarr['_thumbnail_id'] ) ) { 3742 $thumbnail_support = current_theme_supports( 'post-thumbnails', $post _type ) && post_type_supports( $post_type, 'thumbnail' ) || 'revision' === $post_type;3743 if ( ! $thumbnail_support && 'attachment' === $post _type && $post_mime_type) {3744 if ( wp_attachment_is( 'audio', $post _ID) ) {3766 $thumbnail_support = current_theme_supports( 'post-thumbnails', $postarr['post_type'] ) && post_type_supports( $postarr['post_type'], 'thumbnail' ) || 'revision' === $postarr['post_type']; 3767 if ( ! $thumbnail_support && 'attachment' === $postarr['post_type'] && $postarr['post_mime_type'] ) { 3768 if ( wp_attachment_is( 'audio', $postarr['ID'] ) ) { 3745 3769 $thumbnail_support = post_type_supports( 'attachment:audio', 'thumbnail' ) || current_theme_supports( 'post-thumbnails', 'attachment:audio' ); 3746 } elseif ( wp_attachment_is( 'video', $post _ID) ) {3770 } elseif ( wp_attachment_is( 'video', $postarr['ID'] ) ) { 3747 3771 $thumbnail_support = post_type_supports( 'attachment:video', 'thumbnail' ) || current_theme_supports( 'post-thumbnails', 'attachment:video' ); 3748 3772 } 3749 3773 } … … 3751 3775 if ( $thumbnail_support ) { 3752 3776 $thumbnail_id = intval( $postarr['_thumbnail_id'] ); 3753 3777 if ( -1 === $thumbnail_id ) { 3754 delete_post_thumbnail( $post _ID);3778 delete_post_thumbnail( $postarr['ID'] ); 3755 3779 } else { 3756 set_post_thumbnail( $post _ID, $thumbnail_id );3780 set_post_thumbnail( $postarr['ID'], $thumbnail_id ); 3757 3781 } 3758 3782 } 3759 3783 } 3760 3784 3761 clean_post_cache( $post _ID);3785 clean_post_cache( $postarr['ID'] ); 3762 3786 3763 $post = get_post( $post _ID);3787 $post = get_post( $postarr['ID'] ); 3764 3788 3765 3789 if ( ! empty( $postarr['page_template'] ) ) { 3766 3790 $post->page_template = $postarr['page_template']; … … 3769 3793 if ( $wp_error ) { 3770 3794 return new WP_Error( 'invalid_page_template', __( 'Invalid page template.' ) ); 3771 3795 } 3772 update_post_meta( $post _ID, '_wp_page_template', 'default' );3796 update_post_meta( $postarr['ID'], '_wp_page_template', 'default' ); 3773 3797 } else { 3774 update_post_meta( $post _ID, '_wp_page_template', $postarr['page_template'] );3798 update_post_meta( $postarr['ID'], '_wp_page_template', $postarr['page_template'] ); 3775 3799 } 3776 3800 } 3777 3801 … … 3786 3810 * 3787 3811 * @param int $post_ID Attachment ID. 3788 3812 */ 3789 do_action( 'edit_attachment', $post _ID);3790 $post_after = get_post( $post _ID);3813 do_action( 'edit_attachment', $postarr['ID'] ); 3814 $post_after = get_post( $postarr['ID'] ); 3791 3815 3792 3816 /** 3793 3817 * Fires once an existing attachment has been updated. … … 3798 3822 * @param WP_Post $post_after Post object following the update. 3799 3823 * @param WP_Post $post_before Post object before the update. 3800 3824 */ 3801 do_action( 'attachment_updated', $post _ID, $post_after, $post_before );3825 do_action( 'attachment_updated', $postarr['ID'], $post_after, $post_before ); 3802 3826 } else { 3803 3827 3804 3828 /** … … 3808 3832 * 3809 3833 * @param int $post_ID Attachment ID. 3810 3834 */ 3811 do_action( 'add_attachment', $post _ID);3835 do_action( 'add_attachment', $postarr['ID'] ); 3812 3836 } 3813 3837 3814 return $post _ID;3838 return $postarr['ID']; 3815 3839 } 3816 3840 3817 3841 if ( $update ) { … … 3826 3850 * @param int $post_ID Post ID. 3827 3851 * @param WP_Post $post Post object. 3828 3852 */ 3829 do_action( "edit_post_{$post->post_type}", $post _ID, $post );3853 do_action( "edit_post_{$post->post_type}", $postarr['ID'], $post ); 3830 3854 3831 3855 /** 3832 3856 * Fires once an existing post has been updated. … … 3836 3860 * @param int $post_ID Post ID. 3837 3861 * @param WP_Post $post Post object. 3838 3862 */ 3839 do_action( 'edit_post', $post _ID, $post );3863 do_action( 'edit_post', $postarr['ID'], $post ); 3840 3864 3841 $post_after = get_post( $post _ID);3865 $post_after = get_post( $postarr['ID'] ); 3842 3866 3843 3867 /** 3844 3868 * Fires once an existing post has been updated. … … 3849 3873 * @param WP_Post $post_after Post object following the update. 3850 3874 * @param WP_Post $post_before Post object before the update. 3851 3875 */ 3852 do_action( 'post_updated', $post _ID, $post_after, $post_before );3876 do_action( 'post_updated', $postarr['ID'], $post_after, $post_before ); 3853 3877 } 3854 3878 3855 3879 /** … … 3864 3888 * @param WP_Post $post Post object. 3865 3889 * @param bool $update Whether this is an existing post being updated or not. 3866 3890 */ 3867 do_action( "save_post_{$post->post_type}", $post _ID, $post, $update );3891 do_action( "save_post_{$post->post_type}", $postarr['ID'], $post, $update ); 3868 3892 3869 3893 /** 3870 3894 * Fires once a post has been saved. … … 3875 3899 * @param WP_Post $post Post object. 3876 3900 * @param bool $update Whether this is an existing post being updated or not. 3877 3901 */ 3878 do_action( 'save_post', $post _ID, $post, $update );3902 do_action( 'save_post', $postarr['ID'], $post, $update ); 3879 3903 3880 3904 /** 3881 3905 * Fires once a post has been saved. … … 3886 3910 * @param WP_Post $post Post object. 3887 3911 * @param bool $update Whether this is an existing post being updated or not. 3888 3912 */ 3889 do_action( 'wp_insert_post', $post _ID, $post, $update );3913 do_action( 'wp_insert_post', $postarr['ID'], $post, $update ); 3890 3914 3891 return $post _ID;3915 return $postarr['ID']; 3892 3916 } 3893 3917 3894 3918 /** -
tests/phpunit/tests/dependencies/scripts.php
866 866 * @covers ::wp_enqueue_code_editor() 867 867 */ 868 868 public function test_wp_enqueue_code_editor_when_generated_array_by_compact_will_be_passed() { 869 $file = ''; 869 870 $wp_enqueue_code_editor = wp_enqueue_code_editor( compact( 'file' ) ); 870 871 $this->assertNonEmptyMultidimensionalArray( $wp_enqueue_code_editor ); 871 872