WordPress 4.3更新小部件后无法正常工作

时间:2015-08-20 21:41:49

标签: php wordpress-plugin wordpress

将WordPress更新为4.3后,我的小部件无效。 在更新之前,我的小部件工作正常。 我走过谷歌,但除了他们说我必须使用我正在使用的__construct功能外,我发现什么都没有帮助我。 有帮助吗?

PS。我知道我已经包含了文件,窗口小部件显示在窗口小部件列表中我也放弃了侧边栏上的窗口小部件,但它不会在侧边栏上打印“这是窗口小部件的内容”。

这是我的简单代码:(编辑:下面是已编辑的代码,现在可以使用。感谢提供解决方案的两个人)

<?php

class test_widget extends WP_Widget {

function __construct() {
  parent::__construct(
    'test_pop', // Base ID
    __( 'test widget', 'text_domain' ), // Name
    array( 'description' => __( 'A test Widget', 'text_domain' ), ) // Args
  );

  add_action('widgets_init', array($this, 'widgets_init'));
}

public function widget( $args, $instance ) {
  echo $args['before_widget'];
  echo "<h1> This is the content of widget<h1>";
  echo $args['after_widget'];
}

public function form( $instance ) {

}

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

}

function test_widget_register() {
  register_widget( 'test_widget' );
}

add_action( 'widgets_init', 'test_widget_register' );

?>

3 个答案:

答案 0 :(得分:2)

<pre><code>
public function update( $new_instance, $old_instance ) {        
        $instance = array();        
        return $instance;       
    }
</code></pre>

$instance必须设置。

答案 1 :(得分:1)

内幕功能__construct

function __construct(){
    parent::__construct(
    //define your widgets ID,Name, Description.
    )
    add_action('widgets_init', array($this, 'widgets_init'));
}

然后在上面应用user5251252进行功能更新。

答案 2 :(得分:0)

这些问题来自插件。因为某些插件旧版本的类名和函数名相同所以你会这样做,

  1. 首先停用所有插件并更新所有插件。它将起作用。
  2. 示例:

        class PHP_Code_Widget extends WP_Widget {
    
        function PHP_Code_Widget() {
    
       }
    
相关问题