wordpress小部件表单方法中的$instance为null

wordpress小部件表单方法中的$instance为null,wordpress,Wordpress,我是wordpress小部件开发的新手,在旅途中学习。我正在尝试为我的网站创建一个简单的小部件。到目前为止,我正在按照视频中的每个步骤进行操作,但仍然出现以下错误,并且表单没有保存值 Warning: extract() expects parameter 1 to be array, null given in C:\Program Files\Ampps\www\test\wp-content\plugins\first\index.php on line 50 这是从方法开始的 publ

我是wordpress小部件开发的新手,在旅途中学习。我正在尝试为我的网站创建一个简单的小部件。到目前为止,我正在按照视频中的每个步骤进行操作,但仍然出现以下错误,并且表单没有保存值

Warning: extract() expects parameter 1 to be array, null given in C:\Program Files\Ampps\www\test\wp-content\plugins\first\index.php on line 50
这是从方法开始的

public function form($instance){ 
extract($instance);
?>
        <p>
            <lable for="<?php echo $this->get_field_id('ap_title_text');?>">Title Text: </lable>
            <input type="text" class="widefat" id="<?php echo $this->get_field_id('ap_title_text');?>"  name="<?php echo $this->get_field_name('ap_title_text');?>" value="<?php if(isset($ap_title_text)) echo esc_attr($ap_title_text);?>" />
        </p>

<?php
公共函数表单($instance){
摘录($实例);
?>


代码正在崩溃,因为变量
$instance
不是数组。
extract()
函数必须接收数组才能完成它的工作。这一点很清楚,也很简单

问题是,除非您提供调用
form()
函数的代码,否则没有人能帮助您解释为什么
$instance
为空。可能有一百万个原因说明
$instance
不是数组。

在下面的代码中

add_action('widgets_init','appRegisterWidget');
function appRegisterWidget()
{
    register_widget('appSidebarWidget'); <--
}
我在小部件设置表单中添加了一个url
文本框
,它正在工作(下面给出了完整的修改代码)

class SidebarWidget扩展了WP_Widget{
函数_u构造()
{
$options=array(
'description'=>'从任何页面开始工作的最简单方法',
“名称”=>“侧栏小部件”
);
父项::_构造('appSidebarWidget','',$options);
}
公共函数表($instance)
{   
摘录($实例);
?>


表格(WP_Widgets对象正在调用函数。

$instance
如果您有一个空的更新函数,则在form方法中也可能始终为null。这可能与此问题无关,但如果遇到类似问题,请检查这是否是问题。

有人可以帮助我。我已尝试完成g代码,但小部件仍然显示相同的错误。我甚至尝试了print\r($instance),但没有解决方案。请现在发布小部件类的完整代码。
add_action('widgets_init','appRegisterWidget');
function appRegisterWidget()
{
    register_widget('appSidebarWidget'); <--
}
register_widget('SidebarWidget');
class SidebarWidget extends WP_Widget{
    function __construct()
    {
        $options = array(
            'description'   =>  'Simplest way to start working from any page',
            'name'          =>  'Sidebar Widget'
        );
        parent::__construct('appSidebarWidget', '', $options);
    }

    public function form($instance)
    {   
        extract($instance);
        ?>
        <p>
            <label for="<?php echo $this->get_field_id('ap_title_text'); ?>" >Title Text: </lable>
            <input type="text" class="widefat" id="<?php echo $this->get_field_id('ap_title_text');?>"  name="<?php echo $this->get_field_name('ap_title_text');?>" value="<?php if(isset($ap_title_text)) echo esc_attr($ap_title_text);?>" />
        </p>

        <p>
            <label for="<?php echo $this->get_field_id('ap_app_name'); ?>" >App Name: </lable>
            <input type="text" class="widefat" id="<?php echo $this->get_field_id('ap_app_name');?>"    name="<?php echo $this->get_field_name('ap_app_name');?>"   value="<?php if(isset($ap_app_name)) echo esc_attr($ap_app_name);?>" />
        </p>
        <!-- New text box added -->
        <p>
            <label for="<?php echo $this->get_field_id('ap_app_url'); ?>" >App Url: </lable>
            <input type="text" class="widefat" id="<?php echo $this->get_field_id('ap_app_url');?>"    name="<?php echo $this->get_field_name('ap_app_url');?>"   value="<?php if(isset($ap_app_url)) echo esc_attr($ap_app_url);?>" />
        </p>

        <?php
    }

    public function widget($args, $instance)
    {
        extract($args);
        extract($instance);
        $display_gadget = "<iframe src='http://" . $ap_app_url . "' width='150px' height='200px' scrolling='auto' frameborder='0' allowtransparency='true'></iframe>";

        if(empty($ap_title_text)){$ap_title_text = "Schedule Now";}
        echo $before_widget;
        echo $before_title.$ap_title_text.$after_title;
        echo $display_gadget;
        echo $after_widget;
    }

}

add_action('widgets_init','appRegisterWidget');
function appRegisterWidget()
{
    register_widget('SidebarWidget');
}