/** * * * @SuppressWarnings(PHPMD.LongVariable) */ public static function get_testimonials($atts) { $hide_gravatar = $atts['hide_gravatar']; $args = self::get_query_args($atts); $args['query'] = true; $testimonials = apply_filters('testimonials_widget_cache_get', false, $args); if (false === $testimonials) { $testimonials = new WP_Query($args); $testimonials = apply_filters('testimonials_widget_cache_set', $testimonials, $args); } if (has_filter('posts_results', array(__CLASS__, 'posts_results_sort_none'))) { remove_filter('posts_results', array(__CLASS__, 'posts_results_sort_none')); } self::$max_num_pages = $testimonials->max_num_pages; self::$found_posts = $testimonials->found_posts; self::$post_count = $testimonials->post_count; self::$wp_query = $testimonials; wp_reset_postdata(); $image_size = apply_filters('testimonials_widget_image_size', 'thumbnail'); if (!is_array($image_size)) { global $_wp_additional_image_sizes; if (!empty($_wp_additional_image_sizes[$image_size])) { $gravatar_size = $_wp_additional_image_sizes[$image_size]['width']; } else { $gravatar_size = get_option($image_size . '_size_w'); } $gravatar_size = apply_filters('testimonials_widget_gravatar_size', $gravatar_size); } else { $gravatar_size = apply_filters('testimonials_widget_gravatar_size', $image_size); } $testimonial_data = array(); if (empty(self::$post_count)) { return $testimonial_data; } foreach ($testimonials->posts as $row) { $post_id = $row->ID; $email = get_post_meta($post_id, 'testimonials-widget-email', true); if (has_post_thumbnail($post_id)) { $image = get_the_post_thumbnail($post_id, $image_size); } elseif (!$hide_gravatar && is_email($email)) { $image = get_avatar($email, $gravatar_size); self::make_gravatar_featured($post_id, $email); } else { $image = false; } $image = self::strip_protocol($image); $url = get_post_meta($post_id, 'testimonials-widget-url', true); if (!empty($url) && 0 === preg_match('#https?://#', $url)) { $url = 'http://' . $url; } $data = array('post_id' => $post_id, 'testimonial_company' => get_post_meta($post_id, 'testimonials-widget-company', true), 'testimonial_content' => $row->post_content, 'testimonial_email' => $email, 'testimonial_extra' => '', 'testimonial_image' => $image, 'testimonial_location' => get_post_meta($post_id, 'testimonials-widget-location', true), 'testimonial_source' => $row->post_title, 'testimonial_title' => get_post_meta($post_id, 'testimonials-widget-title', true), 'testimonial_url' => $url); $testimonial_data[] = $data; } $testimonial_data = apply_filters('testimonials_widget_data', $testimonial_data, $atts); return $testimonial_data; }