【发布时间】:2015-11-14 17:22:22
【问题描述】:
在我将 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' );
?>
【问题讨论】: