/** * @see WP_Widget::form() */ function test_wp_widget_form() { $widget = new WP_Widget('foo', 'Foo'); ob_start(); $retval = $widget->form(array()); $output = ob_get_clean(); $this->assertEquals('noform', $retval); $this->assertContains('no-options-widget', $output); }
/** * Outputs the options form on admin * * @param array $instance The widget options */ public function form($instance) { parent::form($instance); //Biến tạo các giá trị mặc định trong form $defaults = ['title' => 'Widget title', 'image' => 'Widget image', 'link' => 'Link your banner']; //Gộp các giá trị trong mảng $default vào biến $instance để nó trở thành các giá trị mặc định $instance = wp_parse_args($instance, $defaults); //Tạo biến riêng cho giá trị mặc định trong mảng $default $title = esc_attr($instance['title']); $image = esc_url($instance['image']); $link = esc_url($instance['link']); ?> <p> <label for="<?php echo $this->get_field_name('title'); ?> "><?php _e('Title:'); ?> </label> <input class="widefat" id="<?php echo $this->get_field_id('title'); ?> " name="<?php echo $this->get_field_name('title'); ?> " type="text" value="<?php echo esc_attr($title); ?> " /> </p> <p> <label for="<?php echo $this->get_field_name('image'); ?> "><?php _e('Image:'); ?> </label> <input name="<?php echo $this->get_field_name('image'); ?> " id="<?php echo $this->get_field_id('image'); ?> " class="widefat" type="text" size="36" value="<?php echo esc_url($image); ?> " /> <input class="upload_image_button button button-primary" type="button" value="Upload Image" /> </p> <p> <label for="<?php echo $this->get_field_name('link'); ?> "><?php _e('Link:', KC_DOMAIN); ?> </label> <input class="widefat" id="<?php echo $this->get_field_id('link'); ?> " name="<?php echo $this->get_field_name('link'); ?> " type="text" value="<?php echo esc_url($link); ?> " /> </p> <?php }
/** * Event triggered when ready to render the widget's configuration page * * @see form() * @param array $instance Current settings * @api */ public function onFormRender($instance) { parent::form($instance); }
/** * Základní (ne)formulář, resp. výpis zadaného popisku a informace, že není dostupná konfigurace widgetu * Pozn.: pokud chcete vlastní konfiguraci widgetu, tak je třeba tuto metodu přepsat a udělat vlastní formulář * * @author Martin Hlaváč * @link http://www.ktstudio.cz * * @param array $instance * @return string */ public function form($instance) { echo "<p>{$this->getDescription()}</p>"; return parent::form($instance); }