接收专业WordPress插件语法错误“Unexpected}”,侧栏菜单小部件

时间:2014-07-08 23:34:00

标签: php wordpress wordpress-plugin

我收到一个商业化的WordPress插件,侧边栏菜单小工具的“意外}”语法错误,我似乎无法找出为什么会抛出这样的错误。小部件由以下内容组成,在类sidebar_menu_widget中的函数形式($ instance)的右大括号中发生“Unexpected}”语法错误扩展WP_Widget:

    <? ob_start();
    /*
    Plugin Name: Sidebar Menu Widget
    Plugin URI: http://webloungeinc.com
    Description: With this plugin you can display menu in sidebar according to nev menu.
    Author: Weblounge inc.
    Version: 1.0
    Author URI: http://webloungeinc.com
    */
    define( 'PLUGINS_PATH', plugin_dir_url(__FILE__) );
    wp_register_style( 'style', PLUGINS_PATH . 'style.css' );
    wp_enqueue_style ( 'style' );

    function _getSidebarMenu($menu_id='',$post)
    {
        $menuItems = wp_get_nav_menu_items($menu_id);

        foreach($menuItems as $menuItem)
        {

            if($menuItem->object_id == $post->ID && $menuItem->object == $post->post_type)
            {
                $parentMenuId = $menuItem->menu_item_parent;
                $currentMenuId = $menuItem->ID;
            }
        }
        $menuItems = (array) $menuItems;

        $_cnt = 0;
        foreach($menuItems as $_counter)
        {

            if($currentMenuId==$_counter->menu_item_parent)
            {
                $_cnt++;
            }
        }

        foreach($menuItems as $kmi=>$vmi)
        {

            $vmi = (array) $vmi;
            if($currentMenuId <> "")
            {
                if(in_array($currentMenuId,$vmi))
                {
                    if($currentMenuId == $vmi[ID])
                    {
                        if($_cnt <> 0)
                        {
                            echo $content = '<li class="m_title">' . $vmi[title] . '</li>';
                        }
                        else
                        {
                            foreach($menuItems as $sis_menu)
                            {
                                // Parent
                                $sis_menu = (array) $sis_menu;

                                if($sis_menu[ID] == $parentMenuId)
                                {
                                        echo $content = '<li class="m_title">' . $sis_menu[title] . '</li>';
                                }

                                if($sis_menu[menu_item_parent] == $parentMenuId)
                                {
                                        $_other_cls = implode(" ",$sis_menu[classes]);

                                        if($sis_menu[ID] == $currentMenuId)
                                        {
                                            $_cur_class = 'current_m_item';
                                        }
                                        else
                                        {
                                            $_cur_class = "";
                                        }
                                        echo $content = '<li><a href="' . $sis_menu[url]. '" class="'.$_other_cls." ".$_cur_class.'" rel="'.$sis_menu[xfn].'" target="'.$sis_menu[target].'">&raquo;&nbsp;' . $sis_menu[title] . '</a></li>';
                                }
                            }
                        }
                    }
                    else
                    {
                        $_other_cls = implode(" ",$vmi[classes]);
                        echo $content = '<li><a href="' . $vmi[url]. '" class="'.$_other_cls." ".$_cur_class.'" rel="'.$vmi[xfn].'" target="'.$vmi[target].'">&raquo;&nbsp;' . $vmi[title] . '</a></li>';
                    }   
                }
            }
            else
            {
                if($vmi[menu_item_parent]==0)
                {
                    $_other_cls = implode(" ",$vmi[classes]);
                    echo $content = '<li><a href="' . $vmi[url]. '" class="'.$_other_cls." ".$_cur_class.'" rel="'.$vmi[xfn].'" target="'.$vmi[target].'">&raquo;&nbsp;' . $vmi[title] . '</a></li>';
                }
            }

        }

    }


    /* Custom Product Specials Widget */
    class sidebar_menu_widget extends WP_Widget {
        function sidebar_menu_widget() {
            // widget actual processes
            parent::WP_Widget(false, $name = 'Sidebar Menu', array(
                'description' => 'Displays a Sidebar Menu'
            ));
        }
        function widget($args, $instance) {
            global $post;
            extract($args);

            echo $before_widget;

                $instance['title'] = apply_filters('widget_title', $instance['title'], $instance, $this->id_base);
                if ( !empty($instance['title']) )
                echo $before_title . $instance['title'] . $after_title;
                echo '<ul class="menu ' . $instance['class'] . '">';
                    _getSidebarMenu($instance['nav_menu'],$post);
                echo '</ul>';

            echo $after_widget;
        }
        function update($new_instance, $old_instance) {
            return $new_instance;
        }
        function form($instance) {
            $title = isset( $instance['title'] ) ? $instance['title'] : '';
            $class = isset( $instance['class'] ) ? $instance['class'] : '';
            $nav_menu = isset( $instance['nav_menu'] ) ? $instance['nav_menu'] : '';
            // Get menus
            $menus = get_terms( 'nav_menu', array( 'hide_empty' => false ) );
            // If no menus exists, direct the user to go and create some.
            if ( !$menus ) {
                echo '<p>'. sprintf( __('No menus have been created yet. <a href="%s">Create some</a>.'), admin_url('nav-menus.php') ) .'</p>';
                return;
            }
            ?>
            <p>
                <label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title:') ?></label>
                <input type="text" class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" value="<?php echo $title; ?>" />
            </p>
            <p>
                <label for="<?php echo $this->get_field_id('class'); ?>"><?php _e('Class:') ?></label>
                <input type="text" class="widefat" id="<?php echo $this->get_field_id('class'); ?>" name="<?php echo $this->get_field_name('class'); ?>" value="<?php echo $class; ?>" />
            </p>
            <p>
                <label for="<?php echo $this->get_field_id('nav_menu'); ?>"><?php _e('Select Menu:'); ?></label>
                <select id="<?php echo $this->get_field_id('nav_menu'); ?>" name="<?php echo $this->get_field_name('nav_menu'); ?>">
            <?php
                foreach ( $menus as $menu ) {
                    $selected = $nav_menu == $menu->term_id ? ' selected="selected"' : '';
                    echo '<option'. $selected .' value="'. $menu->term_id .'">'. $menu->name .'</option>';
                }
            ?>
                </select>
            </p>

            <?php
---->   }
    }
    add_action('widgets_init', 'register_sidebar_menu_widget');
    function register_sidebar_menu_widget() {
        register_widget('sidebar_menu_widget');
    }

我用箭头表示错误的位置。经过大量调试后,我能想到的唯一可能导致这种错误的是在form()函数中插入HTML。但是,我认为ob_start()可以允许这样的中断发生,同时通过缓冲输出来维持php的流量?我是否需要在HTML之后进行某种ob_get_contents()调用以允许这样的延续?

我即将重写该插件以避免中断,但令我困扰的是,这是一款商用插件,对我来说无法直接使用。任何帮助将不胜感激!感谢。

顺便说一句,我正在运行PHP 5.5.12,并且这个错误消息是通过XDebug提供给我的。如果您需要帮助,请告诉我您是否需要任何其他信息。

0 个答案:

没有答案