Skip to content
Browse files

Add checks for WP_Error. Props filosofo. see #4809

git-svn-id: http://svn.automattic.com/wordpress/trunk@6125 1a063a9b-81f0-0310-95a4-ce76da25c4cd
  • Loading branch information...
1 parent f30cd7a commit 9bfccd628638e948c2150bf3f3d4019d2a5e52bc ryan committed Sep 18, 2007
View
5 wp-admin/admin-ajax.php
@@ -204,8 +204,11 @@ function wp_ajax_meta_row( $pid, $mid, $key, $value ) {
$now = current_time('timestamp', 1);
if ( $pid = wp_insert_post( array(
'post_title' => sprintf('Draft created on %s at %s', date(get_option('date_format'), $now), date(get_option('time_format'), $now))
- ) ) )
+ ) ) ) {
+ if ( is_wp_error( $pid ) )
+ return $pid;
$mid = add_meta( $pid );
+ }
else
die('0');
} else if ( !$mid = add_meta( $id ) ) {
View
11 wp-admin/import/blogger.php
@@ -380,7 +380,9 @@ function import_blog($blogID) {
$entry = "<feed>$entry</feed>";
$AtomParser = new AtomParser();
$AtomParser->parse( $entry );
- $this->import_post($AtomParser->entry);
+ $result = $this->import_post($AtomParser->entry);
+ if ( is_wp_error( $result ) )
+ return $result;
unset($AtomParser);
}
} else break;
@@ -518,6 +520,8 @@ function import_post( $entry ) {
$post = compact('post_date', 'post_content', 'post_title', 'post_status');
$post_id = wp_insert_post($post);
+ if ( is_wp_error( $post_id ) )
+ return $post_id;
wp_create_categories( array_map( 'addslashes', $entry->categories ), $post_id );
@@ -531,6 +535,7 @@ function import_post( $entry ) {
++$this->blogs[$importing_blog]['posts_done'];
}
$this->save_vars();
+ return;
}
function import_comment( $entry ) {
@@ -767,7 +772,9 @@ function start() {
if ( isset( $_REQUEST['blog'] ) ) {
$blog = is_array($_REQUEST['blog']) ? array_shift( array_keys( $_REQUEST['blog'] ) ) : $_REQUEST['blog'];
$blog = (int) $blog;
- $this->import_blog( $blog );
+ $result = $this->import_blog( $blog );
+ if ( is_wp_error( $result ) )
+ echo $result->get_error_message();
} elseif ( isset($_GET['token']) )
$this->auth();
elseif ( $this->token && $this->token_is_valid() )
View
11 wp-admin/import/blogware.php
@@ -91,6 +91,9 @@ function import_posts() {
printf(__('Importing post <i>%s</i>...'), stripslashes($post_title));
$postdata = compact('post_author', 'post_date', 'post_content', 'post_title', 'post_status');
$post_id = wp_insert_post($postdata);
+ if ( is_wp_error( $post_id ) ) {
+ return $post_id;
+ }
if (!$post_id) {
_e("Couldn't get post ID");
echo '</li>';
@@ -155,7 +158,9 @@ function import() {
}
$this->file = $file['file'];
- $this->import_posts();
+ $result = $this->import_posts();
+ if ( is_wp_error( $result ) )
+ return $result;
wp_import_cleanup($file['id']);
echo '<h3>';
@@ -176,7 +181,9 @@ function dispatch() {
$this->greet();
break;
case 1 :
- $this->import();
+ $result = $this->import();
+ if ( is_wp_error( $result ) )
+ $result->get_error_message();
break;
}
View
12 wp-admin/import/dotclear.php
@@ -364,6 +364,8 @@ function posts2wp($posts='')
'ping_status' => $comment_status_map[$post_open_tb],
'comment_count' => $post_nb_comment + $post_nb_trackback)
);
+ if ( is_wp_error( $ret_id ) )
+ return $ret_id;
}
else
{
@@ -382,6 +384,8 @@ function posts2wp($posts='')
'ping_status' => $comment_status_map[$post_open_tb],
'comment_count' => $post_nb_comment + $post_nb_trackback)
);
+ if ( is_wp_error( $ret_id ) )
+ return $ret_id;
}
$dcposts2wpposts[$post_id] = $ret_id;
@@ -562,7 +566,9 @@ function import_posts()
{
// Post Import
$posts = $this->get_dc_posts();
- $this->posts2wp($posts);
+ $result = $this->posts2wp($posts);
+ if ( is_wp_error( $result ) )
+ return $result;
echo '<form action="admin.php?import=dotclear&amp;step=4" method="post">';
wp_nonce_field('import-dotclear');
@@ -710,7 +716,9 @@ function dispatch()
$this->import_users();
break;
case 3 :
- $this->import_posts();
+ $result = $this->import_posts();
+ if ( is_wp_error( $result ) )
+ echo $result->get_error_message();
break;
case 4 :
$this->import_comments();
View
7 wp-admin/import/greymatter.php
@@ -233,6 +233,8 @@ function import() {
$postdata = compact('post_author', 'post_date', 'post_date_gmt', 'post_content', 'post_title', 'post_excerpt', 'post_status', 'comment_status', 'ping_status', 'post_modified', 'post_modified_gmt');
$post_ID = wp_insert_post($postdata);
+ if ( is_wp_error( $post_ID ) )
+ return $post_ID;
}
$c=count($entry);
@@ -287,6 +289,7 @@ function import() {
<p><?php _e('Completed GreyMatter import!') ?></p>
<?php
$this->footer();
+ return;
}
function dispatch() {
@@ -301,7 +304,9 @@ function dispatch() {
break;
case 1:
check_admin_referer('import-greymatter');
- $this->import();
+ $result = $this->import();
+ if ( is_wp_error( $result ) )
+ echo $result->get_error_message();
break;
}
}
View
10 wp-admin/import/livejournal.php
@@ -71,6 +71,8 @@ function import_posts() {
printf(__('Importing post <i>%s</i>...'), stripslashes($post_title));
$postdata = compact('post_author', 'post_date', 'post_content', 'post_title', 'post_status');
$post_id = wp_insert_post($postdata);
+ if ( is_wp_error( $post_id ) )
+ return $post_id;
if (!$post_id) {
_e("Couldn't get post ID");
echo '</li>';
@@ -132,7 +134,9 @@ function import() {
}
$this->file = $file['file'];
- $this->import_posts();
+ $result = $this->import_posts();
+ if ( is_wp_error( $result ) )
+ return $result;
wp_import_cleanup($file['id']);
echo '<h3>';
@@ -154,7 +158,9 @@ function dispatch() {
break;
case 1 :
check_admin_referer('import-upload');
- $this->import();
+ $result = $this->import();
+ if ( is_wp_error( $result ) )
+ echo $result->get_error_message();
break;
}
View
14 wp-admin/import/mt.php
@@ -215,6 +215,8 @@ function save_post(&$post, &$comments, &$pings) {
$post->post_author = $this->checkauthor($post->post_author); //just so that if a post already exists, new users are not created by checkauthor
$post_id = wp_insert_post($post);
+ if ( is_wp_error( $post_id ) )
+ return $post_id;
// Add categories.
if ( 0 != count($post->categories) ) {
@@ -291,7 +293,9 @@ function process_posts() {
} else if ( '--------' == $line ) {
// Finishing a post.
$context = '';
- $this->save_post($post, $comments, $pings);
+ $result = $this->save_post($post, $comments, $pings);
+ if ( is_wp_error( $result ) )
+ return $result;
$post = new StdClass;
$comment = new StdClass();
$ping = new StdClass();
@@ -415,7 +419,9 @@ function import() {
else
$this->file = get_attached_file($this->id);
$this->get_authors_from_post();
- $this->process_posts();
+ $result = $this->process_posts();
+ if ( is_wp_error( $result ) )
+ return $result;
}
function dispatch() {
@@ -434,7 +440,9 @@ function dispatch() {
break;
case 2:
check_admin_referer('import-mt');
- $this->import();
+ $result = $this->import();
+ if ( is_wp_error( $result ) )
+ echo $result->get_error_message();
break;
}
}
View
10 wp-admin/import/rss.php
@@ -110,6 +110,8 @@ function import_posts() {
_e('Post already imported');
} else {
$post_id = wp_insert_post($post);
+ if ( is_wp_error( $post_id ) )
+ return $post_id;
if (!$post_id) {
_e("Couldn't get post ID");
return;
@@ -135,7 +137,9 @@ function import() {
$this->file = $file['file'];
$this->get_posts();
- $this->import_posts();
+ $result = $this->import_posts();
+ if ( is_wp_error( $result ) )
+ return $result;
wp_import_cleanup($file['id']);
echo '<h3>';
@@ -157,7 +161,9 @@ function dispatch() {
break;
case 1 :
check_admin_referer('import-upload');
- $this->import();
+ $result = $this->import();
+ if ( is_wp_error( $result ) )
+ echo $result->get_error_message();
break;
}
View
12 wp-admin/import/textpattern.php
@@ -305,6 +305,8 @@ function posts2wp($posts='')
'post_name' => $url_title,
'comment_count' => $comments_count)
);
+ if ( is_wp_error( $ret_id ) )
+ return $ret_id;
}
else
{
@@ -321,6 +323,8 @@ function posts2wp($posts='')
'post_name' => $url_title,
'comment_count' => $comments_count)
);
+ if ( is_wp_error( $ret_id ) )
+ return $ret_id;
}
$txpposts2wpposts[$ID] = $ret_id;
@@ -498,7 +502,9 @@ function import_posts()
{
// Post Import
$posts = $this->get_txp_posts();
- $this->posts2wp($posts);
+ $result = $this->posts2wp($posts);
+ if ( is_wp_error( $result ) )
+ return $result;
echo '<form action="admin.php?import=textpattern&amp;step=4" method="post">';
wp_nonce_field('import-textpattern');
@@ -638,7 +644,9 @@ function dispatch()
$this->import_users();
break;
case 3 :
- $this->import_posts();
+ $result = $this->import_posts();
+ if ( is_wp_error( $result ) )
+ echo $result->get_error_message();
break;
case 4 :
$this->import_comments();
View
23 wp-admin/import/wordpress.php
@@ -250,8 +250,11 @@ function process_posts() {
$i = -1;
echo '<ol>';
- foreach ($this->posts as $post)
- $this->process_post($post);
+ foreach ($this->posts as $post) {
+ $result = $this->process_post($post);
+ if ( is_wp_error( $result ) )
+ return $result;
+ }
echo '</ol>';
@@ -303,7 +306,11 @@ function process_post($post) {
// If it has parent, process parent first.
$post_parent = (int) $post_parent;
if ($parent = $this->posts_processed[$post_parent]) {
- if (!$parent[1]) $this->process_post($parent[0]); // If not yet, process the parent first.
+ if (!$parent[1]) {
+ $result = $this->process_post($parent[0]); // If not yet, process the parent first.
+ if ( is_wp_error( $result ) )
+ return $result;
+ }
$post_parent = $parent[1]; // New ID of the parent;
}
@@ -314,6 +321,8 @@ function process_post($post) {
$postdata = compact('post_author', 'post_date', 'post_date_gmt', 'post_content', 'post_title', 'post_excerpt', 'post_status', 'post_name', 'comment_status', 'ping_status', 'post_modified', 'post_modified_gmt', 'guid', 'post_parent', 'menu_order', 'post_type');
$comment_post_ID = $post_id = wp_insert_post($postdata);
+ if ( is_wp_error( $post_id ) )
+ return $post_id;
// Memorize old and new ID.
if ( $post_id && $post_ID && $this->posts_processed[$post_ID] )
@@ -382,7 +391,9 @@ function import() {
$this->get_authors_from_post();
$this->get_entries();
$this->process_categories();
- $this->process_posts();
+ $result = $this->process_posts();
+ if ( is_wp_error( $result ) )
+ return $result;
}
function dispatch() {
@@ -402,7 +413,9 @@ function dispatch() {
break;
case 2:
check_admin_referer('import-wordpress');
- $this->import();
+ $result = $this->import();
+ if ( is_wp_error( $result ) )
+ echo $result->get_error_message();
break;
}
$this->footer();
View
3 wp-admin/includes/import.php
@@ -8,7 +8,8 @@ function get_importers() {
function register_importer( $id, $name, $description, $callback ) {
global $wp_importers;
-
+ if ( is_wp_error( $callback ) )
+ return $callback;
$wp_importers[$id] = array ( $name, $description, $callback );
}
View
2 wp-admin/includes/post.php
@@ -284,6 +284,8 @@ function wp_write_post() {
// Create the post.
$post_ID = wp_insert_post( $_POST );
+ if ( is_wp_error( $post_ID ) )
+ return $post_ID;
if ( empty($post_ID) )
return 0;
View
2 wp-admin/includes/upgrade.php
@@ -992,7 +992,7 @@ function dbDelta($queries, $execute = true) {
}
// Add the column list to the index create string
$index_string .= ' ('.$index_columns.')';
-
+ error_log("Index string: $index_string", 0);
if(!(($aindex = array_search($index_string, $indices)) === false)) {
unset($indices[$aindex]);
//echo "<pre style=\"border:1px solid #ccc;margin-top:5px;\">{$table}:<br />Found index:".$index_string."</pre>\n";
View
2 wp-admin/link-manager.php
@@ -159,6 +159,8 @@ function checkAll(form)
$cat_names = array();
foreach ($link->link_category as $category) {
$cat = get_term($category, 'link_category', OBJECT, 'display');
+ if ( is_wp_error( $cat ) )
+ echo $cat->get_error_message();
$cat_name = $cat->name;
if ( $cat_id != $category )
$cat_name = "<a href='link-manager.php?cat_id=$category'>$cat_name</a>";
View
2 wp-app.php
@@ -262,6 +262,8 @@ function create_post() {
log_app('Inserting Post. Data:', print_r($post_data,true));
$postID = wp_insert_post($post_data);
+ if ( is_wp_error( $postID ) )
+ $this->internal_error($postID->get_error_message());
if (!$postID) {
$this->internal_error(__('Sorry, your entry could not be posted. Something wrong happened.'));
View
31 wp-includes/category-template.php
@@ -12,6 +12,8 @@ function get_category_children($id, $before = '/', $after = '') {
continue;
$category = get_category($cat_id);
+ if ( is_wp_error( $category ) )
+ return $category;
if ( $category->parent == $id ) {
$chain .= $before.$category->term_id.$after;
$chain .= get_category_children($category->term_id, $before, $after);
@@ -29,6 +31,8 @@ function get_category_link($category_id) {
$catlink = $file . '?cat=' . $category_id;
} else {
$category = &get_category($category_id);
+ if ( is_wp_error( $category ) )
+ return $category;
$category_nicename = $category->slug;
if ( $parent = $category->parent )
@@ -43,6 +47,8 @@ function get_category_link($category_id) {
function get_category_parents($id, $link = FALSE, $separator = '/', $nicename = FALSE){
$chain = '';
$parent = &get_category($id);
+ if ( is_wp_error( $parent ) )
+ return $parent;
if ( $nicename )
$name = $parent->slug;
@@ -98,6 +104,8 @@ function _usort_terms_by_ID($a, $b) {
function get_the_category_by_ID($cat_ID) {
$cat_ID = (int) $cat_ID;
$category = &get_category($cat_ID);
+ if ( is_wp_error( $category ) )
+ return $category;
return $category->name;
}
@@ -313,7 +321,10 @@ function wp_tag_cloud( $args = '' ) {
return;
$return = wp_generate_tag_cloud( $tags, $args ); // Here's where those top tags get sorted according to $args
- echo apply_filters( 'wp_tag_cloud', $return, $args );
+ if ( is_wp_error( $return ) )
+ return false;
+ else
+ echo apply_filters( 'wp_tag_cloud', $return, $args );
}
// $tags = prefetched tag array ( get_tags() )
@@ -334,6 +345,8 @@ function wp_generate_tag_cloud( $tags, $args = '' ) {
foreach ( (array) $tags as $tag ) {
$counts[$tag->name] = $tag->count;
$tag_links[$tag->name] = get_tag_link( $tag->term_id );
+ if ( is_wp_error( $tag_links[$tag->name] ) )
+ return $tag_links[$tag->name];
$tag_ids[$tag->name] = $tag->term_id;
}
@@ -410,6 +423,8 @@ function get_tag_link( $tag_id ) {
$taglink = $wp_rewrite->get_tag_permastruct();
$tag = &get_term($tag_id, 'post_tag');
+ if ( is_wp_error( $tag ) )
+ return $tag;
$slug = $tag->slug;
if ( empty($taglink) ) {
@@ -450,8 +465,12 @@ function get_the_tag_list( $before = '', $sep = '', $after = '' ) {
return false;
$tag_list = $before;
- foreach ( $tags as $tag )
- $tag_links[] = '<a href="' . get_tag_link($tag->term_id) . '" rel="tag">' . $tag->name . '</a>';
+ foreach ( $tags as $tag ) {
+ $link = get_tag_link($tag->term_id);
+ if ( is_wp_error( $link ) )
+ return $link;
+ $tag_links[] = '<a href="' . $link . '" rel="tag">' . $tag->name . '</a>';
+ }
$tag_links = join( $sep, $tag_links );
$tag_links = apply_filters( 'the_tags', $tag_links );
@@ -463,7 +482,11 @@ function get_the_tag_list( $before = '', $sep = '', $after = '' ) {
}
function the_tags( $before = 'Tags: ', $sep = ', ', $after = '' ) {
- echo get_the_tag_list($before, $sep, $after);
+ $return = get_the_tag_list($before, $sep, $after);
+ if ( is_wp_error( $return ) )
+ return false;
+ else
+ echo $return;
}
?>
View
4 wp-includes/category.php
@@ -30,6 +30,8 @@ function &get_categories($args = '') {
// Handles category caching.
function &get_category($category, $output = OBJECT, $filter = 'raw') {
$category = get_term($category, 'category', $output, $filter);
+ if ( is_wp_error( $category ) )
+ return $category;
_make_cat_compat($category);
@@ -58,6 +60,8 @@ function get_category_by_path($category_path, $full_match = true, $output = OBJE
$curcategory = $category;
while ( ($curcategory->parent != 0) && ($curcategory->parent != $curcategory->term_id) ) {
$curcategory = get_term($curcategory->parent, 'category');
+ if ( is_wp_error( $curcategory ) )
+ return $curcategory;
$path = '/' . $curcategory->slug . $path;
}
View
2 wp-includes/feed.php
@@ -12,6 +12,8 @@ function bloginfo_rss($show = '') {
function get_wp_title_rss($sep = '&#187;') {
$title = wp_title($sep, false);
+ if ( is_wp_error( $title ) )
+ return $title->get_error_message();
$title = apply_filters('get_wp_title_rss', $title);
return $title;
}
View
2 wp-includes/general-template.php
@@ -195,6 +195,8 @@ function wp_title($sep = '&raquo;', $display = true) {
if ( !empty($tag) ) {
$tag = get_term($tag, 'post_tag', OBJECT, 'display');
+ if ( is_wp_error( $tag ) )
+ return $tag;
if ( ! empty($tag->name) )
$title = apply_filters('single_tag_title', $tag->name);
}
View
4 wp-includes/query.php
@@ -940,6 +940,8 @@ function &get_posts() {
if ( !empty($q['category__not_in']) ) {
$ids = get_objects_in_term($q['category__not_in'], 'category');
+ if ( is_wp_error( $ids ) )
+ return $ids;
if ( is_array($ids) && count($ids > 0) ) {
$out_posts = "'" . implode("', '", $ids) . "'";
$whichcat .= " AND $wpdb->posts.ID NOT IN ($out_posts)";
@@ -1415,6 +1417,8 @@ function get_queried_object() {
} else if ($this->is_tag) {
$tag_id = $this->get('tag_id');
$tag = &get_term($tag_id, 'post_tag');
+ if ( is_wp_error( $tag ) )
+ return $tag;
$this->queried_object = &$tag;
$this->queried_object_id = (int) $tag_id;
} else if ($this->is_posts_page) {
View
5 wp-includes/taxonomy.php
@@ -391,7 +391,6 @@ function get_term_children( $term, $taxonomy ) {
function get_term_field( $field, $term, $taxonomy, $context = 'display' ) {
$term = (int) $term;
$term = get_term( $term, $taxonomy );
-
if ( is_wp_error($term) )
return $term;
@@ -801,6 +800,8 @@ function wp_delete_term( $term, $taxonomy, $args = array() ) {
// Update children to point to new parent
if ( is_taxonomy_hierarchical($taxonomy) ) {
$term_obj = get_term($term, $taxonomy);
+ if ( is_wp_error( $term_obj ) )
+ return $term_obj;
$parent = $term_obj->parent;
$wpdb->query("UPDATE $wpdb->term_taxonomy SET parent = '$parent' WHERE parent = '$term_obj->term_id' AND taxonomy = '$taxonomy'");
@@ -1252,6 +1253,8 @@ function &_get_term_children($term_id, $terms, $taxonomy) {
$use_id = false;
if ( !is_object($term) ) {
$term = get_term($term, $taxonomy);
+ if ( is_wp_error( $term ) )
+ return $term;
$use_id = true;
}
View
2 wp-mail.php
@@ -148,6 +148,8 @@
$post_data = add_magic_quotes($post_data);
$post_ID = wp_insert_post($post_data);
+ if ( is_wp_error( $post_ID ) )
+ echo "\n" . $post_ID->get_error_message();
if (!$post_ID) {
// we couldn't post, for whatever reason. better move forward to the next email
View
4 xmlrpc.php
@@ -800,6 +800,8 @@ function blogger_newPost($args) {
$post_data = compact('blog_ID', 'post_author', 'post_date', 'post_date_gmt', 'post_content', 'post_title', 'post_category', 'post_status');
$post_ID = wp_insert_post($post_data);
+ if ( is_wp_error( $post_ID ) )
+ return new IXR_Error(500, $post_ID->get_error_message());
if (!$post_ID) {
return new IXR_Error(500, __('Sorry, your entry could not be posted. Something wrong happened.'));
@@ -1088,6 +1090,8 @@ function mw_newPost($args) {
$postdata = compact('post_author', 'post_date', 'post_date_gmt', 'post_content', 'post_title', 'post_category', 'post_status', 'post_excerpt', 'comment_status', 'ping_status', 'to_ping', 'post_type', 'post_name', 'post_password', 'post_parent', 'menu_order', 'tags_input');
$post_ID = wp_insert_post($postdata);
+ if ( is_wp_error( $post_ID ) )
+ return new IXR_Error(500, $post_ID->get_error_message());
if (!$post_ID) {
return new IXR_Error(500, __('Sorry, your entry could not be posted. Something wrong happened.'));

0 comments on commit 9bfccd6

Please sign in to comment.
Something went wrong with that request. Please try again.