WordPress 4.3更新后小部件不工作


After WordPress 4.3 update widget does not work

我更新到4.3后,我的小部件不工作。在更新之前,我的小部件工作得很好。我走过谷歌,但我发现没有什么可以帮助我,除了他们说我必须使用__construct函数,我正在使用。有什么帮助吗?

p。我知道我已经包含了文件,小部件出现在小部件列表中,我也确实在侧边栏上放下了小部件,但它没有在侧边栏上打印"这是小部件的内容"。

这是我的简单代码:(编辑:下面是编辑后的代码,现在工作。感谢提供解决方案的两个人)

<?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' );
?>
<pre><code>
public function update( $new_instance, $old_instance ) {        
        $instance = array();        
        return $instance;       
    }
</code></pre>

$instance必须设置

内部函数__construct:

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

则应用上面的user5251252进行函数更新。

这些问题来自于插件。因为一些旧版本的插件类名和函数名是一样的所以你可以这样做,

  1. 首先停用所有插件并更新所有插件。

的例子:

    class PHP_Code_Widget extends WP_Widget {
    function PHP_Code_Widget() {
   }