diff --git a/test/widgets/BuyThisPrintWidgetTest.php b/test/widgets/BuyThisPrintWidgetTest.php new file mode 100644 index 0000000..4da9c11 --- /dev/null +++ b/test/widgets/BuyThisPrintWidgetTest.php @@ -0,0 +1,36 @@ +w = new BuyThisPrintWidget('id', 'name', array()); + } + + function providerTestUpdate() { + return array( + array( + array(), array() + ), + array( + array('test' => 'test'), array() + ), + array( + array('title' => 'title'), array('title' => 'title') + ), + array( + array('title' => "title"), array('title' => 'title') + ) + ); + } + + /** + * @dataProvider providerTestUpdate + */ + function testUpdate($input, $expected_output) { + $this->assertEquals($expected_output, $this->w->update($input)); + } +} diff --git a/widgets/BuyThisPrintWidget.inc b/widgets/BuyThisPrintWidget.inc new file mode 100644 index 0000000..39906a7 --- /dev/null +++ b/widgets/BuyThisPrintWidget.inc @@ -0,0 +1,60 @@ + 'ComicPressBuyThisPrint', 'description' => __('Adds a button that goes to the buy print template page.','comicpress') ); + $this->WP_Widget('comicpress_buyprint', __('Buy This Print','comicpress'), $widget_ops); + } + + function init() { + add_filter('comicpress_buy_print_structure', array(&$this, 'buy_print_structure')); + } + + function widget($args, $instance) { + extract($args, EXTR_SKIP); + + echo $before_widget; + $title = apply_filters('widget_title', $instance['title']); + if ( !empty( $title ) ) { echo $before_title . $title . $after_title; }; + + if ( get_post_meta( get_the_ID(), "buythiscomic", true ) !== 'sold' ) { + echo apply_filters('comicpress_buy_print_structure', ''); + } + + echo $after_widget; + } + + function buy_print_structure($content = '') { + global $buy_print_url; ?> +
+ +
+
+ '' ) ); + $title = strip_tags($instance['title']); + ?> +

+ -
- -
-
- 'widget_comicpress_buy_this_print', 'description' => __('Adds a button that goes to the buy print template page.','comicpress') ); - $this->WP_Widget('comicpress_buyprint', __('Buy This Print','comicpress'), $widget_ops); - } - - function widget($args, $instance) { - global $buy_print_url; - extract($args, EXTR_SKIP); - - echo $before_widget; - $title = empty($instance['title']) ? '' : apply_filters('widget_title', $instance['title']); - if ( !empty( $title ) ) { echo $before_title . $title . $after_title; }; - buy_this_print_comic(); - echo $after_widget; - } - - function update($new_instance, $old_instance) { - $instance = $old_instance; - $instance['title'] = strip_tags($new_instance['title']); - return $instance; - } - - function form($instance) { - $instance = wp_parse_args( (array) $instance, array( 'title' => '' ) ); - $title = strip_tags($instance['title']); - ?> -

- \ No newline at end of file