WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm using a custom theme that is doing something that blocks Custom Menu Classes (the optional ones that you can input from inside the Menu Panel) to print to HTML.

  1. I found in the code where they are adding classes to the li tag. So I tried to add this line of code:


Would that be the correct code to use to pull the class field from the menu panel? If so..

I did that and I got this error:

Warning: stripos() [function.stripos]: needle is not a string or an integer in file-path/file.php on line 397

Here's that block of code: (I noted just above the line the warning referenceS)

protected static function attrClass($action, DOMNode $node, $class) {

    $classes = $node->getAttribute('class');
/* error found in line below */
    $found   = stripos($classes, $class) !== false && in_array(strtolower($class), explode(' ', strtolower($classes)));

    if ($action == 'has') {
        return $found;

    if ($action == 'toggle') {
        $action = $found ? 'remove' : 'add';

    if ($action == 'add' && !$found) {
        $node->setAttribute('class', trim(preg_replace('/\s{2,}/i', ' ', $classes.' '.$class)));

    if ($action == 'remove' && $found) {

        $classes = trim(preg_replace('/\s{2,}/i', ' ', preg_replace('/(^|\s)'.preg_quote($class, '/').'(?:\s|$)/i', ' ', $classes)));

        if ($classes !== '') {
            $node->setAttribute('class', $classes);
        } else {

    return $node;

I'm not sure what's going wrong and what I need to do next in order to get the menu custom class function working.

Note: Still learning wordpress/php so if I'm missing any needed any information I'm sorry and I'll post it if you ask. Trying to be as thorough as possible!

-edit- Here's the block of code where i tried adding $li->addClass($classes); (I noted just before it again)

class WarpMenuDefault extends WarpMenu {

    Function: process

public function process($module, $element) {
    self::_process($module, $element->first('ul:first'));
    return $element;

    Function: _process

protected static function _process($module, $element, $level = 0) {

    if ($level == 0) {
        $element->attr('class', 'menu '.$module->menu_style);
    } else {
        $element->addClass('level'.($level + 1));

    foreach ($element->children('li') as $li) {

        // is active ?
        if ($active = $li->attr('data-menu-active')) {
            $active = $active == 2 ? ' active current' : ' active';

        // is parent ?
        $ul = $li->children('ul');
        $parent = $ul->length ? ' parent' : null;

        // set class in li
        $li->attr('class', sprintf('level%d item%s'.$parent.$active, $level + 1, $li->attr('data-id'),$class));
/* Here's the line I added*/            $li->addClass($classes); 

        // set class in a/span
        foreach ($li->children('a,span') as $child) {

            // get title
            $title = $child->first('span:first');

            // set subtile
            $subtitle = $title ? explode('||', $title->text()) : array();

            if (count($subtitle) == 2) {
                $title->html(sprintf('<span class="title">%s</span><span class="subtitle">%s</span>', trim($subtitle[0]), trim($subtitle[1])));

            // set image
            if ($image = $li->attr('data-menu-image')) {
                $title->prepend(sprintf('<span class="icon" style="background-image: url(\'%s\');"> </span>', $image));

            $child->addClass(sprintf('level%d'.$parent.$active, $level + 1));

        // process submenu
        if ($ul->length) {
            self::_process($module, $ul->item(0), $level + 1);



share|improve this question
Where is the code you edited? The part with $li->addClass($classes);? – s_ha_dum Jan 18 '14 at 16:01
@s_ha_dum I updated the question with it. It's in a different file, I wasn't sure if the whole block of code was relevant or not. – Derek Jan 18 '14 at 18:01
Where is $classes defined? Am I missing something? (Posting from my phone. The code is hard to read.) – s_ha_dum Jan 18 '14 at 18:45
I'm guessing I'm probably wrong here then, but I assumed that was how you called the called the "menu css classes" from the menu panel. I'm not sure how to do that, and I can't find any documentation/guides anywhere that explains it. – Derek Jan 18 '14 at 19:09
$classes would have to be defined in the method or imported into the class/method via method parameters. I don't see that happening. And you are dealing with non-Core classes. Neither WarpMenuDefault nor WarpMenu is a WordPress class. WarpMenu might itself be an extension of a Core class but I can't tell. – s_ha_dum Jan 19 '14 at 1:57

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.