From 7aa24fb90487d93207d03e7f8bdf46856fc17e0c Mon Sep 17 00:00:00 2001 From: ryan Date: Wed, 13 Feb 2008 06:49:23 +0000 Subject: [PATCH] Use array keys instead of hard coded list when traversing post fields to sanitize. Props andy. fixes #5836 git-svn-id: http://svn.automattic.com/wordpress/trunk@6803 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/post.php | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/wp-includes/post.php b/wp-includes/post.php index d2077a1928..4795f3d639 100644 --- a/wp-includes/post.php +++ b/wp-includes/post.php @@ -696,23 +696,15 @@ function get_post_custom_values( $key = '', $post_id = 0 ) { } function sanitize_post($post, $context = 'display') { - if ( 'raw' == $context ) return $post; - // TODO: Use array keys instead of hard coded list - $fields = array('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_date', 'post_date_gmt', 'post_parent', 'menu_order', 'post_mime_type', 'post_category'); - - $do_object = false; if ( is_object($post) ) - $do_object = true; - - foreach ( $fields as $field ) { - if ( $do_object ) + foreach ( array_keys(get_object_vars($post)) as $field ) $post->$field = sanitize_post_field($field, $post->$field, $post->ID, $context); - else + else + foreach ( array_keys($post) as $field ) $post[$field] = sanitize_post_field($field, $post[$field], $post['ID'], $context); - } return $post; }