$GLOBALS['wpkb'] = $wpkb = new Plugin(WPKB_VERSION, __FILE__, __DIR__);
$wpkb->add_hooks();
// load breadcrumbs
$breadcrumbs = new Breadcrumbs\Manager($wpkb->get_option('custom_archive_page_id'));
$breadcrumbs->add_hooks();
$wpkb->attach($breadcrumbs, 'breadcrumbs');
// load search
$search = new Search($wpkb);
$search->add_hooks();
$wpkb->attach($search, 'search');
// load code highlighter
$highlighting = new CodeHighlighting($wpkb);
$highlighting->add_hooks();
// load callouts
$callouts = new Callouts();
$callouts->add_hooks();
// rating
$rating = new Rating\Rater();
$rating->add_hooks();
$wpkb->attach($rating, 'rating');
if (is_admin()) {
    $rating_admin = new Rating\Admin();
    $rating_admin->add_hooks();
}
// load template manager
add_action('template_redirect', function () use($wpkb) {
    $template = new TemplateManager($wpkb);
    $template->override_templates();
});
// Register [wpkb_list] shortcode
ArticleList::register_shortcode();
global $wpkb;
$wpkb = wpkb();
$wpkb['options'] = $options = new Options('wpkb', array('custom_archive_page_id' => 0));
$router = new Router($options->get('custom_archive_page_id', 0));
$router->add_hooks();
$wpkb['plugin'] = $plugin = new Plugin(WPKB_VERSION, __FILE__, __DIR__);
$wpkb['categories'] = new Term_List('wpkb-category');
$wpkb['keywords'] = new Term_List('wpkb-keyword');
// search
$wpkb['search'] = $search = new Search($plugin);
$search->add_hooks();
// breadcrumbs
$wpkb['breadcrumbs'] = function () use($router) {
    return new Breadcrumbs\Crumbs($router->archive_page);
};
// code highlighting
$highlighting = new CodeHighlighting($plugin);
$highlighting->add_hooks();
// callout boxes
$callouts = new Callouts();
$callouts->add_hooks();
// article ratings
$wpkb['ratings'] = $ratings = new Rating\Rater();
$ratings->add_hooks();
// load admin specific code
if (is_admin() && (!defined('DOING_AJAX') || !DOING_AJAX)) {
    $admin = new Admin($options);
    $admin->add_hooks();
    $rating_admin = new Rating\Admin($ratings);
    $rating_admin->add_hooks();
}