I am new to Wordpress widget development and am learning tutsplus videos on the go. I am trying to create a simple widget for my site. So far I have been following every step of the video, but still I get the following error and the form does not save the value.
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
This is the from method.
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
So far, I just created a constructor and registered a widget. No errors were detected before this step in the video. And every site I was looking for for this problem showed similar steps. I do not understand why it shows an error in my system.
I am using wordpress 3.5.2, downloaded yesterday and using php5.3.
EDIT :: Here is the code.
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> <?php } public function widget($args, $instance) { extract($args); extract($instance); $display_gadget = "<iframe src='http://$appURL' 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('appSidebarWidget'); }
I still failed to get it to work. However, the actual project that I studied works as expected. I would still like to know what is wrong with this. Because of this, I almost lost my job.
Also, can anyone lead me to call a custom javascript function using a button on the displayed widget. Basically, my goal is to display a button on widgets displayed by form information. When someone clicks a button, he should display an overlay with a message.
source share