@@ -175,6 +175,27 @@ function _wp_translate_postdata( $update = false, $post_data = null ) {
175175 return $ post_data ;
176176}
177177
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+
178199/**
179200 * Update an existing post with values provided in $_POST.
180201 *
@@ -243,6 +264,7 @@ function edit_post( $post_data = null ) {
243264 $ post_data = _wp_translate_postdata ( true , $ post_data );
244265 if ( is_wp_error ($ post_data ) )
245266 wp_die ( $ post_data ->get_error_message () );
267+ $ translated = _wp_get_allowed_postdata ( $ post_data );
246268
247269 // Post Formats
248270 if ( isset ( $ post_data ['post_format ' ] ) )
@@ -322,7 +344,7 @@ function edit_post( $post_data = null ) {
322344 $ attachment_data = isset ( $ post_data ['attachments ' ][ $ post_ID ] ) ? $ post_data ['attachments ' ][ $ post_ID ] : array ();
323345
324346 /** 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 );
326348 }
327349
328350 // Convert taxonomy input to term IDs, to avoid ambiguity.
@@ -367,26 +389,26 @@ function edit_post( $post_data = null ) {
367389 }
368390 }
369391
370- $ post_data ['tax_input ' ][ $ taxonomy ] = $ clean_terms ;
392+ $ translated ['tax_input ' ][ $ taxonomy ] = $ clean_terms ;
371393 }
372394 }
373395
374396 add_meta ( $ post_ID );
375397
376398 update_post_meta ( $ post_ID , '_edit_last ' , get_current_user_id () );
377399
378- $ success = wp_update_post ( $ post_data );
400+ $ success = wp_update_post ( $ translated );
379401 // If the save failed, see if we can sanity check the main fields and try again
380402 if ( ! $ success && is_callable ( array ( $ wpdb , 'strip_invalid_text_for_column ' ) ) ) {
381403 $ fields = array ( 'post_title ' , 'post_content ' , 'post_excerpt ' );
382404
383405 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 ] );
386408 }
387409 }
388410
389- wp_update_post ( $ post_data );
411+ wp_update_post ( $ translated );
390412 }
391413
392414 // Now that we have an ID we can fix any attachment anchor hrefs
@@ -546,24 +568,22 @@ function bulk_edit_posts( $post_data = null ) {
546568 unset( $ post_data ['tax_input ' ]['category ' ] );
547569 }
548570
571+ $ post_data ['post_ID ' ] = $ post_ID ;
549572 $ post_data ['post_type ' ] = $ post ->post_type ;
550573 $ post_data ['post_mime_type ' ] = $ post ->post_mime_type ;
551- $ post_data ['guid ' ] = $ post ->guid ;
552574
553575 foreach ( array ( 'comment_status ' , 'ping_status ' , 'post_author ' ) as $ field ) {
554576 if ( ! isset ( $ post_data [ $ field ] ) ) {
555577 $ post_data [ $ field ] = $ post ->$ field ;
556578 }
557579 }
558580
559- $ post_data ['ID ' ] = $ post_ID ;
560- $ post_data ['post_ID ' ] = $ post_ID ;
561-
562581 $ post_data = _wp_translate_postdata ( true , $ post_data );
563582 if ( is_wp_error ( $ post_data ) ) {
564583 $ skipped [] = $ post_ID ;
565584 continue ;
566585 }
586+ $ post_data = _wp_get_allowed_postdata ( $ post_data );
567587
568588 $ updated [] = wp_update_post ( $ post_data );
569589
@@ -574,8 +594,8 @@ function bulk_edit_posts( $post_data = null ) {
574594 unstick_post ( $ post_ID );
575595 }
576596
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 ' ] );
579599 }
580600
581601 return array ( 'updated ' => $ updated , 'skipped ' => $ skipped , 'locked ' => $ locked );
@@ -756,9 +776,10 @@ function wp_write_post() {
756776 $ translated = _wp_translate_postdata ( false );
757777 if ( is_wp_error ($ translated ) )
758778 return $ translated ;
779+ $ translated = _wp_get_allowed_postdata ( $ translated );
759780
760781 // Create the post.
761- $ post_ID = wp_insert_post ( $ _POST );
782+ $ post_ID = wp_insert_post ( $ translated );
762783 if ( is_wp_error ( $ post_ID ) )
763784 return $ post_ID ;
764785
@@ -1678,6 +1699,7 @@ function wp_create_post_autosave( $post_data ) {
16781699 $ post_data = _wp_translate_postdata ( true , $ post_data );
16791700 if ( is_wp_error ( $ post_data ) )
16801701 return $ post_data ;
1702+ $ post_data = _wp_get_allowed_postdata ( $ post_data );
16811703
16821704 $ post_author = get_current_user_id ();
16831705
0 commit comments