/** * Create the necessary form to customize the widget. * * @uses title @since 0.1 * * @author Nate Jacobs * @date 09/13/13 * @since 1.4 * * @param array */ public function form($instance) { $instance = wp_parse_args((array) $instance, array('themeName' => '')); $themeName = esc_attr($instance['themeName']); //call functions class and use get method to retrieve list of themes $brickset = new BricksetAPISearch(); $themes = $brickset->get_themes(); ?> <p> <label for="<?php echo $this->get_field_id('themeName'); ?> "><?php _e('Theme Name', 'bs_api'); ?> :</label> <?php // check for errors if (is_wp_error($brickset)) { echo $brickset->get_error_message(); } else { ?> <select class="widefat" id="<?php echo $this->get_field_id('themeName'); ?> " name="<?php echo $this->get_field_name('themeName'); ?> "> <?php foreach ($themes as $theme) { ?> <option value="<?php echo $theme->theme; ?> " <?php selected($themeName, $theme->theme); ?> ><?php echo $theme->theme; ?> </option> <?php } ?> </select> <?php } ?> </p> <?php }
/** * Generates the widget that displays the themes as a list of links. * * @author Nate Jacobs * @since 0.1 * * @param array * @param array */ public function widget($args, $instance) { extract($args); $title = apply_filters('widget_title', $instance['title']); echo $before_widget; if ($title) { echo $before_title . $title . $after_title; } //call functions class and use get method to retrieve list of themes $brickset = new BricksetAPISearch(); $themes = $brickset->get_themes(); // check for errors if (is_wp_error($brickset)) { echo $brickset->get_error_message(); } else { foreach ($themes as $theme) { echo "<a href='http://www.brickset.com/browse/themes/?theme={$theme->theme}'>" . $theme->theme . '</a>'; echo '<br>'; } echo $after_widget; } }