From 0b3cf7e738f267b7bedb3dd63f6d1b0106e4e697 Mon Sep 17 00:00:00 2001 From: ryan Date: Wed, 23 Nov 2005 01:35:08 +0000 Subject: [PATCH] Allow wp_insert/update_post to handle classes in addition to associative arrays. This should avoid the 'Cannot use object of type stdClass as array' warnings. git-svn-id: http://svn.automattic.com/wordpress/trunk@3200 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/functions-post.php | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/wp-includes/functions-post.php b/wp-includes/functions-post.php index bb04280547..9bdc7f05c4 100644 --- a/wp-includes/functions-post.php +++ b/wp-includes/functions-post.php @@ -8,6 +8,9 @@ function wp_insert_post($postarr = array()) { global $wpdb, $allowedtags, $user_ID; + if ( is_object($postarr) ) + $postarr = get_object_vars($postarr); + // export array as variables extract($postarr); @@ -196,6 +199,9 @@ function wp_insert_post($postarr = array()) { function wp_insert_attachment($object, $file, $post_parent = 0) { global $wpdb, $user_ID; + + if ( is_object($object) ) + $object = get_object_vars($object); // Export array as variables extract($object); @@ -221,9 +227,12 @@ function wp_insert_attachment($object, $file, $post_parent = 0) { $post_status = 'attachment'; - // Get the post ID. - if ( $update ) - $post_ID = $ID; + // Are we updating or creating? + $update = false; + if ( !empty($ID) ) { + $update = true; + $post_ID = $ID; + } // Create a valid post name. if ( empty($post_name) ) @@ -378,6 +387,9 @@ function wp_get_recent_posts($num = 10) { function wp_update_post($postarr = array()) { global $wpdb; + if ( is_object($postarr) ) + $postarr = get_object_vars($postarr); + // First, get all of the original fields $post = wp_get_single_post($postarr['ID'], ARRAY_A);