function widget($args, $instance)
 {
     extract($args);
     // Get testimonials to display
     $query_args = array('post_type' => 'testimonial', 'numberposts' => 1);
     if (is_numeric($instance['testimonial_id'])) {
         $query_args['include'] = $instance['testimonial_id'];
     } else {
         if (is_array($instance['testimonial_random_category'])) {
             $query_args['testimonial_category'] = implode(',', array_keys($instance['testimonial_random_category']));
         }
         $query_args['orderby'] = 'rand';
     }
     $testimonials = get_posts($query_args);
     // Widget title
     $title = apply_filters('widget_title', $instance['title'], $instance, $this->id_base);
     echo $before_widget;
     if (strlen($title)) {
         echo $before_title . $title . $after_title;
     }
     if ($testimonials) {
         foreach ($testimonials as $testimonial) {
             $testimonial = new WP_Testimonial($testimonial->ID);
             $testimonial->word_limit = isset($instance['testimonial_word_limit']) ? $instance['testimonial_word_limit'] : 0;
         }
         $testimonial->render(true);
     }
     echo $after_widget;
 }
function shortcode_testimonials($atts)
{
    $args = array('posts_per_page' => isset($atts['per_page']) ? $atts['per_page'] : 2, 'paged' => get_query_var('paged'), 'order' => isset($atts['order']) ? $atts['order'] : 'DESC', 'orderby' => isset($atts['orderby']) ? $atts['orderby'] : 'date', 'post_type' => 'testimonial');
    $output = '';
    if (isset($atts['category'])) {
        $ids = explode(',', $atts['category']);
        $slugs = array();
        foreach ($ids as $id) {
            if ($term = get_term_by('id', $id, 'testimonial_category')) {
                $slugs[] = $term->slug;
            }
        }
        $args['testimonial_category'] = implode(',', $slugs);
    }
    if (query_posts($args)) {
        if (have_posts()) {
            ob_start();
            echo '<div class="testimonial-category">';
            while (have_posts()) {
                the_post();
                $testimonial = new WP_Testimonial(get_the_ID());
                $testimonial->word_limit = isset($atts['word_limit']) && is_numeric($atts['word_limit']) ? $atts['word_limit'] : -1;
                $testimonial->render();
            }
            $pagination = true;
            if (isset($atts['pagination']) && $atts['pagination'] == 'false') {
                $pagination = false;
            }
            if ($pagination) {
                if (function_exists('wp_paginate')) {
                    wp_paginate();
                } else {
                    global $wp_query;
                    $big = 9999999;
                    echo paginate_links(array('base' => str_replace($big, '%#%', esc_url(get_pagenum_link($big))), 'format' => '?paged=%#%', 'current' => max(1, get_query_var('paged')), 'total' => $wp_query->max_num_pages));
                }
            }
            echo '</div>';
            $output = ob_get_contents();
            ob_end_clean();
        }
        wp_reset_query();
        return $output;
    }
}
 public static function ajax_get_random_testimonial()
 {
     $testimonial = get_posts(array('post_type' => 'testimonial', 'posts_per_page' => 1, 'orderby' => 'rand'));
     if ($testimonial) {
         $testimonial = new WP_Testimonial($testimonial[0]->ID);
         $testimonial->word_limit = isset($_POST['word_limit']) ? $_POST['word_limit'] : -1;
         ob_start();
         $testimonial->render();
         $markup = ob_get_contents();
         ob_end_clean();
         wp_send_json_success(array('markup' => $markup, 'testimonial_id' => $testimonial->ID));
     } else {
         wp_send_json_error();
     }
 }