From 2bab8b487e3dc4349da96569f8d6fc07ecba08ed Mon Sep 17 00:00:00 2001 From: Ryan Boren 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: https://develop.svn.wordpress.org/trunk@3200 602fd350-edb4-49c9-b593-d223f7449a82 --- 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);