WordPress主题致命错误”致命错误(调用未定义的方法WP_Error::get_items()”)

我的Wordpress主题之一显示以下错误:

Fatal error: Call to undefined method WP_Error::get_items() in /home1/mywebsite/public_html/learnphp123.com/wp-content/themes/econews/admin/IDE_admin.php on line 88

该文件的代码是(你可以在第88行上看到” get_items()” ……实际上是代码的第三行):
if($feed) { $html = '< ul> '; foreach ($feed-> get_items() as $item){ $html.="< li> < span> ".$item-> get_date('d M Y')."< /span> < a href=http://www.srcmini.com/"".$item-> get_permalink()."\"> ".$item-> get_title()."< /a> < /li> "; }

谁能告诉我用什么代替” get_items()” 吗?
【WordPress主题致命错误” 致命错误(调用未定义的方法WP_Error::get_items()” )】非常感谢你的帮助!该文件的总代码如下所示, 我仅在与提要get_items()有关的第88行上得到了错误。
< ?php/* Copyright 2010, idesigneco.com http://idesigneco.com */define('IDE_ADMIN_FEED', 'http://idesigneco.com/wp_pub.php?id=ide_admin_newsfeed.xml& theme='.IDE_CODE.'& ver='.IDE_VERSION); // load form generator and validator include IDE_ADMIN_PATH.'IDE_FormGenerator.class.php'; // initialize the admin form $Form = new IDE_FormGenerator(array( 'name' => 'admin', 'method' => 'post', 'action' => '' )); // setup the form fields $Form-> elements( null, array( 'admin_action' => array( 'type' => 'hidden', 'value' => 'admin', 'error' => 'Your settings have been updated.' ) ) ); // load theme specific options include IDE_ADMIN_PATH.'/IDE_admin_options.php'; $Form-> elements( null, array( 'submit' => array( 'type' => 'submit', 'value' => 'Save', 'label' => '' ), ) ); $Form-> printErrors(true); // ________________________________________________________// process the form data if(!empty($_POST['admin_action'])) {// unchecked checkbox options don't show up, so fill them with predefined key names ide_save_options( array_merge( array_fill_keys($IDE_checkboxes, ''), stripslashes_deep($_POST) ) ); $Form-> setErrors(array('admin_action')); }// ________________________________________________________// populate the form with saved options $Form-> data($IDE_options); // ________________________________________________________// print out the admin area ide_admin_header(); $Form-> generate(); ide_admin_footer(); // ________________________________________________________// idesigneco news feed function ide_admin_news() {$time = ide_option('admin_newsfeed_time'); $html =ide_option('admin_newsfeed'); // feed expired, update if(!$html || !$time || ($time+(5*3600)) < time() ) { if(function_exists('fetch_feed')){ $feed = fetch_feed(IDE_ADMIN_FEED); if($feed) { $html = '< ul> '; foreach ($feed-> get_items() as $item){ $html.="< li> < span> ".$item-> get_date('d M Y')."< /span> < a href=http://www.srcmini.com/"".$item-> get_permalink()."\"> ".$item-> get_title()."< /a> < /li> "; } $html.= '< /ul> '; } else { $html = 'Updates unavailable at this time'; } } else { // deprecated feed api if(function_exists('fetch_rss')){ include_once(ABSPATH . WPINC . '/rss.php'); $rss = fetch_rss(IDE_ADMIN_FEED); $html = '< ul> '; foreach ($rss-> items as $item){ $html.="< li> < span> ".date('d M Y', strtotime($item['pubdate']))."< /span> < a href=http://www.srcmini.com/"".$item['link']."\"> ".$item['title']."< /a> < /li> "; } $html.= '< /ul> '; } }ide_save_option('admin_newsfeed_time', time()); ide_save_option('admin_newsfeed', $html); }echo $html; }// admin header function ide_admin_header() { ?> < div id="ide_admin"> < div class="left"> < h1 class="ide_title"> < ?php echo IDE_NAME.' '.IDE_VERSION; ?> < /h1> < div class="clear"> < /div> < ?php }// admin footer function ide_admin_footer() { ?> < /div> < !-- left //--> < div class="right"> < div class="idesigneco"> < a href="http://idesigneco.com"> < img src="http://www.srcmini.com/< ?php echo IDE_ADMIN_STATIC.'/idesigneco.png'; ?> " alt="Theme by iDesignEco" title="Theme by iDesignEco" /> < /a> < /div> < div class="news"> < h2> iDesignEco Updates< /h2> < ?php ide_admin_news(); ?> < /div> < /div> < !-- right //--> < div class="clear"> < /div> < /div> < !-- ide_admin //--> < ?php }

?>
#1当获取$ feed的数据失败时, 可能会发生这种情况, 因此它变成了没有get_items()方法的WP_Error类。尝试像这样修改代码:
if (! is_wp_error( $feed )){ $html = '< ul> '; foreach ($feed-> get_items() as $item){ $html.="< li> < span> ".$item-> get_date('d M Y')."< /span> < a href=http://www.srcmini.com/"".$item-> get_permalink()."\"> ".$item-> get_title()."< /a> < /li> "; }

更新:
就像我假设的那样, $ feed从fetch_feed()获取其数据, 因此解决方案仍然应该是替换:
if($feed) {

与:
if (! is_wp_error( $feed )){

    推荐阅读