Changeset 44055 for branches/4.8/src/wp-admin/includes/post.php
- Timestamp:
- 12/13/2018 01:39:08 AM (6 years ago)
- Location:
- branches/4.8
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/4.8
- Property svn:mergeinfo changed
/branches/5.0 merged: 44047
- Property svn:mergeinfo changed
-
branches/4.8/src/wp-admin/includes/post.php
r40424 r44055 177 177 178 178 /** 179 * Returns only allowed post data fields 180 * 181 * @since 4.9.9 182 * 183 * @param array $post_data Array of post data. Defaults to the contents of $_POST. 184 * @return object|bool WP_Error on failure, true on success. 185 */ 186 function _wp_get_allowed_postdata( $post_data = null ) { 187 if ( empty( $post_data ) ) { 188 $post_data = $_POST; 189 } 190 191 // Pass through errors 192 if ( is_wp_error( $post_data ) ) { 193 return $post_data; 194 } 195 196 return array_diff_key( $post_data, array_flip( array( 'meta_input', 'file', 'guid' ) ) ); 197 } 198 199 /** 179 200 * Update an existing post with values provided in $_POST. 180 201 * … … 244 265 if ( is_wp_error($post_data) ) 245 266 wp_die( $post_data->get_error_message() ); 267 $translated = _wp_get_allowed_postdata( $post_data ); 246 268 247 269 // Post Formats … … 323 345 324 346 /** This filter is documented in wp-admin/includes/media.php */ 325 $ post_data = apply_filters( 'attachment_fields_to_save', $post_data, $attachment_data );347 $translated = apply_filters( 'attachment_fields_to_save', $translated, $attachment_data ); 326 348 } 327 349 … … 368 390 } 369 391 370 $ post_data['tax_input'][ $taxonomy ] = $clean_terms;392 $translated['tax_input'][ $taxonomy ] = $clean_terms; 371 393 } 372 394 } … … 376 398 update_post_meta( $post_ID, '_edit_last', get_current_user_id() ); 377 399 378 $success = wp_update_post( $ post_data);400 $success = wp_update_post( $translated ); 379 401 // If the save failed, see if we can sanity check the main fields and try again 380 402 if ( ! $success && is_callable( array( $wpdb, 'strip_invalid_text_for_column' ) ) ) { … … 382 404 383 405 foreach ( $fields as $field ) { 384 if ( isset( $ post_data[ $field ] ) ) {385 $ post_data[ $field ] = $wpdb->strip_invalid_text_for_column( $wpdb->posts, $field, $post_data[ $field ] );406 if ( isset( $translated[ $field ] ) ) { 407 $translated[ $field ] = $wpdb->strip_invalid_text_for_column( $wpdb->posts, $field, $translated[ $field ] ); 386 408 } 387 409 } 388 410 389 wp_update_post( $ post_data);411 wp_update_post( $translated ); 390 412 } 391 413 … … 547 569 } 548 570 571 $post_data['post_ID'] = $post_ID; 549 572 $post_data['post_type'] = $post->post_type; 550 573 $post_data['post_mime_type'] = $post->post_mime_type; 551 $post_data['guid'] = $post->guid;552 574 553 575 foreach ( array( 'comment_status', 'ping_status', 'post_author' ) as $field ) { … … 557 579 } 558 580 559 $post_data['ID'] = $post_ID;560 $post_data['post_ID'] = $post_ID;561 562 581 $post_data = _wp_translate_postdata( true, $post_data ); 563 582 if ( is_wp_error( $post_data ) ) { … … 565 584 continue; 566 585 } 586 $post_data = _wp_get_allowed_postdata( $post_data ); 567 587 568 588 $updated[] = wp_update_post( $post_data ); … … 575 595 } 576 596 577 if ( isset( $ post_data['post_format'] ) )578 set_post_format( $post_ID, $ post_data['post_format'] );597 if ( isset( $shared_post_data['post_format'] ) ) 598 set_post_format( $post_ID, $shared_post_data['post_format'] ); 579 599 } 580 600 … … 757 777 if ( is_wp_error($translated) ) 758 778 return $translated; 779 $translated = _wp_get_allowed_postdata( $translated ); 759 780 760 781 // Create the post. 761 $post_ID = wp_insert_post( $ _POST);782 $post_ID = wp_insert_post( $translated ); 762 783 if ( is_wp_error( $post_ID ) ) 763 784 return $post_ID; … … 1679 1700 if ( is_wp_error( $post_data ) ) 1680 1701 return $post_data; 1702 $post_data = _wp_get_allowed_postdata( $post_data ); 1681 1703 1682 1704 $post_author = get_current_user_id();
Note: See TracChangeset
for help on using the changeset viewer.