register_widget is causing 500 errors
-
I have a multie site setup, and I am trying to activate a theme. When doing so I get a nasty 500 error and the site (including admin dasboard for that site) are down.
Server error
The website encountered an error while retrieving https://localhost/blog.site.com/wp-admin/. It may be down for maintenance or configured incorrectly.
Here are some suggestions:
Reload this webpage later.
HTTP Error 500 (Internal Server Error): An unexpected condition was encountered while the server was attempting to fulfill the request.I activated the logs and get this error:
[10-Apr-2013 17:46:17 UTC] PHP Fatal error: Class 'Header' not found in /Applications/MAMP/htdocs/blog.site.com/wp-includes/widgets.php on line 324
I traced the header class to my functions.php file for the theme where I am trying to register a widget:
register_widget( 'Header' ); register_widget( 'Search_Widget' ); class Header extends WP_Widget { function __construct() { $widget_ops = array('description' => __( 'Displays the header.') ); parent::__construct('header', __('Header'), $widget_ops); } function widget( $args, $instance ) { extract( $args ); // global $post; global $categories, $cat_count, $top_level_cats, $top_level_count; $categories = get_the_category($post->ID); $cat_count = count($categories); /* if the page requested is a post detail or category page */ if ( is_single() || is_category() ) { /* set top level categories based on the nav */ $top_level_cats = array('brown', 'green', 'blue', 'red'); $top_level_count = count($top_level_cats); for ( $i = 0; $i < $cat_count; $i++ ) { /* if we're not in a parent category, then get the parent ID */ /* DISCLAIMER: we're only going 1 level deep here */ $slug = $categories[$i]->slug; $parentID = $categories[$i]->category_parent; if ( $parentID != 0 ) { $parent = get_category( $parentID ); } for ( $j = 0; $j < $top_level_count; $j++ ) { if ( $parentID == 0 && $slug == $top_level_cats[$j] ) { /* if it's a parent category and a top level category */ $slug = preg_replace("/-/", "_", $slug); $banner = get_option( $slug . '_banner'); $name = $categories[$i]->name; break 2; } else if ( $parent->category_parent == 0 && $parent->slug == $top_level_cats[$j] ) { /* if it's a child of a top level category */ $slug = preg_replace("/-/", "_", $parent->slug); $banner = get_option( $slug . '_banner'); $name = $parent->name; break 2; } } } } if ( !$banner ) { /* if banner was not set by the previous function, set it now */ $banner = get_option('banner'); $name = get_bloginfo('name'); } echo "<div class=\"container\">\n"; echo "<a href=\"" . get_option('home') . "\"><img src=\"" . $banner . "\" alt=\"" . $name . "\"></a>\n"; wp_nav_menu( array( 'theme_location' => 'blog-menu', 'container' => false, 'menu_id' => 'menu', 'fallback_cb' => '', 'link_before' => '<span class="c">', 'link_after' => '</span><span class="r"></span><span class="b"></span>' ) ); echo "</div>\n"; } } class Search_Widget extends WP_Widget { function __construct() { $widget_ops = array('description' => __( 'New search widget for the right rail.') ); parent::__construct('search_widget', __('Search Widget'), $widget_ops); } function widget( $args, $instance ) { extract( $args ); echo "<div class=\"pod wp-search\"><div class=\"hd\"></div><div class=\"bd\">\n"; include('searchform.php'); echo $after_widget; } }
I am completely baffled.
- The topic ‘register_widget is causing 500 errors’ is closed to new replies.