Unidentified Index Error

I am using a plugin for WordPRess called Easy Bootstrap Shortcodes to use Booystrap CSS within wordpress posts. Tabs are one feature I use a lot and when I use the tabs short code, it throws the following error:

Notice: Undefined index: tabs in /home/onedirec/public_html/tester/wp-content/plugins/easy-bootstrap-shortcodes/shortcode/tabs/plugin_shortcode.php on line 38

Read More

What’s weird is that the tabs and all the information following is rendered apart from an indent that shouldn;t be there. You can see this in action here: http://onedirectionconnection.com/tester/?projects=take-me-home-tour

If anyone could help me figure out what the issue is, it would be greatly appreciated. Here’s the code that’s causing the error:

<?php

/* * *********************************************************
 * jQuery UI Tabs
 * ********************************************************* */
$_oscitas_tabs = array();

function osc_theme_tabs($params, $content = null) {
    global $_oscitas_tabs;
    extract(shortcode_atts(array(
                'id' => count($_oscitas_tabs),
                'class' => ''
                    ), $params));
    $_oscitas_tabs[$id] = array();
    do_shortcode($content);
    $scontent = '<ul class="nav nav-tabs " id="oscitas-tabs-' . $id . '">' . implode('', $_oscitas_tabs[$id]['tabs']) . '</ul><div
    class="tab-content">' . implode('', $_oscitas_tabs[$id]['panes']) . '</div>';
    if (trim($scontent) != "") {
        $output = '<div class="' . $class . '">' . $scontent;
        $output .= '</div>';

        return $output;
    } else {
        return "";
    }
}

add_shortcode('tabs', 'osc_theme_tabs');

function osc_theme_tab($params, $content = null) {
    global $_oscitas_tabs;
    extract(shortcode_atts(array(
                'title' => 'title',
                'active' => '',
                    ), $params));

    $index = count($_oscitas_tabs) - 1;
    $pane_id = 'pane-' . $index . '-' . count($_oscitas_tabs[$index]['tabs']);
    $_oscitas_tabs[$index]['tabs'][] = '<li class="' . $active . '"><a href="#' . $pane_id . '" data-toggle="tab">' . $title
            . '</a></li>';
    $_oscitas_tabs[$index]['panes'][] = '<div class="tab-pane ' . $active . '" id="'
            . $pane_id . '">'
            . do_shortcode
                    (trim($content)) . '</div>';
}

add_shortcode('tab', 'osc_theme_tab');

And here is line 38 on its own:

$pane_id = 'pane-' . $index . '-' . count($_oscitas_tabs[$index]['tabs']);

I know very little about PHP so if anyone can help me spot the error here, it would be greatly appreciated.

Related posts

Leave a Reply

1 comment

  1. Well I’ll just post the answer here since it worked in the comments.

    Add this line just before line 38:

    $_oscitas_tabs[$index]['tabs'] = array(); 
    

    Right above this line:

    $pane_id = 'pane-' . $index . '-' . count($_oscitas_tabs[$index]['tabs']);
    

    That should stop the PHP notice from appearing.

    You could try adding a @ right before count()

    $pane_id = 'pane-' . $index . '-' . @count($_oscitas_tabs[$index]['tabs']);
    

    It keeps PHP from complaining.