我有一个问题,而不是试着看看现在找不到它的地方。 Wordpress返回以下警告:
Missing argument 1 for WP_Widget :: __ construct ()
Missing argument 2 for WP_Widget::__construct()
我的代码是:
class WP_Mrw_Widget extends WP_Widget {
function Mrw_Widget(){
$widget_ops = array( 'classname' => 'MiRegata', 'description' => 'Plugin para mostrar las regatas ya finalizadas' );
$control_ops = array( 'width' => 300, 'height' => 350, 'id_base' => 'mrw_widget' );
$this->WP_Widget( 'mrw_widget', 'Mi Regata Widget', $widget_ops, $control_ops );
}
function widget($args, $instance){
}
function update($new_instance, $old_instance){
}
function form($instance){
}
}
答案 0 :(得分:1)
扩展WP_Widget
时,您的子类必须通过调用父构造函数向WordPress注册您的小部件。例如:
/**
* Register widget with WordPress.
*/
function __construct() {
parent::__construct(
'foo_widget', // Base ID
__( 'Widget Title', 'text_domain' ), // Name
array( 'description' => __( 'A Foo Widget', 'text_domain' ), ) // Args
);
}
这很可能是因为你看到了缺失的论点通知。
答案 1 :(得分:0)
问题的解决方案是
function Mrw_Widget(){
parent::__construct('Mrw_Widget',"MiRegata",array("description"=>"Widet que nos muestra las ultimas regatas disputadas"));
}