更新到4.3后,Wordpress小部件丢失

时间:2015-08-25 17:58:59

标签: wordpress widget

欢迎所有想要帮助我解决这个(也许)简单问题的人。 wordpress更新到4.3后我错过了我的自定义小部件。这是之前有效的代码。仍然在后端看到我的小部件,但它没有显示在前面。

我必须改变什么才能让它在4.3中再次运行?

class Toast_Baan_Widget extends WP_Widget {

    function __construct() {
        parent::__construct(

            // base ID of the widget
            'toast_baan_widget',

            // name of the widget
            __('Baanstatus Pro', 'broekploder' ),

            // widget options
            array (
                'description' => __( 'Baanstatus widget die de setting haalt vanuit de baanstatus opties', 'broekploder' )
            )
        );
    }

    function form( $instance ) {

        // markup for form ?>
       <p>Deze widget toont de baanstatus gegevens die zijn ingevuld bij de baanstatus optie</p>

    <?php
    }

    function update( $new_instance, $old_instance ) {    

    }

    function widget( $args, $instance ) {
        extract( $args );

        // widget options

        echo $before_widget;  

        // WIDGET CODE GOES HERE
        query_posts(
            array( 
            'post_type' => 'baanstatus',
            'showposts' => 1 
        ));
        if (have_posts()) : 
            echo "";
            while (have_posts()) : the_post(); ?>

            <div class="entry-content">
                <h4 class="widget-title"><?php the_title(); ?></h4>
                <p class="h-no-margin-bottom">Caddiemaster: <span class="h-link-color"><?php echo rwmb_meta( 'toast_bs_caddiemaster' ); ?></span></p>
                <p class="h-no-margin-top h-no-margin-bottom">Baanstatus: <span class="h-link-color"><?php echo rwmb_meta( 'toast_bs_baanstatus' ); ?></span></p>
                <p class="h-no-margin-top">Handicarts: <span class="h-link-color"><?php echo rwmb_meta( 'toast_bs_handicarts' ); ?></span></p>
                <p><span class="h-underline">Baanbezetting</span>: <?php echo rwmb_meta( 'toast_bs_baanbezetting' ); ?></p>
            </div>

            <?php endwhile;
            echo "";
        endif; 
        wp_reset_query();
        echo '<iframe id="widget-frame" class="h-center-block" src="http://www.weeronline.nl/Go/ExternalWidgetsNew/TwoDaysCity?gid=4057952&activityType=6&sizeType=1&temperatureScale=Celsius&defaultSettings=False" width="255" height="145" frameborder="0" scrolling="no" style="border: none;" allowtransparency="true"></iframe>';

        echo $after_widget;
    }
}

function toast_register_wheather_widget() {
    register_widget( 'Toast_Baan_Widget' );
}
add_action( 'widgets_init', 'toast_register_wheather_widget' );

希望有人能帮助我朝着正确的方向前进。

2 个答案:

答案 0 :(得分:2)

这是4.3中的一个错误,它会影响具有空$实例的小部件。它在4.31中修复。我可以通过修改 wp-includes \ widgets.php 第319行暂时修复我的自定义小部件:

更改

if ( isset( $instances[ $this->number ] ) ) { 

为:

if ( array_key_exists( $this->number, $instances ) ) { 

我没有对Update或_construct函数进行任何更改。

更多信息:Reference # 33442

答案 1 :(得分:0)

尝试用此替换您的代码。

class Toast_Baan_Widget extends WP_Widget {

    function __construct() {
        parent::__construct(

            // base ID of the widget
            'toast_baan_widget',

            // name of the widget
            __('Baanstatus Pro', 'broekploder' ),

            // widget options
            array (
                'description' => __( 'Baanstatus widget die de setting haalt vanuit de baanstatus opties', 'broekploder' )
            )
        );
        add_action('widgets_init', array($this, 'widgets_init'));
    }

    function form( $instance ) {

        // markup for form ?>
       <p>Deze widget toont de baanstatus gegevens die zijn ingevuld bij de baanstatus optie</p>

    <?php
    }

    function update( $new_instance, $old_instance ) {
        $instance = array();
        return $instance;
    }

    function widget( $args, $instance ) {
        extract( $args );

        // widget options

        echo $before_widget;  

        // WIDGET CODE GOES HERE
        query_posts(
            array( 
            'post_type' => 'baanstatus',
            'showposts' => 1 
        ));
        if (have_posts()) : 
            echo "";
            while (have_posts()) : the_post(); ?>

            <div class="entry-content">
                <h4 class="widget-title"><?php the_title(); ?></h4>
                <p class="h-no-margin-bottom">Caddiemaster: <span class="h-link-color"><?php echo rwmb_meta( 'toast_bs_caddiemaster' ); ?></span></p>
                <p class="h-no-margin-top h-no-margin-bottom">Baanstatus: <span class="h-link-color"><?php echo rwmb_meta( 'toast_bs_baanstatus' ); ?></span></p>
                <p class="h-no-margin-top">Handicarts: <span class="h-link-color"><?php echo rwmb_meta( 'toast_bs_handicarts' ); ?></span></p>
                <p><span class="h-underline">Baanbezetting</span>: <?php echo rwmb_meta( 'toast_bs_baanbezetting' ); ?></p>
            </div>

            <?php endwhile;
            echo "";
        endif; 
        wp_reset_query();
        echo '<iframe id="widget-frame" class="h-center-block" src="http://www.weeronline.nl/Go/ExternalWidgetsNew/TwoDaysCity?gid=4057952&activityType=6&sizeType=1&temperatureScale=Celsius&defaultSettings=False" width="255" height="145" frameborder="0" scrolling="no" style="border: none;" allowtransparency="true"></iframe>';

        echo $after_widget;
    }
}

function toast_register_wheather_widget() {
    register_widget( 'Toast_Baan_Widget' );
}
add_action( 'widgets_init', 'toast_register_wheather_widget' );