/**
 *  Test if Post is Sticky
 * -----------------------------------------------------------------------------
 * Return whether the current post is the set sticky post.
 * 
 * @param   object/int  $post               Post ID or post object.
 * @return  bool                            Post ID is sticky, true/false.
 */
function kaitain_is_post_sticky($post)
{
    if (!($post = get_post($post)) || !kaitain_has_sticky_been_set()) {
        return false;
    }
    $sticky = kaitain_get_sticky_id();
    return $sticky === $post->ID;
}
 /**
  * Widget Public Display
  * -------------------------------------------------------------------------
  * @param array     $defaults         Widget default values. 
  * @param array     $instance         Widget instance arguments.
  */
 public function widget($defaults, $instance)
 {
     // $post object is needed in order to correctly run setup_postdata().
     global $post;
     $classes = array('widget' => 'widget widget--featured', 'post_row' => 'flex--four-col--article vspace--half widget--featured__row');
     // Array of featured and sticky posts.
     $featured = array();
     if ($instance['show_sticky']) {
         /* If sticky was checked, see if it is available to use. Otherwise
          * grab the last featured post. */
         if (kaitain_has_sticky_been_set()) {
             $featured[] = kaitain_get_sticky_post();
         } else {
             /* If no stick is set, but was asked to display, increment
              * count to fill. */
             $instance['count']++;
         }
     }
     // Show other featured posts if they were elected ot be shown.
     $featured = array_merge($featured, kaitain_get_featured($instance['count'], true));
     if (!empty($defaults['before_widget'])) {
         printf($defaults['before_widget']);
     }
     printf('<div class="%s">', $classes['widget']);
     // Number modifier for when sticky posts are selected.
     $mod = $instance['show_sticky'] ? 0 : 1;
     foreach ($featured as $number => $post) {
         if (!empty($post)) {
             setup_postdata($post);
             if ($instance['show_sticky'] && $number === 0) {
                 kaitain_partial('article', 'lead');
             }
             if (($number + $mod) % 4 === 1) {
                 printf('<div class="%s">', $classes['post_row']);
             }
             if (!$instance['show_sticky'] || $number > 0) {
                 kaitain_partial('article', 'small');
             }
             if ($number > 0 && ($number + $mod) % 4 === 0) {
                 printf('</div>');
             }
         }
     }
     printf('</div>');
     if ($instance['count'] > 1) {
         printf('<hr>');
     }
     if (!empty($defaults['after_widget'])) {
         printf($defaults['after_widget']);
     }
     wp_reset_postdata();
 }