Make WordPress Core

Changeset 6125


Ignore:
Timestamp:
09/18/2007 04:32:22 PM (19 years ago)
Author:
ryan
Message:

Add checks for WP_Error. Props filosofo. see #4809

Location:
trunk
Files:
23 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/admin-ajax.php

    r5923 r6125  
    205205                if ( $pid = wp_insert_post( array(
    206206                        'post_title' => sprintf('Draft created on %s at %s', date(get_option('date_format'), $now), date(get_option('time_format'), $now))
    207                 ) ) )
     207                ) ) ) {
     208                        if ( is_wp_error( $pid ) )
     209                                return $pid;
    208210                        $mid = add_meta( $pid );
     211                }
    209212                else
    210213                        die('0');
  • trunk/wp-admin/import/blogger.php

    r6043 r6125  
    381381                                                $AtomParser = new AtomParser();
    382382                                                $AtomParser->parse( $entry );
    383                                                 $this->import_post($AtomParser->entry);
     383                                                $result = $this->import_post($AtomParser->entry);
     384                                                if ( is_wp_error( $result ) )
     385                                                        return $result;
    384386                                                unset($AtomParser);
    385387                                        }
     
    519521
    520522                        $post_id = wp_insert_post($post);
     523                        if ( is_wp_error( $post_id ) )
     524                                return $post_id;
    521525
    522526                        wp_create_categories( array_map( 'addslashes', $entry->categories ), $post_id );
     
    532536                }
    533537                $this->save_vars();
     538                return;
    534539        }
    535540
     
    768773                        $blog = is_array($_REQUEST['blog']) ? array_shift( array_keys( $_REQUEST['blog'] ) ) : $_REQUEST['blog'];
    769774                        $blog = (int) $blog;
    770                         $this->import_blog( $blog );
     775                        $result = $this->import_blog( $blog );
     776                        if ( is_wp_error( $result ) )
     777                                echo $result->get_error_message();
    771778                } elseif ( isset($_GET['token']) )
    772779                        $this->auth();
  • trunk/wp-admin/import/blogware.php

    r5087 r6125  
    9292                                $postdata = compact('post_author', 'post_date', 'post_content', 'post_title', 'post_status');
    9393                                $post_id = wp_insert_post($postdata);
     94                                if ( is_wp_error( $post_id ) ) {
     95                                        return $post_id;
     96                                }
    9497                                if (!$post_id) {
    9598                                        _e("Couldn't get post ID");
     
    156159
    157160                $this->file = $file['file'];
    158                 $this->import_posts();
     161                $result = $this->import_posts();
     162                if ( is_wp_error( $result ) )
     163                        return $result;
    159164                wp_import_cleanup($file['id']);
    160165
     
    177182                                break;
    178183                        case 1 :
    179                                 $this->import();
     184                                $result = $this->import();
     185                                if ( is_wp_error( $result ) )
     186                                        $result->get_error_message();
    180187                                break;
    181188                }
  • trunk/wp-admin/import/dotclear.php

    r6026 r6125  
    365365                                                        'comment_count'         => $post_nb_comment + $post_nb_trackback)
    366366                                                        );
     367                                        if ( is_wp_error( $ret_id ) )
     368                                                return $ret_id;
    367369                                }
    368370                                else
     
    383385                                                        'comment_count'         => $post_nb_comment + $post_nb_trackback)
    384386                                                        );
     387                                        if ( is_wp_error( $ret_id ) )
     388                                                return $ret_id;
    385389                                }
    386390                                $dcposts2wpposts[$post_id] = $ret_id;
     
    563567                // Post Import
    564568                $posts = $this->get_dc_posts();
    565                 $this->posts2wp($posts);
     569                $result = $this->posts2wp($posts);
     570                if ( is_wp_error( $result ) )
     571                        return $result;
    566572
    567573                echo '<form action="admin.php?import=dotclear&amp;step=4" method="post">';
     
    711717                                break;
    712718                        case 3 :
    713                                 $this->import_posts();
     719                                $result = $this->import_posts();
     720                                if ( is_wp_error( $result ) )
     721                                        echo $result->get_error_message();
    714722                                break;
    715723                        case 4 :
  • trunk/wp-admin/import/greymatter.php

    r5404 r6125  
    234234                                $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');
    235235                                $post_ID = wp_insert_post($postdata);
     236                                if ( is_wp_error( $post_ID ) )
     237                                        return $post_ID;
    236238                        }
    237239
     
    288290<?php
    289291        $this->footer();
     292        return;
    290293        }
    291294
     
    302305                        case 1:
    303306                                check_admin_referer('import-greymatter');
    304                                 $this->import();
     307                                $result = $this->import();
     308                                if ( is_wp_error( $result ) )
     309                                        echo $result->get_error_message();
    305310                                break;
    306311                }
  • trunk/wp-admin/import/livejournal.php

    r5404 r6125  
    7272                                $postdata = compact('post_author', 'post_date', 'post_content', 'post_title', 'post_status');
    7373                                $post_id = wp_insert_post($postdata);
     74                                if ( is_wp_error( $post_id ) )
     75                                        return $post_id;
    7476                                if (!$post_id) {
    7577                                        _e("Couldn't get post ID");
     
    133135
    134136                $this->file = $file['file'];
    135                 $this->import_posts();
     137                $result = $this->import_posts();
     138                if ( is_wp_error( $result ) )
     139                        return $result;
    136140                wp_import_cleanup($file['id']);
    137141
     
    155159                        case 1 :
    156160                                check_admin_referer('import-upload');
    157                                 $this->import();
     161                                $result = $this->import();
     162                                if ( is_wp_error( $result ) )
     163                                        echo $result->get_error_message();
    158164                                break;
    159165                }
  • trunk/wp-admin/import/mt.php

    r6101 r6125  
    216216                        $post->post_author = $this->checkauthor($post->post_author); //just so that if a post already exists, new users are not created by checkauthor
    217217                        $post_id = wp_insert_post($post);
     218                        if ( is_wp_error( $post_id ) )
     219                                return $post_id;
    218220
    219221                        // Add categories.
     
    292294                                // Finishing a post.
    293295                                $context = '';
    294                                 $this->save_post($post, $comments, $pings);
     296                                $result = $this->save_post($post, $comments, $pings);
     297                                if ( is_wp_error( $result ) )
     298                                        return $result;
    295299                                $post = new StdClass;
    296300                                $comment = new StdClass();
     
    416420                        $this->file = get_attached_file($this->id);
    417421                $this->get_authors_from_post();
    418                 $this->process_posts();
     422                $result = $this->process_posts();
     423                if ( is_wp_error( $result ) )
     424                        return $result;
    419425        }
    420426
     
    435441                        case 2:
    436442                                check_admin_referer('import-mt');
    437                                 $this->import();
     443                                $result = $this->import();
     444                                if ( is_wp_error( $result ) )
     445                                        echo $result->get_error_message();
    438446                                break;
    439447                }
  • trunk/wp-admin/import/rss.php

    r5404 r6125  
    111111                        } else {
    112112                                $post_id = wp_insert_post($post);
     113                                if ( is_wp_error( $post_id ) )
     114                                        return $post_id;
    113115                                if (!$post_id) {
    114116                                        _e("Couldn't get post ID");
     
    136138                $this->file = $file['file'];
    137139                $this->get_posts();
    138                 $this->import_posts();
     140                $result = $this->import_posts();
     141                if ( is_wp_error( $result ) )
     142                        return $result;
    139143                wp_import_cleanup($file['id']);
    140144
     
    158162                        case 1 :
    159163                                check_admin_referer('import-upload');
    160                                 $this->import();
     164                                $result = $this->import();
     165                                if ( is_wp_error( $result ) )
     166                                        echo $result->get_error_message();
    161167                                break;
    162168                }
  • trunk/wp-admin/import/textpattern.php

    r6026 r6125  
    306306                                                'comment_count'         => $comments_count)
    307307                                                );
     308                                        if ( is_wp_error( $ret_id ) )
     309                                                return $ret_id;
    308310                                }
    309311                                else
     
    322324                                                'comment_count'         => $comments_count)
    323325                                                );
     326                                        if ( is_wp_error( $ret_id ) )
     327                                                return $ret_id;
    324328                                }
    325329                                $txpposts2wpposts[$ID] = $ret_id;
     
    499503                // Post Import
    500504                $posts = $this->get_txp_posts();
    501                 $this->posts2wp($posts);
     505                $result = $this->posts2wp($posts);
     506                if ( is_wp_error( $result ) )
     507                        return $result;
    502508
    503509                echo '<form action="admin.php?import=textpattern&amp;step=4" method="post">';
     
    639645                                break;
    640646                        case 3 :
    641                                 $this->import_posts();
     647                                $result = $this->import_posts();
     648                                if ( is_wp_error( $result ) )
     649                                        echo $result->get_error_message();
    642650                                break;
    643651                        case 4 :
  • trunk/wp-admin/import/wordpress.php

    r6026 r6125  
    251251                echo '<ol>';
    252252
    253                 foreach ($this->posts as $post)
    254                         $this->process_post($post);
     253                foreach ($this->posts as $post) {
     254                        $result = $this->process_post($post);
     255                        if ( is_wp_error( $result ) )
     256                                return $result;
     257                }
    255258
    256259                echo '</ol>';
     
    304307                        $post_parent = (int) $post_parent;
    305308                        if ($parent = $this->posts_processed[$post_parent]) {
    306                                 if (!$parent[1]) $this->process_post($parent[0]); // If not yet, process the parent first.
     309                                if (!$parent[1]) {
     310                                        $result = $this->process_post($parent[0]); // If not yet, process the parent first.
     311                                        if ( is_wp_error( $result ) )
     312                                                return $result;
     313                                }
    307314                                $post_parent = $parent[1]; // New ID of the parent;
    308315                        }
     
    315322                        $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');
    316323                        $comment_post_ID = $post_id = wp_insert_post($postdata);
     324                        if ( is_wp_error( $post_id ) )
     325                                return $post_id;
    317326
    318327                        // Memorize old and new ID.
     
    383392                $this->get_entries();
    384393                $this->process_categories();
    385                 $this->process_posts();
     394                $result = $this->process_posts();
     395                if ( is_wp_error( $result ) )
     396                        return $result;
    386397        }
    387398
     
    403414                        case 2:
    404415                                check_admin_referer('import-wordpress');
    405                                 $this->import();
     416                                $result = $this->import();
     417                                if ( is_wp_error( $result ) )
     418                                        echo $result->get_error_message();
    406419                                break;
    407420                }
  • trunk/wp-admin/includes/import.php

    r5566 r6125  
    99function register_importer( $id, $name, $description, $callback ) {
    1010        global $wp_importers;
    11 
     11        if ( is_wp_error( $callback ) )
     12                return $callback;
    1213        $wp_importers[$id] = array ( $name, $description, $callback );
    1314}
  • trunk/wp-admin/includes/post.php

    r6026 r6125  
    285285        // Create the post.
    286286        $post_ID = wp_insert_post( $_POST );
     287        if ( is_wp_error( $post_ID ) )
     288                return $post_ID;
    287289
    288290        if ( empty($post_ID) )
  • trunk/wp-admin/includes/upgrade.php

    r6053 r6125  
    993993                                                // Add the column list to the index create string
    994994                                                $index_string .= ' ('.$index_columns.')';
    995 
     995                                                error_log("Index string: $index_string", 0);
    996996                                                if(!(($aindex = array_search($index_string, $indices)) === false)) {
    997997                                                        unset($indices[$aindex]);
  • trunk/wp-admin/link-manager.php

    r5906 r6125  
    160160                                        foreach ($link->link_category as $category) {
    161161                                                $cat = get_term($category, 'link_category', OBJECT, 'display');
     162                                                if ( is_wp_error( $cat ) )
     163                                                        echo $cat->get_error_message();
    162164                                                $cat_name = $cat->name;
    163165                                                if ( $cat_id != $category )
  • trunk/wp-app.php

    r6032 r6125  
    263263
    264264                $postID = wp_insert_post($post_data);
     265                if ( is_wp_error( $postID ) )
     266                        $this->internal_error($postID->get_error_message());
    265267
    266268                if (!$postID) {
  • trunk/wp-includes/category-template.php

    r6091 r6125  
    1313
    1414                $category = get_category($cat_id);
     15                if ( is_wp_error( $category ) )
     16                        return $category;
    1517                if ( $category->parent == $id ) {
    1618                        $chain .= $before.$category->term_id.$after;
     
    3032        } else {
    3133                $category = &get_category($category_id);
     34                if ( is_wp_error( $category ) )
     35                        return $category;
    3236                $category_nicename = $category->slug;
    3337
     
    4448        $chain = '';
    4549        $parent = &get_category($id);
     50        if ( is_wp_error( $parent ) )
     51                return $parent;
    4652
    4753        if ( $nicename )
     
    99105        $cat_ID = (int) $cat_ID;
    100106        $category = &get_category($cat_ID);
     107        if ( is_wp_error( $category ) )
     108                return $category;
    101109        return $category->name;
    102110}
     
    314322
    315323        $return = wp_generate_tag_cloud( $tags, $args ); // Here's where those top tags get sorted according to $args
    316         echo apply_filters( 'wp_tag_cloud', $return, $args );
     324        if ( is_wp_error( $return ) )
     325                return false;
     326        else
     327                echo apply_filters( 'wp_tag_cloud', $return, $args );
    317328}
    318329
     
    335346                $counts[$tag->name] = $tag->count;
    336347                $tag_links[$tag->name] = get_tag_link( $tag->term_id );
     348                if ( is_wp_error( $tag_links[$tag->name] ) )
     349                        return $tag_links[$tag->name];
    337350                $tag_ids[$tag->name] = $tag->term_id;
    338351        }
     
    411424
    412425        $tag = &get_term($tag_id, 'post_tag');
     426        if ( is_wp_error( $tag ) )
     427                return $tag;
    413428        $slug = $tag->slug;
    414429
     
    451466
    452467        $tag_list = $before;
    453         foreach ( $tags as $tag )
    454                 $tag_links[] = '<a href="' . get_tag_link($tag->term_id) . '" rel="tag">' . $tag->name . '</a>';
     468        foreach ( $tags as $tag ) {
     469                $link = get_tag_link($tag->term_id);
     470                if ( is_wp_error( $link ) )
     471                        return $link;
     472                $tag_links[] = '<a href="' . $link . '" rel="tag">' . $tag->name . '</a>';
     473        }
    455474
    456475        $tag_links = join( $sep, $tag_links );
     
    464483
    465484function the_tags( $before = 'Tags: ', $sep = ', ', $after = '' ) {
    466         echo get_the_tag_list($before, $sep, $after);
     485        $return = get_the_tag_list($before, $sep, $after);
     486        if ( is_wp_error( $return ) )
     487                return false;
     488        else
     489                echo $return;
    467490}
    468491
  • trunk/wp-includes/category.php

    r6071 r6125  
    3131function &get_category($category, $output = OBJECT, $filter = 'raw') {
    3232        $category = get_term($category, 'category', $output, $filter);
     33        if ( is_wp_error( $category ) )
     34                return $category;
    3335
    3436        _make_cat_compat($category);
     
    5961                while ( ($curcategory->parent != 0) && ($curcategory->parent != $curcategory->term_id) ) {
    6062                        $curcategory = get_term($curcategory->parent, 'category');
     63                        if ( is_wp_error( $curcategory ) )
     64                                return $curcategory;
    6165                        $path = '/' . $curcategory->slug . $path;
    6266                }
  • trunk/wp-includes/feed.php

    r6114 r6125  
    1313function get_wp_title_rss($sep = '&#187;') {
    1414        $title = wp_title($sep, false);
     15        if ( is_wp_error( $title ) )
     16                return $title->get_error_message();
    1517        $title = apply_filters('get_wp_title_rss', $title);
    1618        return $title;
  • trunk/wp-includes/general-template.php

    r6119 r6125  
    196196        if ( !empty($tag) ) {
    197197                $tag = get_term($tag, 'post_tag', OBJECT, 'display');
     198                if ( is_wp_error( $tag ) )
     199                        return $tag;
    198200                if ( ! empty($tag->name) )
    199201                        $title = apply_filters('single_tag_title', $tag->name);
  • trunk/wp-includes/query.php

    r6074 r6125  
    941941                if ( !empty($q['category__not_in']) ) {
    942942                        $ids = get_objects_in_term($q['category__not_in'], 'category');
     943                        if ( is_wp_error( $ids ) )
     944                                return $ids;
    943945                        if ( is_array($ids) && count($ids > 0) ) {
    944946                                $out_posts = "'" . implode("', '", $ids) . "'";
     
    14161418                        $tag_id = $this->get('tag_id');
    14171419                        $tag = &get_term($tag_id, 'post_tag');
     1420                        if ( is_wp_error( $tag ) )
     1421                                return $tag;
    14181422                        $this->queried_object = &$tag;
    14191423                        $this->queried_object_id = (int) $tag_id;
  • trunk/wp-includes/taxonomy.php

    r6121 r6125  
    392392        $term = (int) $term;
    393393        $term = get_term( $term, $taxonomy );
    394 
    395394        if ( is_wp_error($term) )
    396395                return $term;
     
    802801        if ( is_taxonomy_hierarchical($taxonomy) ) {
    803802                $term_obj = get_term($term, $taxonomy);
     803                if ( is_wp_error( $term_obj ) )
     804                        return $term_obj;
    804805                $parent = $term_obj->parent;
    805806
     
    12531254                if ( !is_object($term) ) {
    12541255                        $term = get_term($term, $taxonomy);
     1256                        if ( is_wp_error( $term ) )
     1257                                return $term;
    12551258                        $use_id = true;
    12561259                }
  • trunk/wp-mail.php

    r6056 r6125  
    149149
    150150        $post_ID = wp_insert_post($post_data);
     151        if ( is_wp_error( $post_ID ) )
     152                echo "\n" . $post_ID->get_error_message();
    151153
    152154        if (!$post_ID) {
  • trunk/xmlrpc.php

    r6026 r6125  
    801801
    802802          $post_ID = wp_insert_post($post_data);
     803          if ( is_wp_error( $post_ID ) )
     804                return new IXR_Error(500, $post_ID->get_error_message());
    803805
    804806          if (!$post_ID) {
     
    10891091
    10901092          $post_ID = wp_insert_post($postdata);
     1093          if ( is_wp_error( $post_ID ) )
     1094                return new IXR_Error(500, $post_ID->get_error_message());
    10911095
    10921096          if (!$post_ID) {
Note: See TracChangeset for help on using the changeset viewer.